@shumai-one/shumai 0.4.4 → 0.4.6

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 (178) hide show
  1. package/bin/{chunk-snhsjs4x.js → chunk-07jszkhj.js} +62 -62
  2. package/bin/chunk-0c67210c.js +1 -0
  3. package/bin/{chunk-kswvyqq1.js → chunk-0wvhahzh.js} +2 -2
  4. package/bin/chunk-161rxeq2.js +2 -0
  5. package/bin/{chunk-trveq4wg.js → chunk-1bgsphyz.js} +2 -2
  6. package/bin/{chunk-vap4k11j.js → chunk-1dqsf5qj.js} +6 -6
  7. package/bin/{chunk-zxk7q0zk.js → chunk-1jybg56e.js} +1 -1
  8. package/bin/chunk-1kt5dzjv.js +2 -0
  9. package/bin/{chunk-drepsbb4.js → chunk-1t51fp6n.js} +1 -1
  10. package/bin/{chunk-cbgq517y.js → chunk-2jrjwaqr.js} +2 -2
  11. package/bin/chunk-2qjfpmcf.js +2 -0
  12. package/bin/{chunk-wjyaezs7.js → chunk-2vzzd0q6.js} +1 -1
  13. package/bin/chunk-2yr5k567.js +2 -0
  14. package/bin/chunk-2z1pnt7h.js +2 -0
  15. package/bin/{chunk-0zv3bks2.js → chunk-3d5rm1d1.js} +1 -1
  16. package/bin/{chunk-w4ghe71n.js → chunk-3d9tfxp4.js} +1 -1
  17. package/bin/{chunk-0qjfahk9.js → chunk-3dgahs95.js} +1 -1
  18. package/bin/{chunk-dqxeztfa.js → chunk-3j5njrpr.js} +2 -2
  19. package/bin/{chunk-ryzz5fht.js → chunk-3n4224c0.js} +1 -1
  20. package/bin/{chunk-914bp49r.js → chunk-3tg39jx7.js} +3 -3
  21. package/bin/chunk-3vmapyk9.js +1 -0
  22. package/bin/{chunk-g3fpmyyn.js → chunk-46wfxyd7.js} +2 -2
  23. package/bin/{chunk-4hkkdm2q.js → chunk-47tn3vtg.js} +1 -1
  24. package/bin/{chunk-1zwajpwf.js → chunk-4syt6rn0.js} +3 -3
  25. package/bin/chunk-5kvc1gp2.js +1 -0
  26. package/bin/{chunk-xa18z1py.js → chunk-5vvvgjvz.js} +2 -2
  27. package/bin/{chunk-5nm2jvg5.js → chunk-6vxzkrsj.js} +11 -11
  28. package/bin/{chunk-ytdwk2fq.js → chunk-6y4xkcte.js} +2 -2
  29. package/bin/{chunk-fpc4p0j8.js → chunk-7e5z637e.js} +2 -2
  30. package/bin/chunk-7nvk7waw.js +1 -0
  31. package/bin/{chunk-rq0n0vcc.js → chunk-80qz30dc.js} +2 -2
  32. package/bin/chunk-886pnknh.js +3 -0
  33. package/bin/{chunk-6ghcj4a9.js → chunk-8cn7fx40.js} +1 -1
  34. package/bin/chunk-908pypkr.js +1 -0
  35. package/bin/chunk-952qwf17.js +2 -0
  36. package/bin/chunk-988casfy.js +1 -0
  37. package/bin/chunk-9a2tf0mh.js +2 -0
  38. package/bin/{chunk-nkdk229f.js → chunk-9d0thqcy.js} +1 -1
  39. package/bin/{chunk-s2k4qntr.js → chunk-9nvymwqj.js} +2 -2
  40. package/bin/{chunk-mz0yjra0.js → chunk-9trnkbtr.js} +4 -4
  41. package/bin/{chunk-t2hy6tj9.js → chunk-a4056d0r.js} +1 -1
  42. package/bin/{chunk-ze20rm02.js → chunk-a796sgcw.js} +4 -4
  43. package/bin/{chunk-kpgfqkp0.js → chunk-afnzb9ne.js} +2 -2
  44. package/bin/chunk-apfrw0wd.js +3 -0
  45. package/bin/{chunk-wndm3px3.js → chunk-axmd242s.js} +1 -1
  46. package/bin/{chunk-nr20tvnw.js → chunk-b3aqmcps.js} +2 -2
  47. package/bin/chunk-b6q287d1.js +2 -0
  48. package/bin/{chunk-j1tkmcae.js → chunk-b9hyc0a1.js} +2 -2
  49. package/bin/chunk-ba33nf0q.js +4 -0
  50. package/bin/chunk-batadmvr.js +2 -0
  51. package/bin/{chunk-1t167cvj.js → chunk-brwbhbmc.js} +7 -7
  52. package/bin/chunk-bvdvp192.js +1 -0
  53. package/bin/{chunk-fahk9h62.js → chunk-crja7whq.js} +2 -2
  54. package/bin/{chunk-98715kc3.js → chunk-d7fwggt6.js} +2 -2
  55. package/bin/chunk-db1msmdh.js +2 -0
  56. package/bin/{chunk-97f2af6d.js → chunk-dbw8c1jj.js} +5 -5
  57. package/bin/{chunk-7gmdnsdg.js → chunk-dj5a6kkh.js} +1 -1
  58. package/bin/chunk-dkx3pmdz.js +1 -0
  59. package/bin/{chunk-071x515q.js → chunk-dmvvt8va.js} +2 -2
  60. package/bin/{chunk-3tedzb2j.js → chunk-dpc11hpd.js} +9 -9
  61. package/bin/{chunk-ks8xzc95.js → chunk-dscq4a4k.js} +2 -2
  62. package/bin/{chunk-jmpb5633.js → chunk-dz076sh7.js} +1 -1
  63. package/bin/chunk-edqd8evk.js +2 -0
  64. package/bin/{chunk-0qaq0sp8.js → chunk-ehpfg3km.js} +2 -2
  65. package/bin/chunk-ey3h4sct.js +2 -0
  66. package/bin/{chunk-vm5fx7td.js → chunk-ga3pahzf.js} +1 -1
  67. package/bin/chunk-gc6m7agb.js +3 -0
  68. package/bin/{chunk-7bcxj1jd.js → chunk-gcjsw9yp.js} +1 -1
  69. package/bin/chunk-gqr5hxhj.js +2 -0
  70. package/bin/{chunk-jrjnqx78.js → chunk-gsfcpcye.js} +1 -1
  71. package/bin/chunk-h9mka9br.js +2 -0
  72. package/bin/chunk-hacyjx1s.js +1 -0
  73. package/bin/chunk-hd6dnnyg.js +2 -0
  74. package/bin/chunk-he5nvmqw.js +1 -0
  75. package/bin/{chunk-reyxk4bw.js → chunk-hnhdq2wd.js} +1 -1
  76. package/bin/{chunk-gt4csat6.js → chunk-hs2r9qaw.js} +2 -2
  77. package/bin/{chunk-fb40xxz3.js → chunk-hxyg5q2a.js} +2 -2
  78. package/bin/chunk-hyr1vtfp.js +1 -0
  79. package/bin/{chunk-zw86wnwe.js → chunk-j9ks8bd7.js} +2 -2
  80. package/bin/{chunk-1gvscz88.js → chunk-jg2v25d2.js} +2 -2
  81. package/bin/chunk-jh8q3885.js +211 -0
  82. package/bin/chunk-jzbrt2vk.js +1 -0
  83. package/bin/chunk-k6avge95.js +10 -0
  84. package/bin/{chunk-msfw3jmc.js → chunk-kg8eg9z3.js} +2 -2
  85. package/bin/chunk-kk42xhgz.js +1 -0
  86. package/bin/{chunk-3ttrhqy3.js → chunk-kmbjp5kp.js} +2 -2
  87. package/bin/{chunk-jgs8an3h.js → chunk-md5pcq46.js} +8 -8
  88. package/bin/{chunk-xarsrs08.js → chunk-mtb9fpj2.js} +1 -1
  89. package/bin/chunk-n3xjwszr.js +2 -0
  90. package/bin/chunk-nqym3zbs.js +1 -0
  91. package/bin/{chunk-579e4wv4.js → chunk-p75f5pgq.js} +2 -2
  92. package/bin/{chunk-hm0dkzed.js → chunk-pdh9bnyj.js} +2 -2
  93. package/bin/{chunk-rhvv1vvk.js → chunk-pgj2kjnn.js} +2 -2
  94. package/bin/{chunk-hmpwg5za.js → chunk-pvg3msgw.js} +8 -8
  95. package/bin/{chunk-4991gz3y.js → chunk-pwkby9h7.js} +6 -6
  96. package/bin/{chunk-fnmwksnb.js → chunk-qbqym9m6.js} +2 -2
  97. package/bin/{chunk-4wy87hwd.js → chunk-qgkbxw1k.js} +2 -2
  98. package/bin/{chunk-1j27fzy1.js → chunk-qs7855cz.js} +2 -2
  99. package/bin/{chunk-7jtmwt5a.js → chunk-radcwage.js} +2 -2
  100. package/bin/{chunk-gk2q9a3f.js → chunk-rmzcarv9.js} +2 -2
  101. package/bin/{chunk-s2fnfyn9.js → chunk-rp4pc6kz.js} +1 -1
  102. package/bin/{chunk-5adsx8x4.js → chunk-rsd164d9.js} +2 -2
  103. package/bin/{chunk-hk5rc6cd.js → chunk-s05cdax2.js} +4 -4
  104. package/bin/{chunk-pazjhrnf.js → chunk-sab7tjxw.js} +5 -5
  105. package/bin/chunk-sebbjvgv.css +1 -0
  106. package/bin/{chunk-bkr5zm4h.js → chunk-t350k3s1.js} +1 -1
  107. package/bin/{chunk-4v41a1r9.js → chunk-t7bvde99.js} +3 -3
  108. package/bin/chunk-t8gv2ekj.js +14 -0
  109. package/bin/chunk-teqprbd8.js +2 -0
  110. package/bin/chunk-tgr86ac4.js +2 -0
  111. package/bin/{chunk-5hg6kcfz.js → chunk-v8v8vdf7.js} +9 -9
  112. package/bin/chunk-vm5tn0zm.js +2 -0
  113. package/bin/chunk-vzj2j11x.js +2 -0
  114. package/bin/chunk-w1wxzqqb.js +2 -0
  115. package/bin/chunk-wmjp8dcm.js +1 -0
  116. package/bin/chunk-wy8dkyxj.js +1 -0
  117. package/bin/{chunk-a6gx7f5q.js → chunk-y1b3ck7m.js} +1 -1
  118. package/bin/{chunk-1xh34aew.js → chunk-y20sbaz5.js} +2 -2
  119. package/bin/{chunk-qsr1a0rp.js → chunk-y56yvezn.js} +1 -1
  120. package/bin/{chunk-9t8n2des.js → chunk-yfr0hzb7.js} +2 -2
  121. package/bin/chunk-ysv80zyb.js +5 -0
  122. package/bin/chunk-z08bqvkc.js +42 -0
  123. package/bin/{chunk-5tcdwep5.js → chunk-z6jpt0h6.js} +4 -4
  124. package/bin/shumai-app.html +1 -1
  125. package/bin/shumai-app.js +605 -370
  126. package/package.json +7 -7
  127. package/prisma/migrations/20260913130237_add_asset_comment_asset_id_idx/migration.sql +2 -0
  128. package/prisma/migrations/20260914024424_add_asset_comment_reactions/migration.sql +22 -0
  129. package/prisma/migrations/20260914064432_limit_reaction_code_length/migration.sql +8 -0
  130. package/prisma/migrations/20260914092940_add_jpeg_preview_flags/migration.sql +5 -0
  131. package/prisma/schema.prisma +22 -0
  132. package/bin/chunk-0cmx7k4c.js +0 -1
  133. package/bin/chunk-16xax8kk.js +0 -1
  134. package/bin/chunk-2w5xqhjm.js +0 -1
  135. package/bin/chunk-3zkasqb8.js +0 -1
  136. package/bin/chunk-453ykvaw.js +0 -2
  137. package/bin/chunk-4mjywsj8.js +0 -3
  138. package/bin/chunk-5vzrpz50.js +0 -2
  139. package/bin/chunk-77fmkpdz.js +0 -10
  140. package/bin/chunk-7kjgvxqa.js +0 -2
  141. package/bin/chunk-7pw1550a.js +0 -2
  142. package/bin/chunk-7rhz2gze.js +0 -211
  143. package/bin/chunk-837fky18.js +0 -3
  144. package/bin/chunk-84as6x83.js +0 -1
  145. package/bin/chunk-8e28hcny.js +0 -2
  146. package/bin/chunk-9ccw540k.js +0 -2
  147. package/bin/chunk-9ybt6vbm.js +0 -1
  148. package/bin/chunk-avwgktxb.js +0 -2
  149. package/bin/chunk-d27mm390.js +0 -1
  150. package/bin/chunk-dj92fss9.js +0 -2
  151. package/bin/chunk-f6svp4dp.js +0 -2
  152. package/bin/chunk-fsyzs0tf.js +0 -1
  153. package/bin/chunk-fxecgp5k.js +0 -1
  154. package/bin/chunk-gc5sbfa5.js +0 -2
  155. package/bin/chunk-gdm6yfqq.js +0 -2
  156. package/bin/chunk-gye8gabk.js +0 -2
  157. package/bin/chunk-j2bvj2yn.js +0 -2
  158. package/bin/chunk-jffktpqg.js +0 -1
  159. package/bin/chunk-k2k9vjq6.js +0 -1
  160. package/bin/chunk-m9pr03kn.js +0 -2
  161. package/bin/chunk-mfn9qjm4.js +0 -2
  162. package/bin/chunk-nbdw8fen.js +0 -1
  163. package/bin/chunk-q806pqeh.js +0 -1
  164. package/bin/chunk-qka4mkmj.js +0 -2
  165. package/bin/chunk-rchsme43.js +0 -3
  166. package/bin/chunk-rqf7999q.js +0 -42
  167. package/bin/chunk-rssgmj7x.js +0 -2
  168. package/bin/chunk-t7nsgg5k.js +0 -4
  169. package/bin/chunk-tm7f32c7.js +0 -14
  170. package/bin/chunk-vy8gntez.js +0 -1
  171. package/bin/chunk-vyzptrea.js +0 -2
  172. package/bin/chunk-wdsf44hs.js +0 -2
  173. package/bin/chunk-x5jwwvs0.js +0 -1
  174. package/bin/chunk-x92cq59c.js +0 -1
  175. package/bin/chunk-xtf3c29c.css +0 -1
  176. package/bin/chunk-xx337zcw.js +0 -2
  177. package/bin/chunk-xz6713tj.js +0 -2
  178. package/bin/chunk-yfnem6se.js +0 -2
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{He,jt}from"./chunk-jgs8an3h.js";import{z}from"./chunk-fnmwksnb.js";var _=z(He());var N=(e)=>Boolean(e)&&typeof e==="object"&&typeof e.AccessKeyId==="string"&&typeof e.SecretAccessKey==="string"&&typeof e.Token==="string"&&typeof e.Expiration==="string",h=(e)=>({accessKeyId:e.AccessKeyId,secretAccessKey:e.SecretAccessKey,sessionToken:e.Token,expiration:new Date(e.Expiration),...e.AccountId&&{accountId:e.AccountId}});var C=({maxRetries:e=0,timeout:t=1000})=>({maxRetries:e,timeout:t});var v=z(He());import R from"http";function E(e){return new Promise((t,n)=>{let o=R.request({method:"GET",...e,hostname:e.hostname?.replace(/^\[(.+)\]$/,"$1")});o.on("error",(r)=>{n(Object.assign(new v.ProviderError("Unable to connect to instance metadata service"),r)),o.destroy()}),o.on("timeout",()=>{n(new v.ProviderError("TimeoutError from instance metadata service")),o.destroy()}),o.on("response",(r)=>{let{statusCode:a=400}=r;if(a<200||300<=a)n(Object.assign(new v.ProviderError("Error response received from instance metadata service"),{statusCode:a})),o.destroy();let p=[];r.on("data",(s)=>{p.push(s)}),r.on("end",()=>{t(Buffer.concat(p)),o.destroy()})}),o.end()})}var T=(e,t)=>{let n=e();for(let o=0;o<t;o++)n=n.catch(e);return n};var A="AWS_CONTAINER_CREDENTIALS_FULL_URI",g="AWS_CONTAINER_CREDENTIALS_RELATIVE_URI",D="AWS_CONTAINER_AUTHORIZATION_TOKEN",G=(e={})=>{let{timeout:t,maxRetries:n}=C(e);return()=>T(async()=>{let o=await J({logger:e.logger}),r=JSON.parse(await H(t,o));if(!N(r))throw new _.CredentialsProviderError("Invalid response received from instance metadata service.",{logger:e.logger});return h(r)},n)},H=async(e,t)=>{if(process.env[D])t.headers={...t.headers,Authorization:process.env[D]};return(await E({...t,timeout:e})).toString()},q="169.254.170.2",Y=new Set(["localhost","127.0.0.1"]),j=new Set(["http:","https:"]),J=async({logger:e})=>{if(process.env[g])return{hostname:q,path:process.env[g]};if(process.env[A]){let t;try{t=new URL(process.env[A])}catch{throw new _.CredentialsProviderError(`${process.env[A]} is not a valid container metadata service URL`,{tryNextLink:!1,logger:e})}if(!t.hostname||!Y.has(t.hostname))throw new _.CredentialsProviderError(`${t.hostname} is not a valid container metadata service hostname`,{tryNextLink:!1,logger:e});if(!t.protocol||!j.has(t.protocol))throw new _.CredentialsProviderError(`${t.protocol} is not a valid container metadata service protocol`,{tryNextLink:!1,logger:e});return{protocol:t.protocol,hostname:t.hostname,path:t.pathname+t.search,port:t.port?parseInt(t.port,10):void 0}}throw new _.CredentialsProviderError(`The container metadata credential provider cannot be used unless the ${g} or ${A} environment variable is set`,{tryNextLink:!1,logger:e})};var u=z(He());var y=z(He());class O extends y.CredentialsProviderError{tryNextLink;name="InstanceMetadataV1FallbackError";constructor(e,t=!0){super(e,t);this.tryNextLink=t,Object.setPrototypeOf(this,O.prototype)}}var w=z(He()),F=z(jt());var S;(function(e){e.IPv4="http://169.254.169.254",e.IPv6="http://[fd00:ec2::254]"})(S||(S={}));var P={environmentVariableSelector:(e)=>e.AWS_EC2_METADATA_SERVICE_ENDPOINT,configFileSelector:(e)=>e.ec2_metadata_service_endpoint,default:void 0};var l;(function(e){e.IPv4="IPv4",e.IPv6="IPv6"})(l||(l={}));var X="AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE",Z="ec2_metadata_service_endpoint_mode",L={environmentVariableSelector:(e)=>e[X],configFileSelector:(e)=>e[Z],default:l.IPv4};var b=async()=>F.parseUrl(await Q()||await ee()),Q=async()=>w.loadConfig(P)(),ee=async()=>{let e=await w.loadConfig(L)();switch(e){case l.IPv4:return S.IPv4;case l.IPv6:return S.IPv6;default:throw Error(`Unsupported endpoint mode: ${e}. Select from ${Object.values(l)}`)}};var M=(e,t)=>{let n=300+Math.floor(Math.random()*300),o=new Date(Date.now()+n*1000);t.warn(`Attempting credential expiration extension due to a credential service availability issue. A refresh of these credentials will be attempted after ${new Date(o)}.
2
+ import{$e,qt}from"./chunk-md5pcq46.js";import{z}from"./chunk-qbqym9m6.js";var _=z($e());var N=(e)=>Boolean(e)&&typeof e==="object"&&typeof e.AccessKeyId==="string"&&typeof e.SecretAccessKey==="string"&&typeof e.Token==="string"&&typeof e.Expiration==="string",h=(e)=>({accessKeyId:e.AccessKeyId,secretAccessKey:e.SecretAccessKey,sessionToken:e.Token,expiration:new Date(e.Expiration),...e.AccountId&&{accountId:e.AccountId}});var C=({maxRetries:e=0,timeout:t=1000})=>({maxRetries:e,timeout:t});var v=z($e());import R from"http";function E(e){return new Promise((t,n)=>{let o=R.request({method:"GET",...e,hostname:e.hostname?.replace(/^\[(.+)\]$/,"$1")});o.on("error",(r)=>{n(Object.assign(new v.ProviderError("Unable to connect to instance metadata service"),r)),o.destroy()}),o.on("timeout",()=>{n(new v.ProviderError("TimeoutError from instance metadata service")),o.destroy()}),o.on("response",(r)=>{let{statusCode:a=400}=r;if(a<200||300<=a)n(Object.assign(new v.ProviderError("Error response received from instance metadata service"),{statusCode:a})),o.destroy();let p=[];r.on("data",(s)=>{p.push(s)}),r.on("end",()=>{t(Buffer.concat(p)),o.destroy()})}),o.end()})}var T=(e,t)=>{let n=e();for(let o=0;o<t;o++)n=n.catch(e);return n};var A="AWS_CONTAINER_CREDENTIALS_FULL_URI",g="AWS_CONTAINER_CREDENTIALS_RELATIVE_URI",D="AWS_CONTAINER_AUTHORIZATION_TOKEN",G=(e={})=>{let{timeout:t,maxRetries:n}=C(e);return()=>T(async()=>{let o=await J({logger:e.logger}),r=JSON.parse(await H(t,o));if(!N(r))throw new _.CredentialsProviderError("Invalid response received from instance metadata service.",{logger:e.logger});return h(r)},n)},H=async(e,t)=>{if(process.env[D])t.headers={...t.headers,Authorization:process.env[D]};return(await E({...t,timeout:e})).toString()},q="169.254.170.2",Y=new Set(["localhost","127.0.0.1"]),j=new Set(["http:","https:"]),J=async({logger:e})=>{if(process.env[g])return{hostname:q,path:process.env[g]};if(process.env[A]){let t;try{t=new URL(process.env[A])}catch{throw new _.CredentialsProviderError(`${process.env[A]} is not a valid container metadata service URL`,{tryNextLink:!1,logger:e})}if(!t.hostname||!Y.has(t.hostname))throw new _.CredentialsProviderError(`${t.hostname} is not a valid container metadata service hostname`,{tryNextLink:!1,logger:e});if(!t.protocol||!j.has(t.protocol))throw new _.CredentialsProviderError(`${t.protocol} is not a valid container metadata service protocol`,{tryNextLink:!1,logger:e});return{protocol:t.protocol,hostname:t.hostname,path:t.pathname+t.search,port:t.port?parseInt(t.port,10):void 0}}throw new _.CredentialsProviderError(`The container metadata credential provider cannot be used unless the ${g} or ${A} environment variable is set`,{tryNextLink:!1,logger:e})};var u=z($e());var y=z($e());class O extends y.CredentialsProviderError{tryNextLink;name="InstanceMetadataV1FallbackError";constructor(e,t=!0){super(e,t);this.tryNextLink=t,Object.setPrototypeOf(this,O.prototype)}}var w=z($e()),F=z(qt());var S;(function(e){e.IPv4="http://169.254.169.254",e.IPv6="http://[fd00:ec2::254]"})(S||(S={}));var P={environmentVariableSelector:(e)=>e.AWS_EC2_METADATA_SERVICE_ENDPOINT,configFileSelector:(e)=>e.ec2_metadata_service_endpoint,default:void 0};var l;(function(e){e.IPv4="IPv4",e.IPv6="IPv6"})(l||(l={}));var X="AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE",Z="ec2_metadata_service_endpoint_mode",L={environmentVariableSelector:(e)=>e[X],configFileSelector:(e)=>e[Z],default:l.IPv4};var b=async()=>F.parseUrl(await Q()||await ee()),Q=async()=>w.loadConfig(P)(),ee=async()=>{let e=await w.loadConfig(L)();switch(e){case l.IPv4:return S.IPv4;case l.IPv6:return S.IPv6;default:throw Error(`Unsupported endpoint mode: ${e}. Select from ${Object.values(l)}`)}};var M=(e,t)=>{let n=300+Math.floor(Math.random()*300),o=new Date(Date.now()+n*1000);t.warn(`Attempting credential expiration extension due to a credential service availability issue. A refresh of these credentials will be attempted after ${new Date(o)}.
3
3
  For more information, please visit: https://docs.aws.amazon.com/sdkref/latest/guide/feature-static-credentials.html`);let r=e.originalExpiration??e.expiration;return{...e,...r?{originalExpiration:r}:{},expiration:o}};var V=(e,t={})=>{let n=t?.logger||console,o;return async()=>{let r;try{if(r=await e(),r.expiration&&r.expiration.getTime()<Date.now())r=M(r,n)}catch(a){if(o)n.warn("Credential renew failed: ",a),r=M(o,n);else throw a}return o=r,r}};var W="/latest/meta-data/iam/security-credentials/",te="/latest/api/token",x="AWS_EC2_METADATA_V1_DISABLED",k="ec2_metadata_v1_disabled",U="x-aws-ec2-metadata-token",oe=(e={})=>V(re(e),{logger:e.logger}),re=(e={})=>{let t=!1,{logger:n,profile:o}=e,{timeout:r,maxRetries:a}=C(e),p=async(s,m)=>{if(t||m.headers?.[U]==null){let i=!1,c=!1,B=await u.loadConfig({environmentVariableSelector:(d)=>{let f=d[x];if(c=!!f&&f!=="false",f===void 0)throw new u.CredentialsProviderError(`${x} not set in env, checking config file next.`,{logger:e.logger});return c},configFileSelector:(d)=>{let f=d[k];return i=!!f&&f!=="false",i},default:!1},{profile:o})();if(e.ec2MetadataV1Disabled||B){let d=[];if(e.ec2MetadataV1Disabled)d.push("credential provider initialization (runtime option ec2MetadataV1Disabled)");if(i)d.push(`config file profile (${k})`);if(c)d.push(`process environment variable (${x})`);throw new O(`AWS EC2 Metadata v1 fallback has been blocked by AWS SDK configuration in the following: [${d.join(", ")}].`)}}let K=(await T(async()=>{let i;try{i=await ae(m)}catch(c){if(c.statusCode===401)t=!1;throw c}return i},s)).trim();return T(async()=>{let i;try{i=await se(K,m,e)}catch(c){if(c.statusCode===401)t=!1;throw c}return i},s)};return async()=>{let s=await b();if(t)return n?.debug("AWS SDK Instance Metadata","using v1 fallback (no token fetch)"),p(a,{...s,timeout:r});else{let m;try{m=(await ne({...s,timeout:r})).toString()}catch(I){if(I?.statusCode===400)throw Object.assign(I,{message:"EC2 Metadata token request returned error"});else if(I.message==="TimeoutError"||[403,404,405].includes(I.statusCode))t=!0;return n?.debug("AWS SDK Instance Metadata","using v1 fallback (initial)"),p(a,{...s,timeout:r})}return p(a,{...s,headers:{[U]:m},timeout:r})}}},ne=async(e)=>E({...e,path:te,method:"PUT",headers:{"x-aws-ec2-metadata-token-ttl-seconds":"21600"}}),ae=async(e)=>(await E({...e,path:W})).toString(),se=async(e,t,n)=>{let o=JSON.parse((await E({...t,path:W+e})).toString());if(!N(o))throw new u.CredentialsProviderError("Invalid response received from instance metadata service.",{logger:n.logger});return h(o)};export{A as ENV_CMDS_FULL_URI,g as ENV_CMDS_RELATIVE_URI,G as fromContainerMetadata,oe as fromInstanceMetadata};
@@ -0,0 +1 @@
1
+ import{P,h,D,b,u,S,Z,t,o,K,L,B,ft,Ue,A,I,F,ke,rn,bt,eo,to,Po,pe,we,Re,E,he,ge,Ae,W,Vr,Vt,mf,ym,gf,M0,k0,_f,yf,Ne,E_,Xa,z_,H_,th,it,Tf,Ky,ib,fh,mb,_b,yb,bb,vb,wb,ki,ma,Zc,Pf,Ri,Qb,rv,yv,Tv,kv,$v,Vv,Qv,gd,Kw,Nx,Px,zx,qx,op,tg,sp,SS,ES,El,PE,HE,Fo,QE,oC,iC,Zg,zg,zc,Cl,Cp,Ip,Tp,Il,jc,qc,Mp,kp,Hc,b1,v1,w1,x1,S1,gn,Bp,X1,eI,Up,nA,iI,lI,cI,uI,dI,ue,ie,me,Ge,le,H,ce,lt,Nr,An,$n,Gc,k,yr,on,Q,je,Fe,Le,Ze,Be,ne,ya,$t,hr,wt,Yp}from"./chunk-jh8q3885.js";import{zi,Ia}from"./chunk-07jszkhj.js";import{Xc,wa}from"./chunk-t8gv2ekj.js";import"./chunk-w1wxzqqb.js";import"./chunk-ey3h4sct.js";import"./chunk-vzj2j11x.js";import{Er}from"./chunk-ehpfg3km.js";import{ai,Zl}from"./chunk-2yr5k567.js";import{si}from"./chunk-kmbjp5kp.js";import{Pl}from"./chunk-0wvhahzh.js";import{Ol}from"./chunk-2qjfpmcf.js";import{tr}from"./chunk-2z1pnt7h.js";import"./chunk-d7fwggt6.js";import{Hl,$l}from"./chunk-n3xjwszr.js";import"./chunk-2jrjwaqr.js";import"./chunk-rmzcarv9.js";import{lo}from"./chunk-yfr0hzb7.js";import"./chunk-6y4xkcte.js";import{co}from"./chunk-80qz30dc.js";import{Rr}from"./chunk-3d5rm1d1.js";S();var Ct=[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]],dt=I("folder-open",Ct);var _t=[["path",{d:"M2 5h20",key:"1fs1ex"}],["path",{d:"M6 12h12",key:"8npq4p"}],["path",{d:"M9 19h6",key:"456am0"}]],ct=I("list-filter",_t);S();function It({ratio:a}){switch(a){case"16:9":return t("span",{className:"inline-block w-4 h-2.5 border border-current rounded-[1px] shrink-0"});case"9:16":return t("span",{className:"inline-block w-2.5 h-4 border border-current rounded-[1px] shrink-0"});case"4:3":return t("span",{className:"inline-block w-3.5 h-2.5 border border-current rounded-[1px] shrink-0"});case"3:4":return t("span",{className:"inline-block w-2.5 h-3.5 border border-current rounded-[1px] shrink-0"});case"1:1":return t("span",{className:"inline-block w-3 h-3 border border-current rounded-[1px] shrink-0"});default:return t("span",{className:"inline-block w-4 h-2.5 border border-current rounded-[1px] shrink-0"})}}function st(){return Math.random().toString(36).substring(2,9)}function mt(){return{id:st(),type:"text",text:"CONFIDENTIAL",x:0.5,y:0.5,size:0.05,color:"#999999",opacity:0.5,rotation:-30}}function Ft(){return{id:st(),type:"image",imageAssetKey:"",x:0.5,y:0.5,size:0.15,opacity:0.5,rotation:0}}var rt=[{id:"dark",label:"Dark Slate",bg:"#1e293b",dot:"#475569"},{id:"black",label:"Black",bg:"#000000",dot:"#404040"},{id:"gray",label:"Slate Gray",bg:"#64748b",dot:"#cbd5e1"},{id:"white",label:"White",bg:"#ffffff",dot:"#94a3b8"},{id:"green",label:"Chroma Green",bg:"#059669",dot:"#047857"}],Dt={"16:9":1.7777777777777777,"9:16":0.5625,"4:3":1.3333333333333333,"3:4":0.75,"1:1":1};function pt({open:a,onOpenChange:N,initialConfig:x,shareId:p,teamId:C,onSaveSuccess:v}){let q=K(),[d,w]=u([]),[c,g]=u(null),[R,V]=u(null),[_,xe]=u("16:9"),[be,ye]=u("grid"),[Ie,J]=u(!1),[ve,oe]=u("new"),[fe,ee]=u(""),[te,ae]=u(null),M=b(null),re=b(null),[se,De]=u({w:0,h:0}),[T,G]=u(!1),s=P((e)=>{if(re.current=e,!e)return;let l=()=>{let{clientWidth:z,clientHeight:y}=e;if(z<=0||y<=0)return;let U=Dt[_],at=z,qe=at/U;if(qe>y)qe=y,at=qe*U;De({w:Math.round(at),h:Math.round(qe)})};l();let n=new ResizeObserver(l);return n.observe(e),()=>{n.disconnect(),re.current=null}},[_]),X=lt((e)=>e.teamId),Se=C||X,[Ke,Pe]=u(!1),[Y,Me]=u({}),de=b(null),Ce=A.api.teams[":teamId"].files.$post,Te=async(e,l)=>{let n=e.target.files?.[0];if(!n)return;if(n.size>1048576){if(k.error(Qb()),de.current)de.current.value="";return}if(!Se){k.error(Zc());return}Pe(!0);let z=URL.createObjectURL(n);Me((y)=>({...y,[l]:z}));try{let y=await Ce({param:{teamId:Se},form:{file:n}});if(!y.ok)throw Error(Zc());let U=await y.json();j(l,{imageAssetKey:U.key,imageAssetUrl:U.url})}catch(y){let U=y instanceof Error?y.message:Zc();k.error(U)}finally{if(Pe(!1),de.current)de.current.value=""}};h(()=>{if(a){if(x?.blocks&&x.blocks.length>0)w(x.blocks),g(x.blocks[0].id);else{let e=mt();w([e]),g(e.id)}V(null)}},[a,x]);let{data:O=[]}=L({queryKey:["watermark-templates",C],queryFn:async()=>{let e=await A.api["watermark-templates"].$get({query:C?{teamId:C}:{}});if(!e.ok)return[];return await e.json()},enabled:a}),Ee=A.api.shares[":shareId"].watermark.$put,{mutate:_e,isPending:Qe}=B({mutationFn:async(e)=>{let l=await Ee({param:{shareId:p},json:{enabled:!0,config:e}});if(!l.ok){let n=await l.json().catch(()=>null);throw Error(n?.error||ma())}return await l.json()},onSuccess:()=>{q.invalidateQueries({queryKey:["share",p]}),q.invalidateQueries({queryKey:["shares"]}),k.success(dI()),N(!1),v?.()},onError:(e)=>{k.error(e.message||ma())}}),Ve=A.api["watermark-templates"].$post,{mutate:He,isPending:Xe}=B({mutationFn:async({name:e,config:l})=>{let n=await Ve({json:{name:e,teamId:C||void 0,config:l}});if(!n.ok)throw Error(ma());return await n.json()},onSuccess:(e)=>{q.invalidateQueries({queryKey:["watermark-templates"]}),V(e.id),J(!1),k.success(w1())},onError:()=>{k.error(ma())}}),Ye=A.api["watermark-templates"][":templateId"].$put,{mutate:ze,isPending:Je}=B({mutationFn:async({templateId:e,config:l})=>{let n=await Ye({param:{templateId:e},json:{config:l}});if(!n.ok)throw Error(ma());return await n.json()},onSuccess:()=>{q.invalidateQueries({queryKey:["watermark-templates"]}),J(!1),k.success(x1())},onError:()=>{k.error(ma())}}),r=A.api["watermark-templates"][":templateId"].$delete,{mutate:m}=B({mutationFn:async(e)=>{if(!(await r({param:{templateId:e}})).ok)throw Error(ki())},onSuccess:(e,l)=>{if(q.invalidateQueries({queryKey:["watermark-templates"]}),R===l)V(null);k.success(b1())},onError:()=>{k.error(ki())}}),f=d.findIndex((e)=>e.id===c),i=f>=0?d[f]:null,We=()=>{let e=mt();w((l)=>[...l,e]),g(e.id)},xt=()=>{let e=Ft();w((l)=>[...l,e]),g(e.id)},nt=(e)=>{if(!e)return;w((l)=>{let n=l.filter((z)=>z.id!==e);if(c===e)g(n.length>0?n[Math.max(0,f-1)].id:null);return n})},j=(e,l)=>{w((n)=>n.map((z)=>z.id===e?{...z,...l}:z))},ht=()=>{if(d.length===0)return;let e=(f-1+d.length)%d.length;g(d[e].id)},vt=()=>{if(d.length===0)return;let e=(f+1)%d.length;g(d[e].id)},yt=(e,l)=>{e.stopPropagation(),g(l),G(!0)},et=P((e)=>{if(!T||!c||!M.current)return;let l=M.current.getBoundingClientRect(),n=(e.clientX-l.left)/l.width,z=(e.clientY-l.top)/l.height,y=Math.max(0,Math.min(1,Math.round(n*100)/100)),U=Math.max(0,Math.min(1,Math.round(z*100)/100));j(c,{x:y,y:U})},[T,c]),tt=P(()=>{G(!1)},[]);h(()=>{if(T)window.addEventListener("mousemove",et),window.addEventListener("mouseup",tt);return()=>{window.removeEventListener("mousemove",et),window.removeEventListener("mouseup",tt)}},[T,et,tt]),h(()=>{let e=(l)=>{if(!a||!c)return;let n=l.target?.tagName?.toLowerCase();if(n==="input"||n==="textarea"||n==="select")return;if(l.key==="Delete"||l.key==="Backspace")l.preventDefault(),nt(c)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[a,c,f]);let Nt=(e)=>{if(e.config?.blocks&&e.config.blocks.length>0){let l=e.config.blocks.map((n)=>({...n,id:st()}));w(l),g(l[0].id),V(e.id)}},kt=()=>{if(d.length===0){k.error(Px());return}_e({blocks:d})},St=()=>{if(ve==="new"){if(!fe.trim()){k.error(fh());return}He({name:fe.trim(),config:{blocks:d}})}else{let e=te||R;if(!e){k.error(Zg());return}ze({templateId:e,config:{blocks:d}})}};return o(Z,{children:[t(ue,{open:a,onOpenChange:N,children:o(ie,{showCloseButton:!1,className:"sm:max-w-[1400px] max-w-[95vw] w-[95vw] h-[88vh] flex flex-col p-0 gap-0 overflow-hidden",onPointerDownOutside:(e)=>e.preventDefault(),children:[o("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border bg-card",children:[t("div",{className:"flex items-center gap-3",children:t(le,{className:"text-base font-semibold",children:lI()})}),o("div",{className:"flex items-center gap-2",children:[o(he,{modal:!1,children:[t(ge,{asChild:!0,children:o(E,{variant:"outline",size:"sm",className:"gap-2 text-xs",children:[t(dt,{className:"h-4 w-4 text-muted-foreground"}),cI()]})}),o(Ae,{align:"end",className:"w-56",children:[t(Vr,{className:"text-xs font-semibold text-muted-foreground",children:Qv()}),O.length===0?t("div",{className:"px-2 py-1.5 text-xs text-muted-foreground italic",children:Nx()}):O.map((e)=>o(W,{onClick:()=>Nt(e),className:"flex items-center justify-between text-xs cursor-pointer",children:[t("span",{className:"truncate flex-1",children:e.name}),R===e.id&&t(ke,{className:"h-3.5 w-3.5 text-primary ml-2 flex-shrink-0"}),t(E,{variant:"ghost",size:"icon",className:"h-5 w-5 hover:bg-destructive/10 hover:text-destructive ml-1",onClick:(l)=>{l.stopPropagation(),m(e.id)},children:t(we,{className:"h-3 w-3"})})]},e.id)),t(Vt,{}),o(W,{onClick:()=>{oe("new"),ee(""),J(!0)},className:"text-xs gap-2 cursor-pointer",children:[t(pe,{className:"h-3.5 w-3.5 text-primary"}),th()]}),O.length>0&&o(W,{onClick:()=>{oe("overwrite"),ae(R||O[0].id),J(!0)},className:"text-xs gap-2 cursor-pointer",children:[t(si,{className:"h-3.5 w-3.5 text-muted-foreground"}),tg()]})]})]}),t(E,{variant:"outline",size:"sm",className:"text-xs",onClick:()=>N(!1),children:Ne()}),o(E,{size:"sm",className:"text-xs bg-primary hover:bg-primary/90 text-primary-foreground gap-1.5",disabled:Qe,onClick:kt,children:[t(si,{className:"h-3.5 w-3.5"}),QE()]})]})]}),o("div",{className:"flex-1 flex overflow-hidden",children:[o("div",{className:"w-[65%] flex flex-col p-4 bg-muted/20 border-r border-border overflow-hidden select-none",children:[o("div",{className:"flex items-center justify-between mb-3",children:[t("div",{className:"flex items-center gap-1 bg-muted/60 p-1 rounded-md border border-border/60",children:["16:9","9:16","4:3","3:4","1:1"].map((e)=>o(E,{variant:_===e?"secondary":"ghost",size:"sm",className:$e("h-7 px-2.5 text-xs gap-1.5 font-mono transition-all",_===e?"bg-background shadow-xs font-semibold text-foreground border border-border/50":"text-muted-foreground hover:text-foreground"),onClick:()=>xe(e),children:[t(It,{ratio:e}),t("span",{children:e})]},e))}),t("div",{className:"flex items-center gap-1.5 bg-background border border-border/60 rounded-md p-1",children:rt.map((e)=>t("button",{type:"button",onClick:()=>ye(e.id),style:{backgroundColor:e.bg},className:$e("w-5 h-5 rounded-full border border-border/80 transition-all cursor-pointer relative",be===e.id?"ring-2 ring-primary ring-offset-1 scale-110":"hover:scale-105 opacity-80 hover:opacity-100"),title:e.label},e.id))})]}),t("div",{ref:s,className:"flex-1 flex items-center justify-center overflow-hidden",children:(()=>{let e=rt.find((n)=>n.id===be)||rt[0],l=se.w>0&&se.h>0;return t("div",{ref:M,onClick:()=>g(null),style:{backgroundColor:e.bg,backgroundImage:`radial-gradient(${e.dot} 1px, transparent 1px)`,backgroundSize:"16px 16px",...l?{width:se.w,height:se.h}:{}},className:$e("relative rounded-lg border border-border overflow-hidden shadow-inner transition-all",_==="16:9"&&"aspect-[16/9] w-full max-h-full",_==="9:16"&&"aspect-[9/16] h-full max-w-full",_==="4:3"&&"aspect-[4/3] w-full max-h-full",_==="3:4"&&"aspect-[3/4] h-full max-w-full",_==="1:1"&&"aspect-square h-full max-w-full"),children:d.map((n)=>{let z=n.id===c,y=n.size*(se.w||640);return t("div",{onMouseDown:(U)=>yt(U,n.id),onClick:(U)=>{U.stopPropagation(),g(n.id)},style:{left:`${n.x*100}%`,top:`${n.y*100}%`,transform:`translate(-50%, -50%) rotate(${n.rotation}deg)`,opacity:n.opacity},className:$e("absolute cursor-move select-none transition-shadow rounded p-1.5 flex items-center justify-center",z?"ring-2 ring-primary ring-offset-2 ring-offset-background/80 bg-primary/10":"hover:ring-1 hover:ring-muted-foreground/50"),children:n.type==="text"?t("span",{style:{fontSize:`${y}px`,color:n.color,lineHeight:1,whiteSpace:"nowrap",fontWeight:700,textShadow:"0 1px 3px rgba(0,0,0,0.5)"},children:n.text||"Text"}):t("div",{style:{width:`${y}px`,height:`${y}px`},className:"bg-primary/20 border border-primary/40 rounded flex items-center justify-center p-1 overflow-hidden",children:Y[n.id]||n.imageAssetUrl?t("img",{src:Y[n.id]||n.imageAssetUrl,alt:"Watermark logo",className:"w-full h-full object-contain pointer-events-none"}):t(eo,{className:"h-1/2 w-1/2 opacity-70 text-primary"})})},n.id)})})})()})]}),o("div",{className:"w-[35%] flex flex-col bg-card overflow-hidden border-l border-border",children:[t("div",{className:"p-4 border-b border-border bg-muted/10 flex items-center justify-between",children:o("div",{className:"flex items-center gap-2",children:[t(to,{className:"h-4 w-4 text-muted-foreground"}),t("span",{className:"text-xs font-semibold",children:nA()})]})}),o("div",{className:"p-3 border-b border-border bg-background flex items-center justify-between gap-2",children:[o("div",{className:"flex items-center gap-1",children:[t(E,{variant:"outline",size:"icon",className:"h-7 w-7",disabled:d.length<=1,onClick:ht,children:t(rn,{className:"h-4 w-4"})}),o(he,{modal:!1,children:[t(ge,{asChild:!0,children:t(E,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs font-mono",children:d.length===0?"0 / 0":`${f+1} / ${d.length}`})}),t(Ae,{align:"start",className:"w-48",children:d.map((e,l)=>o(W,{onClick:()=>g(e.id),className:"text-xs flex items-center justify-between cursor-pointer",children:[o("span",{className:"flex items-center gap-2 truncate",children:[e.type==="text"?t(zi,{className:"h-3.5 w-3.5 text-muted-foreground"}):t(eo,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.type==="text"?e.text||"Text":e.imageAssetKey||"Image"]}),o("span",{className:"text-[10px] font-mono text-muted-foreground ml-2",children:["#",l+1]})]},e.id))})]}),t(E,{variant:"outline",size:"icon",className:"h-7 w-7",disabled:d.length<=1,onClick:vt,children:t(bt,{className:"h-4 w-4"})})]}),o("div",{className:"flex items-center gap-1",children:[i&&t(E,{variant:"ghost",size:"icon",className:"h-7 w-7 text-destructive hover:bg-destructive/10",title:it(),onClick:()=>nt(i.id),children:t(we,{className:"h-4 w-4"})}),o(he,{modal:!1,children:[t(ge,{asChild:!0,children:o(E,{size:"sm",className:"h-7 text-xs gap-1",children:[t(pe,{className:"h-3.5 w-3.5"}),mf()]})}),o(Ae,{align:"end",children:[o(W,{onClick:We,className:"text-xs gap-2 cursor-pointer",children:[t(zi,{className:"h-3.5 w-3.5"}),gf()]}),o(W,{onClick:xt,className:"text-xs gap-2 cursor-pointer",children:[t(eo,{className:"h-3.5 w-3.5"}),ym()]})]})]})]})]}),t(ce,{className:"flex-1 min-h-0 p-4",children:i?o("div",{className:"space-y-5 text-xs",children:[o("div",{className:"flex items-center justify-between pb-2 border-b border-border",children:[o("span",{className:"font-semibold text-muted-foreground flex items-center gap-1.5",children:[i.type==="text"?t(zi,{className:"h-4 w-4 text-primary"}):t(eo,{className:"h-4 w-4 text-primary"}),i.type==="text"?gf():ym()]}),o("span",{className:"text-[10px] font-mono text-muted-foreground",children:["ID: ",i.id.slice(0,6)]})]}),i.type==="text"&&o("div",{className:"space-y-2",children:[t(Q,{className:"text-xs",children:S1()}),t(H,{type:"text",value:i.text,onChange:(e)=>j(i.id,{text:e.target.value}),className:"text-xs h-8"})]}),i.type==="image"&&o("div",{className:"space-y-2",children:[o("div",{className:"flex items-center justify-between",children:[t(Q,{className:"text-xs",children:Tv()}),i.imageAssetKey&&o("button",{type:"button",onClick:()=>j(i.id,{imageAssetKey:"",imageAssetUrl:void 0}),className:"text-xs text-muted-foreground hover:text-destructive flex items-center gap-1 font-medium transition-colors cursor-pointer",children:[t(Re,{className:"w-3.5 h-3.5"}),El?El():"Remove"]})]}),t("input",{type:"file",ref:de,className:"hidden",accept:"image/*",onChange:(e)=>Te(e,i.id)}),o("div",{onClick:()=>de.current?.click(),className:"relative aspect-square w-full rounded-xl border border-dashed border-border flex items-center justify-center cursor-pointer overflow-hidden group shadow-inner bg-muted/20 hover:border-primary/50 hover:bg-muted/40 transition-all p-2",children:[Ke&&t("div",{className:"absolute inset-0 bg-background/70 backdrop-blur-xs flex flex-col items-center justify-center gap-2 z-20",children:o("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-background border rounded-full shadow-lg",children:[t(F,{className:"w-4 h-4 animate-spin text-primary"}),t("span",{className:"text-xs font-semibold",children:Up()})]})}),Y[i.id]||i.imageAssetUrl?o(Z,{children:[t("img",{src:Y[i.id]||i.imageAssetUrl,alt:"Uploaded logo preview",className:"max-w-full max-h-full object-contain transition-transform duration-300 group-hover:scale-105"}),o("div",{className:"absolute inset-0 bg-black/45 opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex flex-col items-center justify-center gap-1 text-white z-10",children:[t(lo,{className:"w-5 h-5 transform translate-y-1 group-hover:translate-y-0 transition-transform duration-300"}),t("span",{className:"text-xs font-semibold",children:Bp()})]})]}):o("div",{className:"flex flex-col items-center gap-1.5 text-center p-3",children:[t("div",{className:"p-2 rounded-full bg-background border shadow-xs group-hover:scale-110 transition-transform duration-300",children:t(lo,{className:"w-4 h-4 text-muted-foreground"})}),o("div",{children:[t("p",{className:"text-xs font-medium text-foreground",children:X1()}),t("p",{className:"text-[10px] text-muted-foreground mt-0.5 max-w-[150px] mx-auto leading-normal",children:eI()})]})]})]})]}),o("div",{className:"space-y-2",children:[o("div",{className:"flex items-center justify-between",children:[t(Q,{className:"text-xs",children:i.type==="text"?rv():kv()}),o("span",{className:"font-mono text-[11px] text-muted-foreground",children:[Math.round(i.size*100),"%"]})]}),o("div",{className:"flex items-center gap-3",children:[t(Ia,{min:i.type==="text"?0.01:0.02,max:i.type==="text"?0.12:0.5,step:0.005,value:[i.size],onValueChange:([e])=>j(i.id,{size:e}),className:"flex-1"}),t(H,{type:"number",min:1,max:100,value:Math.round(i.size*100),onChange:(e)=>j(i.id,{size:Math.min(1,Math.max(0.001,Number(e.target.value)/100))}),className:"w-16 h-7 text-xs font-mono text-right"})]})]}),i.type==="text"&&o("div",{className:"space-y-2",children:[o("div",{className:"flex items-center justify-between",children:[t(Q,{className:"text-xs",children:E_()}),t("span",{className:"font-mono text-[11px] text-muted-foreground uppercase",children:i.color})]}),o("div",{className:"flex items-center gap-2",children:[t("input",{type:"color",value:i.color,onChange:(e)=>j(i.id,{color:e.target.value}),className:"w-8 h-8 rounded border border-border cursor-pointer bg-transparent p-0"}),t(H,{type:"text",value:i.color,onChange:(e)=>j(i.id,{color:e.target.value}),className:"flex-1 h-8 text-xs font-mono"})]}),t("div",{className:"flex items-center gap-1.5 pt-1",children:["#FFFFFF","#000000","#999999","#EF4444","#3B82F6","#10B981","#F59E0B"].map((e)=>t("button",{type:"button",onClick:()=>j(i.id,{color:e}),style:{backgroundColor:e},className:"w-5 h-5 rounded-full border border-border hover:scale-110 transition-transform"},e))})]}),o("div",{className:"space-y-2",children:[o("div",{className:"flex items-center justify-between",children:[t(Q,{className:"text-xs",children:zx()}),o("span",{className:"font-mono text-[11px] text-muted-foreground",children:[Math.round(i.opacity*100),"%"]})]}),t(Ia,{min:0,max:1,step:0.01,value:[i.opacity],onValueChange:([e])=>j(i.id,{opacity:e})})]}),o("div",{className:"space-y-2",children:[o("div",{className:"flex items-center justify-between",children:[t(Q,{className:"text-xs",children:HE()}),o("span",{className:"font-mono text-[11px] text-muted-foreground",children:[i.rotation,"°"]})]}),t(Ia,{min:-180,max:180,step:1,value:[i.rotation],onValueChange:([e])=>j(i.id,{rotation:e})}),t("div",{className:"flex items-center gap-1.5 pt-1",children:[-45,-30,0,30,45].map((e)=>o(E,{variant:"outline",size:"sm",className:"h-6 text-[10px] flex-1 px-1 font-mono",onClick:()=>j(i.id,{rotation:e}),children:[e,"°"]},e))})]}),o("div",{className:"space-y-2",children:[o("div",{className:"flex items-center justify-between",children:[t(Q,{className:"text-xs",children:SS()}),o("span",{className:"font-mono text-[11px] text-muted-foreground",children:[Math.round(i.x*100),"%"]})]}),t(Ia,{min:0,max:1,step:0.01,value:[i.x],onValueChange:([e])=>j(i.id,{x:e})})]}),o("div",{className:"space-y-2",children:[o("div",{className:"flex items-center justify-between",children:[t(Q,{className:"text-xs",children:ES()}),o("span",{className:"font-mono text-[11px] text-muted-foreground",children:[Math.round(i.y*100),"%"]})]}),t(Ia,{min:0,max:1,step:0.01,value:[i.y],onValueChange:([e])=>j(i.id,{y:e})})]})]}):o("div",{className:"py-12 text-center text-xs text-muted-foreground space-y-3",children:[t("p",{children:iC()}),o(E,{size:"sm",variant:"outline",onClick:We,children:[t(pe,{className:"h-3.5 w-3.5 mr-1"}),gf()]})]})})]})]})]})}),t(ue,{open:Ie,onOpenChange:J,children:o(ie,{className:"max-w-md",children:[t(me,{children:t(le,{className:"text-sm font-semibold",children:ve==="new"?th():tg()})}),t("div",{className:"py-3 space-y-4 text-xs",children:ve==="new"?o("div",{className:"space-y-2",children:[t(Q,{children:v1()}),t(H,{type:"text",value:fe,onChange:(e)=>ee(e.target.value),placeholder:fh(),className:"text-xs"})]}):o("div",{className:"space-y-2",children:[t(Q,{children:Zg()}),t("select",{value:te||"",onChange:(e)=>ae(e.target.value),className:"w-full h-9 rounded-md border border-input bg-background px-3 text-xs",children:O.map((e)=>t("option",{value:e.id,children:e.name},e.id))})]})}),o(Ge,{children:[t(E,{variant:"outline",size:"sm",className:"text-xs",onClick:()=>J(!1),children:Ne()}),t(E,{size:"sm",className:"text-xs",disabled:Xe||Je,onClick:St,children:Xa()})]})]})})]})}function $e(...a){return a.filter(Boolean).join(" ")}S();function gt({shareLink:a,viewMode:N,onViewModeChange:x,defaultSortOrder:p,onSortOrderChange:C}){let v=K(),[q,d]=u(a.password||""),[w,c]=u(a.expireAt?new Date(a.expireAt):void 0),[g,R]=u(!1);h(()=>{d(a.password||"")},[a.password]);let[V,_]=u(a.hasPassword),[xe,be]=u(!!a.expireAt),{data:ye,refetch:Ie}=L({queryKey:["share-watermark",a.id],queryFn:async()=>{let s=await A.api.shares[":shareId"].watermark.$get({param:{shareId:a.id}});if(!s.ok)return null;return await s.json()},refetchInterval:(s)=>(s.state.data?.watermarkStatus||a.watermarkStatus)==="processing"?3000:!1}),J=A.api.shares[":shareId"].watermark.$put,{mutate:ve}=B({mutationFn:async()=>{let s=await J({param:{shareId:a.id},json:{enabled:!1}});if(!s.ok)throw Error(ma());return await s.json()},onSuccess:()=>{v.invalidateQueries({queryKey:["shares",a.projectId]}),v.invalidateQueries({queryKey:["share",a.id]}),v.invalidateQueries({queryKey:["share-watermark",a.id]}),k.success(iI())}}),oe=ye?.watermarkStatus??a.watermarkStatus??(a.watermarkConfigId?"ready":"disabled"),fe=ye?.watermarkConfig?.config??a.watermarkConfig?.config??null,ee=fe!==null&&oe!=="disabled",{data:te}=L({queryKey:["fields",a.projectId],queryFn:async()=>{let s=await A.api.projects[":projectId"].fields.$get({param:{projectId:a.projectId}});if(!s.ok)throw Error(_b());return await s.json()},enabled:!!a.projectId}),ae=A.api.shares[":shareId"].$put,{mutate:M}=B({mutationFn:async(s)=>{let X=await ae({param:{shareId:a.id},json:s});if(!X.ok)throw Error(ma());return await X.json()},onSuccess:()=>{v.invalidateQueries({queryKey:["shares",a.projectId]}),v.invalidateQueries({queryKey:["share",a.id]}),k.success(zg())}}),re=`${window.location.origin}/share/${a.id}`,se=async(s)=>{if(await co(s))k.success(z_())},De=(s)=>{let X=a.fieldVisibility||{},Se={...X,[s]:!X[s]};M({fieldVisibility:Se})},T="index",G="asc";if(p){let s=p.split(":");T=s[0],G=s[1]||"asc"}return o("div",{className:"flex flex-col h-full bg-background border-l border-border",children:[t("div",{className:"flex-1 overflow-y-auto",children:o("div",{className:"p-4 space-y-6",children:[o("div",{className:"space-y-4",children:[o("div",{className:"flex items-center justify-between",children:[t("h3",{className:"text-sm font-medium",children:$v()}),t(je,{checked:!a.isDisabled,onCheckedChange:(s)=>M({isDisabled:!s})})]}),o("div",{className:"relative w-full",children:[t(H,{value:re,readOnly:!0,className:"pr-10 bg-muted/50 text-xs"}),t(E,{variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full",onClick:()=>se(re),children:t(Rr,{className:"h-4 w-4"})})]})]}),o("div",{className:"space-y-1",children:[t(Oe,{title:oC(),icon:t($l,{className:"h-4 w-4"}),children:o("div",{className:"p-3 space-y-4 pt-2",children:[o("div",{className:"space-y-2",children:[o("div",{className:"flex items-center justify-between",children:[t(Q,{className:"text-xs",children:sp()}),t(je,{checked:V,onCheckedChange:(s)=>{if(_(s),!s)M({password:null})}})]}),V&&o("div",{className:"flex gap-2 animate-in fade-in slide-in-from-top-1 duration-200",children:[t(H,{type:"text",value:q,onChange:(s)=>d(s.target.value),placeholder:ib(),className:"text-xs"}),t(E,{size:"sm",onClick:()=>M({password:q}),children:Fo()})]})]}),o("div",{className:"space-y-2",children:[o("div",{className:"flex items-center justify-between",children:[t(Q,{className:"text-xs",children:mb()}),t(je,{checked:xe,onCheckedChange:(s)=>{if(be(s),!s)c(void 0),M({expireAt:null})}})]}),xe&&t("div",{className:"animate-in fade-in slide-in-from-top-1 duration-200",children:t(ya,{value:w,onChange:(s)=>{c(s),M({expireAt:s?s.toISOString():null})},className:"text-xs"})})]}),o("div",{className:"space-y-2",children:[o("div",{className:"flex items-center justify-between",children:[t(Q,{className:"text-xs",children:M0()}),t(je,{checked:a.allowDownload,onCheckedChange:(s)=>M({allowDownload:s})})]}),t("p",{className:"text-xs text-muted-foreground",children:k0()})]}),o("div",{className:"space-y-2 pt-2 border-t border-border/50",children:[o("div",{className:"flex items-center justify-between",children:[t(Q,{className:"text-xs",children:nA()}),t(je,{checked:ee,disabled:oe==="processing",onCheckedChange:(s)=>{if(!s)ve();else R(!0)}})]}),ee&&oe==="processing"&&o("div",{className:"flex items-center gap-2 text-xs text-amber-600 dark:text-amber-400 font-medium py-1 animate-pulse",children:[t(F,{className:"h-3.5 w-3.5 animate-spin"}),t("span",{children:uI()})]}),ee&&oe!=="processing"&&t(E,{variant:"outline",size:"sm",className:"w-full text-xs gap-1.5 mt-1",onClick:()=>R(!0),children:Ky()})]})]})}),t(Oe,{title:_f(),icon:t(Hl,{className:"h-4 w-4"}),children:o("div",{className:"p-3 space-y-3 pt-2 flex gap-2",children:[o(E,{variant:N==="card"?"secondary":"outline",size:"sm",className:"flex-1 gap-2 text-xs",onClick:()=>x("card"),children:[t(to,{className:"h-4 w-4"}),yv()]}),o(E,{variant:N==="list"?"secondary":"outline",size:"sm",className:"flex-1 gap-2 text-xs",onClick:()=>x("list"),children:[t(Po,{className:"h-4 w-4"}),Vv()]})]})}),t(Oe,{title:Ri(),icon:t(ct,{className:"h-4 w-4"}),children:t("div",{className:"p-3 space-y-3 pt-2",children:te?.map((s)=>o("div",{className:"flex items-center justify-between",children:[t(Q,{className:"text-xs",children:s.config?.name}),t(je,{checked:a.fieldVisibility?.[s.id]??!1,onCheckedChange:()=>De(s.id)})]},s.id))})}),t(Oe,{title:Cl(),icon:t(Ol,{className:"h-4 w-4"}),children:o("div",{className:"p-3 space-y-4 pt-2",children:[o("div",{className:"space-y-2",children:[t(Q,{className:"text-xs text-muted-foreground",children:Pf()}),o(Fe,{value:T,onValueChange:(s)=>{if(s==="index")C(null);else C(`${s}:${G}`)},children:[t(Ze,{className:"w-full text-xs h-9",children:t(Le,{})}),o(Be,{children:[t(ne,{value:"index",children:Cp()}),t(ne,{value:"name",children:Il()}),t(ne,{value:"createdAt",children:Ip()}),t(ne,{value:"size",children:Mp()})]})]})]}),o("div",{className:"space-y-2",children:[t(Q,{className:"text-xs text-muted-foreground",children:op()}),o(E,{variant:"outline",className:"w-full justify-between font-normal text-xs h-9",disabled:T==="index",onClick:()=>{C(`${T}:${G==="asc"?"desc":"asc"}`)},children:[t("span",{children:T==="name"?G==="asc"?zc():Hc():T==="createdAt"?G==="asc"?qc():jc():T==="size"?G==="asc"?kp():Tp():G==="asc"?yf():Tf()}),t(Xc,{className:"h-4 w-4 opacity-50"})]})]})]})})]})]})}),o("div",{className:"p-4 border-t border-border space-y-2",children:[o(E,{variant:"outline",className:"w-full justify-center",onClick:()=>window.open(re,"_blank"),children:[t(Pl,{className:"h-4 w-4 mr-2"}),qx()]}),o(E,{className:"w-full justify-center bg-blue-600 hover:bg-blue-700 text-white",onClick:()=>se(re),children:[t(Rr,{className:"h-4 w-4 mr-2"}),H_()]})]}),t(pt,{open:g,onOpenChange:R,initialConfig:fe,shareId:a.id,onSaveSuccess:()=>{Ie(),v.invalidateQueries({queryKey:["share",a.id]}),v.invalidateQueries({queryKey:["shares",a.projectId]})}})]})}function Oe({title:a,icon:N,children:x}){let[p,C]=u(!1);return o("div",{className:"border-b border-border last:border-0",children:[o("button",{onClick:()=>C(!p),className:"w-full flex items-center justify-between py-3 px-2 hover:bg-muted/50 transition-colors",children:[o("div",{className:"flex items-center gap-3",children:[N,t("span",{className:"text-sm font-medium",children:a})]}),t(bt,{className:Mt("h-4 w-4 transition-transform",p&&"rotate-90")})]}),p&&x&&t("div",{className:"animate-in fade-in slide-in-from-top-1 duration-200",children:x})]})}function Mt(...a){return a.filter(Boolean).join(" ")}function ot({teamId:a,projectId:N,projectName:x,shareId:p,rootFolderId:C}){let v=K(),{fetchMetadata:q}=hr();h(()=>{if(a)q(a)},[a,q]);let{data:d}=L({queryKey:["share",p],queryFn:async()=>{let r=await A.api.shares[":shareId"].$get({param:{shareId:p}});if(!r.ok)throw Error(vb());return await r.json()}}),w=d?.rootFolderId,[c,g]=u(null),[R,V]=u([]);h(()=>{if(w)g(w),V([]),O(new Set)},[w,p]);let _=on((r)=>r.setProjectState),xe=on((r)=>r.clearProjectState),be=(r)=>{if(r===c)return;if(r===w)g(w),V([]);else{let m=R.findIndex((f)=>f.id===r);if(m!==-1)g(r),V(R.slice(m+1))}O(new Set)},[ye,Ie]=u(240),[J,ve]=u(360),{shareConfigLeftSidebarCollapsed:oe,shareConfigRightSidebarCollapsed:fe}=$t(),ee=d?.defaultSortOrder||null,te,ae;if(ee){let r=ee.split(":");te=r[0],ae=r[1]}let M=d?.viewMode??"card",{data:re,fetchNextPage:se,hasNextPage:De,isFetchingNextPage:T,isLoading:G}=ft({queryKey:["folder-children",a,c,"folder",te,ae],queryFn:async({pageParam:r})=>{let m=await A.api.folders[":folderId"].children.$get({param:{folderId:c},query:{assetType:"folder",after:r,sort:te,order:ae}});if(!m.ok)throw Error(bb());return await m.json()},enabled:!!c,initialPageParam:"",getNextPageParam:(r)=>r.pageInfo?.cursor||void 0}),{data:s,fetchNextPage:X,hasNextPage:Se,isFetchingNextPage:Ke,isLoading:Pe}=ft({queryKey:["folder-children",a,c,"file",te,ae],queryFn:async({pageParam:r})=>{let m=await A.api.folders[":folderId"].children.$get({param:{folderId:c},query:{assetType:"file",after:r,sort:te,order:ae}});if(!m.ok)throw Error(yb());return await m.json()},enabled:!!c,initialPageParam:"",getNextPageParam:(r)=>r.pageInfo?.cursor||void 0}),Y=D(()=>re?.pages.flatMap((r)=>r.data??[])??[],[re]),Me=D(()=>s?.pages.flatMap((r)=>r.data??[])??[],[s]);h(()=>{if(d)_({teamId:a,projectId:N,projectName:x,ancestorFolders:R,currentAsset:{name:c===w?d.name:Y.find((r)=>r.id===c)?.name||d.name,type:"folder"},isRootFolder:!1,shareId:p,onFolderClick:be});return()=>xe()},[a,N,x,R,c,w,d,p,Y,_,xe]);let[de,Ce]=u(null),[Te,O]=u(new Set),Ee=()=>{O(new Set),Ce(null)},{dragState:_e,handleDragStart:Qe,handleDragEnd:Ve}=Zl({teamId:a,projectId:N,assetId:c||"",folders:Y,files:Me,selectedIds:Te,onClearSelection:Ee}),He=A.api.shares[":shareId"].assets[":assetId"].$delete,{mutate:Xe}=B({mutationFn:async(r)=>{if(!(await He({param:{shareId:p,assetId:r}})).ok)throw Error(wb())},onSuccess:()=>{v.invalidateQueries({queryKey:["folder-children",a,c]}),k.success(PE())}}),Ye=A.api.shares[":shareId"].$put,{mutate:ze}=B({mutationFn:async(r)=>{let m=await Ye({param:{shareId:p},json:r});if(!m.ok)throw Error(ma());return await m.json()},onSuccess:()=>{v.invalidateQueries({queryKey:["share",p]}),k.success(zg())}}),Je=(r)=>{if(r.type==="folder"||r.targetType==="folder"){let m=c===w?d?.name||"":Y.find((f)=>f.id===c)?.name||gn();V((f)=>[{id:c,name:m},...f]),g(r.id),O(new Set)}};if(!d)return t("div",{children:gd()});return o($n,{modifiers:[ai.configure({anchor:{x:0,y:0}})],sensors:[An.configure({activationConstraints:[new Nr.Distance({value:10})]})],onDragStart:Qe,onDragEnd:Ve,children:[t("div",{className:"flex flex-1 flex-col bg-background min-h-0",children:o("div",{className:"flex flex-1 overflow-hidden relative",children:[!oe&&o(Z,{children:[t("div",{className:"bg-background",style:{width:ye},children:t(yr,{teamId:a,projectId:N,projectName:x,rootFolderId:C,dragState:_e})}),t(Er,{onResize:(r)=>Ie((m)=>Math.max(180,Math.min(400,m+r)))})]}),t(wa,{teamId:a,projectId:N,assetId:c||"",folders:Y,files:Me,selectedItem:de,selectedIds:Te,onItemSelect:(r,m)=>{if(m.metaKey||m.ctrlKey){let f=new Set(Te);if(f.has(r.id)){if(f.delete(r.id),O(f),de?.id===r.id){let i=[...Y,...Me].find((We)=>f.has(We.id));Ce(i||null)}}else f.add(r.id),O(f),Ce(r)}else O(new Set([r.id])),Ce(r)},onItemDoubleClick:Je,onSaveField:()=>{},displayStyle:M,onClearSelection:Ee,fetchNextFoldersPage:se,hasNextFoldersPage:De,isFetchingNextFoldersPage:T,fetchNextFilesPage:X,hasNextFilesPage:Se,isFetchingNextFilesPage:Ke,isLoading:G||Pe,filterConditions:[],onFilterChange:()=>{},dragState:_e,isShareView:!0,onRemoveFromShare:(r)=>{r.forEach((m)=>Xe(m.id))},fieldVisibility:d.fieldVisibility}),!fe&&o(Z,{children:[t(Er,{onResize:(r)=>ve((m)=>Math.max(240,Math.min(600,m-r)))}),t("div",{style:{width:J},className:"flex-shrink-0 h-full",children:t(gt,{shareLink:d,viewMode:M,onViewModeChange:(r)=>ze({viewMode:r}),defaultSortOrder:ee,onSortOrderChange:(r)=>ze({defaultSortOrder:r})})})]})]})}),t(Gc,{children:_e?.isActive?t("div",{className:"flex items-center gap-2 rounded-md bg-popover px-3 py-2 text-sm font-medium shadow-md",children:Kw({count:_e.itemCount})}):null})]})}S();function Tt(){let{projectId:a,shareId:N}=jt.useParams(),{teamId:x,ensureTeamIdForProject:p}=lt();h(()=>{p(a)},[a,p]);let{data:C}=tr(Yp(a)),v=C?.rootFolder,{data:q}=L({queryKey:["folders",v],queryFn:async()=>{let d=await A.api.folders[":folderId"].$get({param:{folderId:v}});if(!d.ok)throw Error("Failed to fetch folder");return await d.json()},enabled:!!v});if(!x||!v||!q)return t(wt,{});return t(ot,{teamId:x,projectId:a,projectName:C.name??"",shareId:N,rootFolderId:v})}var jt=Ue("/projects/$projectId/shares/$shareId")({component:Tt});export{jt as Route};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{Wi}from"./chunk-afnzb9ne.js";export default Wi();
@@ -0,0 +1 @@
1
+ import{O,P,h,D,b,u,Yn,S,Z,t,o,K,Lu,Zu,Ar,Ec,Va,bo,Ht,Qo,Bu,Uu,zu,ju,Cc,qu,L,B,ft,Ue,A,I,vr,F,St,ve,_r,Bt,Re,C,pt,_e,Y,It,xr,Ft,se,ar,E,Ce,Ie,Te,gA,AA,_0,w0,x0,bf,Q0,Qm,Ne,Xa,Xm,ry,Oc,nh,Ls,Wo,hh,gh,Jb,Xb,Mh,Lv,Lw,Zw,px,Xf,ep,Ix,Bx,Xh,Uc,NS,_g,JS,eE,cp,rE,sE,bg,iE,lE,vg,cE,dE,Td,Md,kd,Sl,hp,yE,bE,vE,wE,Rd,Bs,jE,rC,sC,bC,CC,TC,MC,kC,RC,Ug,NC,Fd,h1,y1,N1,Xg,gn,Fp,tI,rI,$c,Je,Xe,et,tt,rt,nt,ot,st,H,Nt,k,Mn,qp,be,mt,ht,gt,kl,Pr,Kd,Et,kt,Rt,Ut,Mt}from"./chunk-jh8q3885.js";import{To,gr}from"./chunk-w1wxzqqb.js";import{jl}from"./chunk-3tg39jx7.js";import{Hs,Bo,Gl,di,Hi,Ra,Vl}from"./chunk-3j5njrpr.js";import{Rn,Nn,Dn,br,xt,_t}from"./chunk-b6q287d1.js";import"./chunk-rsd164d9.js";import"./chunk-tgr86ac4.js";import{Vn,io}from"./chunk-2jrjwaqr.js";S();function te(a,e){let s=new Set(e);return a.filter((i)=>!s.has(i))}var ae=class extends bo{#r;#e;#o;#a;#t;#s;#i;#n;#l;#d=[];constructor(a,e,s){super();this.#r=a,this.#a=s,this.#o=[],this.#t=[],this.#e=[],this.setQueries(e)}onSubscribe(){if(this.listeners.size===1)this.#t.forEach((a)=>{a.subscribe((e)=>{this.#p(a,e)})})}onUnsubscribe(){if(!this.listeners.size)this.destroy()}destroy(){this.listeners=new Set,this.#t.forEach((a)=>{a.destroy()})}setQueries(a,e){this.#o=a,this.#a=e,Ht.batch(()=>{let s=this.#t,i=this.#u(this.#o);i.forEach((c)=>c.observer.setOptions(c.defaultedQueryOptions));let m=i.map((c)=>c.observer),r=m.map((c)=>c.getCurrentResult()),p=s.length!==m.length,f=m.some((c,v)=>c!==s[v]),g=p||f,N=g?!0:r.some((c,v)=>{let y=this.#e[v];return!y||!Va(c,y)});if(!g&&!N)return;if(g)this.#d=i,this.#t=m;if(this.#e=r,!this.hasListeners())return;if(g)te(s,m).forEach((c)=>{c.destroy()}),te(m,s).forEach((c)=>{c.subscribe((v)=>{this.#p(c,v)})});this.#f()})}getCurrentResult(){return this.#e}getQueries(){return this.#t.map((a)=>a.getCurrentQuery())}getObservers(){return this.#t}getOptimisticResult(a,e){let s=this.#u(a),i=s.map((r)=>r.observer.getOptimisticResult(r.defaultedQueryOptions)),m=s.map((r)=>r.defaultedQueryOptions.queryHash);return[i,(r)=>this.#c(r??i,e,m),()=>this.#m(i,s)]}#m(a,e){let s=new Set;return e.map((i,m)=>{let r=a[m];return!i.defaultedQueryOptions.notifyOnChangeProps?i.observer.trackResult(r,(p)=>{if(!s.has(p))s.add(p),e.forEach((f)=>{f.observer.trackProp(p)})}):r})}#c(a,e,s){if(e){let i=this.#l,m=s!==void 0&&i!==void 0&&(i.length!==s.length||s.some((r,p)=>r!==i[p]));if(this.#e!==this.#n||m||e!==this.#i){if(this.#i=e,this.#n=this.#e,s!==void 0)this.#l=s;this.#s=Ec(this.#s,e(a))}return this.#s}return a}#g(){return!this.#a?.combine||this.#t.some((a,e)=>a.options.suspense&&this.#e[e]?.data===void 0)}#u(a){let e=new Map;this.#t.forEach((i)=>{let m=i.options.queryHash;if(!m)return;let r=e.get(m);if(r)r.push(i);else e.set(m,[i])});let s=[];return a.forEach((i)=>{let m=this.#r.defaultQueryOptions(i),r=e.get(m.queryHash)?.shift()??new Qo(this.#r,m);s.push({defaultedQueryOptions:m,observer:r})}),s}#p(a,e){let s=this.#t.indexOf(a);if(s!==-1)this.#e=this.#e.slice(),this.#e[s]=e,this.#f()}#f(){if(this.hasListeners()){let a=this.#g(),e=this.#s,s=a?e:this.#c(this.#m(this.#e,this.#d),this.#a?.combine);if(a||e!==s)Ht.batch(()=>{this.listeners.forEach((i)=>{i(this.#e)})})}}};S();function re({queries:a,...e},s){let i=K(s),m=Lu(),r=Zu(),p=e.subscribed!==!1,f=D(()=>a.map((d)=>{let x=i.defaultQueryOptions(d);return x._optimisticResults=m?"isRestoring":p?"optimistic":void 0,x}),[a,i,m,p]);f.forEach((d)=>{ju(d);let x=i.getQueryCache().get(d.queryHash);Bu(d,r,x)}),Uu(r);let[g]=u(()=>new ae(i,f,e)),[N,c,v]=g.getOptimisticResult(f,e.combine),y=!m&&p;Yn(P((d)=>y?g.subscribe(Ht.batchCalls(d)):Ar,[g,y]),()=>g.getCurrentResult(),()=>g.getCurrentResult()),h(()=>{g.setQueries(f,e)},[f,e,g]);let n=N.some((d,x)=>Cc(f[x],d))?N.flatMap((d,x)=>{let _=f[x];if(_&&Cc(_,d)){let Q=new Qo(i,_);return qu(_,Q,r)}return[]}):[];if(n.length>0)throw Promise.all(n);let w=N.find((d,x)=>{let _=f[x];return _&&zu({result:d,errorResetBoundary:r,throwOnError:_.throwOnError,query:i.getQueryCache().get(_.queryHash),suspense:_.suspense})});if(w)throw w.error;return c(v())}S();S();var xe=Object.defineProperty,M=(a,e)=>xe(a,"name",{value:e,configurable:!0}),W="Collapsible",[ye,Qt]=pt(W),[we,X]=ye(W),ke=O(M(function(e,s){let{__scopeCollapsible:i,open:m,defaultOpen:r,disabled:p,onOpenChange:f,...g}=e,[N,c]=Ft({prop:m,defaultProp:r??!1,onChange:f,caller:W});return t(we,{scope:i,disabled:p,contentId:xr(),open:N,onOpenToggle:P(()=>c((v)=>!v),[c]),children:t(se.div,{"data-state":z(N),"data-disabled":p?"":void 0,...g,ref:s})})},"Collapsible")),Ae="CollapsibleTrigger",qe=O(M(function(e,s){let{__scopeCollapsible:i,...m}=e,r=X(Ae,i);return t(se.button,{type:"button","aria-controls":r.open?r.contentId:void 0,"aria-expanded":r.open||!1,"data-state":z(r.open),"data-disabled":r.disabled?"":void 0,disabled:r.disabled,...m,ref:s,onClick:Y(e.onClick,r.onOpenToggle)})},"CollapsibleTrigger")),oe="CollapsibleContent",De=O(M(function(e,s){let{forceMount:i,...m}=e,r=X(oe,e.__scopeCollapsible);return t(ar,{present:i||r.open,children:({present:p})=>t(Pe,{...m,ref:s,present:p})})},"CollapsibleContent")),Pe=O(M(function(e,s){let{__scopeCollapsible:i,present:m,children:r,...p}=e,f=X(oe,i),[g,N]=u(m),c=b(null),v=_e(s,c),y=b(0),n=y.current,w=b(0),d=w.current,x=f.open||g,_=b(x),Q=b(void 0);return h(()=>{let R=requestAnimationFrame(()=>_.current=!1);return()=>cancelAnimationFrame(R)},[]),It(()=>{let R=c.current;if(R){Q.current=Q.current||{transitionDuration:R.style.transitionDuration,animationName:R.style.animationName},R.style.transitionDuration="0s",R.style.animationName="none";let U=R.getBoundingClientRect();if(y.current=U.height,w.current=U.width,!_.current)R.style.transitionDuration=Q.current.transitionDuration,R.style.animationName=Q.current.animationName;N(m)}},[f.open,m]),t(se.div,{"data-state":z(f.open),"data-disabled":f.disabled?"":void 0,id:f.contentId,hidden:!x,...p,ref:v,style:{["--radix-collapsible-content-height"]:n?`${n}px`:void 0,["--radix-collapsible-content-width"]:d?`${d}px`:void 0,...e.style},children:x&&r})},"CollapsibleContentImpl"));function z(a){return a?"open":"closed"}M(z,"getState");var Se=ke;var He=[["path",{d:"M5 21v-6",key:"1hz6c0"}],["path",{d:"M12 21V3",key:"1lcnhd"}],["path",{d:"M19 21V9",key:"unv183"}]],ie=I("chart-no-axes-column",He);var Oe=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],J=I("funnel",Oe);var Qe=[["path",{d:"M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z",key:"1n2ejm"}],["path",{d:"M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1",key:"1qfcsi"}]],j=I("messages-square",Qe);function ne({teamId:a}){let[e,s]=u("team"),[i,m]=u("1h"),{data:r,isLoading:p}=L({queryKey:["teams",a,"ai-usage",i,"team"],queryFn:async()=>{let d=await A.api.teams[":teamId"]["ai-usage"].$get({param:{teamId:a},query:{timeframe:i}});if(!d.ok)throw Error("Failed to fetch team AI usage");return await d.json()},enabled:!!a&&e==="team"}),{data:f,isLoading:g}=L({queryKey:["teams",a,"members"],queryFn:async()=>{let d=await A.api.teams[":teamId"].members.$get({param:{teamId:a},query:{}});if(!d.ok)throw Error("Failed to fetch team members");return await d.json()},enabled:!!a&&e==="members"}),N=re({queries:(f||[]).map((d)=>({queryKey:["teams",a,"ai-usage",i,d.id],queryFn:async()=>{let x=await A.api.teams[":teamId"]["ai-usage"].$get({param:{teamId:a},query:{timeframe:i,userId:d.id}});if(!x.ok)throw Error(`Failed to fetch AI usage for member ${d.id}`);return await x.json()},enabled:!!a&&e==="members"}))}),c=g||N.some((d)=>d.isLoading),v=(d)=>{if(!d)return"U";let x=d.split(" ");if(x.length>1)return`${x[0][0]}${x[x.length-1][0]}`.toUpperCase();return d.substring(0,2).toUpperCase()},y=(d)=>{if(!d)return"";switch(d.toLowerCase()){case"owner":return Uc();case"editor":return Ls();case"reviewer":return Bs();default:return d}},n=(d)=>(d??0).toLocaleString(),w=(d)=>`$${(d??0).toFixed(6)}`;return o(Et,{className:"border-border/60 shadow-sm",children:[o(kt,{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between pb-6",children:[o("div",{children:[t(Rt,{className:"text-xl font-semibold tracking-tight",children:w0()}),t(Ut,{className:"text-sm text-muted-foreground mt-1",children:x0()})]}),o("div",{className:"flex flex-wrap items-center gap-3",children:[o(To,{type:"single",value:e,onValueChange:(d)=>{if(d)s(d)},className:"border rounded-lg p-1 bg-muted/30",children:[t(gr,{value:"team",className:"px-3 py-1.5 text-xs font-medium",children:y1()}),t(gr,{value:"members",className:"px-3 py-1.5 text-xs font-medium",children:Zw()})]}),o(To,{type:"single",value:i,onValueChange:(d)=>{if(d)m(d)},className:"border rounded-lg p-1 bg-muted/30",children:[t(gr,{value:"1h",className:"px-2.5 py-1.5 text-xs font-medium",children:"1h"}),t(gr,{value:"24h",className:"px-2.5 py-1.5 text-xs font-medium",children:"24h"}),t(gr,{value:"7d",className:"px-2.5 py-1.5 text-xs font-medium",children:"7d"}),t(gr,{value:"30d",className:"px-2.5 py-1.5 text-xs font-medium",children:"30d"})]})]})]}),t(Mt,{children:e==="team"?p?t("div",{className:"flex h-48 items-center justify-center",children:t(F,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):t("div",{className:"rounded-md border",children:o(Rn,{children:[t(Nn,{children:o(br,{children:[t(xt,{children:Fd()}),t(xt,{className:"text-right",children:Mh()}),t(xt,{className:"text-right",children:Xh()}),t(xt,{className:"text-right",children:Qm()}),t(xt,{className:"text-right",children:Xg()}),t(xt,{className:"text-right",children:Xm()})]})}),t(Dn,{children:o(br,{children:[t(_t,{className:"font-medium",children:Fd()}),t(_t,{className:"text-right",children:n(r?.team?.inputTokens)}),t(_t,{className:"text-right",children:n(r?.team?.outputTokens)}),t(_t,{className:"text-right",children:n(r?.team?.cacheReadTokens)}),t(_t,{className:"text-right font-medium",children:n(r?.team?.totalTokens)}),t(_t,{className:"text-right font-medium",children:w(r?.team?.cost)})]})})]})}):c?t("div",{className:"flex h-48 items-center justify-center",children:t(F,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):t("div",{className:"rounded-md border",children:o(Rn,{children:[t(Nn,{children:o(br,{children:[t(xt,{children:Lw()}),t(xt,{children:jE()}),t(xt,{className:"text-right",children:Mh()}),t(xt,{className:"text-right",children:Xh()}),t(xt,{className:"text-right",children:Qm()}),t(xt,{className:"text-right",children:Xg()}),t(xt,{className:"text-right",children:Xm()})]})}),t(Dn,{children:(f||[]).map((d,x)=>{let _=N[x]?.data?.member;return o(br,{children:[t(_t,{children:o("div",{className:"flex items-center gap-3",children:[o(Ce,{className:"h-8 w-8 rounded-full",children:[d.image&&t(Ie,{src:d.image,alt:d.name,className:"object-cover"}),t(Te,{className:"bg-primary/20 text-xs",children:v(d.name)})]}),o("div",{className:"flex flex-col",children:[t("span",{className:"text-sm font-medium leading-none",children:d.name}),t("span",{className:"text-xs text-muted-foreground mt-0.5",children:d.email})]})]})}),t(_t,{className:"text-xs text-muted-foreground",children:y(d.role)}),t(_t,{className:"text-right",children:n(_?.inputTokens)}),t(_t,{className:"text-right",children:n(_?.outputTokens)}),t(_t,{className:"text-right",children:n(_?.cacheReadTokens)}),t(_t,{className:"text-right font-medium",children:n(_?.totalTokens)}),t(_t,{className:"text-right font-medium",children:w(_?.cost)})]},d.id)})})]})})})]})}S();function le({teamId:a}){let[e,s]=u(null),{ref:i,inView:m}=Nt(),{data:r,isLoading:p,isError:f,fetchNextPage:g,hasNextPage:N,isFetchingNextPage:c}=ft({queryKey:["teams",a,"agent-sessions"],queryFn:async({pageParam:n})=>{let w=await A.api.teams[":teamId"]["agent-sessions"].$get({param:{teamId:a},query:{first:"20",after:n?String(n):void 0}});if(!w.ok)throw Error("Failed to fetch agent sessions");return await w.json()},initialPageParam:"",getNextPageParam:(n)=>n.pageInfo.cursor||void 0,enabled:!!a});h(()=>{if(m&&N&&!c)g()},[m,N,c,g]);let v=r?.pages.flatMap((n)=>n.data).filter((n)=>n.id!=="pending")||[],y=(n)=>{switch(n){case"comment":return t(be,{variant:"outline",className:"bg-blue-500/10 text-blue-600 dark:text-blue-400 border-blue-500/20",children:kC()});case"chat":return t(be,{variant:"outline",className:"bg-violet-500/10 text-violet-600 dark:text-violet-400 border-violet-500/20",children:MC()});case"naming":return t(be,{variant:"outline",className:"bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/20",children:RC()});default:return t(be,{variant:"outline",className:"bg-muted text-muted-foreground border-border",children:n})}};return o("div",{className:"space-y-6",children:[o(Et,{className:"border border-border/50 shadow-xs",children:[t(kt,{className:"pb-4",children:t("div",{className:"flex items-center justify-between",children:o("div",{children:[o(Rt,{className:"text-xl font-bold flex items-center gap-2",children:[t(j,{className:"w-5 h-5 text-violet-500"}),Ug()]}),t(Ut,{className:"mt-1 text-sm text-muted-foreground",children:NC()})]})})}),t(Mt,{children:p?t("div",{className:"flex h-64 items-center justify-center",children:t(F,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):f?t("div",{className:"flex h-64 items-center justify-center text-destructive",children:"Failed to load agent sessions."}):v.length===0?o("div",{className:"flex flex-col items-center justify-center py-12 text-center text-muted-foreground",children:[t(j,{className:"w-10 h-10 text-muted-foreground/40 mb-3"}),t("p",{className:"text-base font-medium",children:Ix()})]}):o("div",{className:"rounded-md border border-border/50 overflow-hidden",children:[o(Rn,{children:[t(Nn,{className:"bg-muted/40",children:o(br,{children:[t(xt,{children:CC()}),t(xt,{children:Oc()}),t(xt,{children:TC()}),t(xt,{className:"text-right",children:ry()})]})}),t(Dn,{children:v.map((n)=>o(br,{onClick:()=>s(n.id),className:"cursor-pointer hover:bg-muted/50 transition-colors",children:[t(_t,{className:"font-medium",children:o("div",{className:"flex flex-col",children:[t("span",{className:"text-sm font-semibold text-foreground",children:n.name||Fp()}),t("span",{className:"text-xs font-mono text-muted-foreground/70",children:n.id})]})}),t(_t,{children:o("div",{className:"flex items-center gap-2",children:[o(Ce,{className:"h-6 w-6",children:[t(Ie,{src:n.creator?.image||void 0}),t(Te,{className:"text-[10px]",children:n.creator?.name?.[0]?.toUpperCase()||"?"})]}),t("span",{className:"text-sm text-foreground/90",children:n.creator?.name||"System / Agent"})]})}),t(_t,{children:y(n.type)}),t(_t,{className:"text-right text-xs text-muted-foreground",children:Mn(n.createdAt)})]},n.id))})]}),t("div",{ref:i,className:"py-4 flex justify-center",children:c&&t(F,{className:"h-6 w-6 animate-spin text-muted-foreground"})})]})})]}),t(jl,{sessionId:e,open:!!e,onOpenChange:(n)=>{if(!n)s(null)}})]})}S();function de({...a}){return t(Se,{"data-slot":"collapsible",...a})}function me({...a}){return t(qe,{"data-slot":"collapsible-trigger",...a})}function ce({...a}){return t(De,{"data-slot":"collapsible-content",...a})}function ee(a){switch(a.toLowerCase()){case"owner":return Uc();case"editor":return Ls();case"reviewer":return Bs();default:return a}}function Le(a,e){if(typeof a==="object"&&a!==null&&"message"in a){let s=a.message;if(typeof s==="string")return s}return e}function Be({rule:a}){let e=a.resourceData??{};if(a.resource==="agent_mcp_call_count")return t("span",{children:bE({value:String(e.id??"")})});if(a.resource==="agent_bash_call_count")return t("span",{children:yE({value:String(e.match??"*")})});if(a.resource==="agent_tool_call_count")return t("span",{children:vE({value:String(e.name??e.toolName??"*")})});return null}function Me({rule:a}){if(a.scopeMode==="all_members")return o(be,{variant:"secondary",className:"gap-1 text-xs",children:[t(io,{className:"h-3 w-3"}),o("span",{children:[Td(),a.role?` (${ee(a.role)})`:` (${Sl()})`]})]});if(a.scopeMode==="each_member")return o(be,{variant:"secondary",className:"gap-1 text-xs",children:[t(Vn,{className:"h-3 w-3"}),o("span",{children:[Md(),a.role?` (${ee(a.role)})`:` (${Sl()})`]})]});return o(be,{variant:"secondary",className:"gap-1 text-xs",children:[t(di,{className:"h-3 w-3"}),o("span",{children:[kd()," (",a.userIds?.length||0,")"]})]})}function Fe({teamId:a,rule:e,record:s}){let i=K(),[m,r]=u(!1),[p,f]=u(()=>new Date),g=Hi[e.resource],N=e.scopeMode==="all_members",c=s.percent>=100,v=N?e.role?`${dE()}: ${ee(e.role)}`:wE():s.user?.name||s.userId||gn();h(()=>{if(!s.isWindowActive||!s.periodEnd)return;let n=window.setInterval(()=>f(new Date),60000);return()=>window.clearInterval(n)},[s.isWindowActive,s.periodEnd]);let y=B({mutationFn:async()=>{let n=await A.api.teams[":teamId"].quotas[":id"].records.reset.$post({param:{teamId:a,id:e.id},json:{userId:s.userId??null}});if(!n.ok){let w=await n.json().catch(()=>null);throw Error(Le(w,gh()))}return await n.json()},onSuccess:()=>{i.invalidateQueries({queryKey:["teams",a,"quotas",e.id,"records"]}),i.invalidateQueries({queryKey:["teams",a,"quotas"]}),r(!1),k.success(lE())},onError:(n)=>{let w=n instanceof Error?n.message:gh();r(!1),k.error(w)}});return o(Z,{children:[o("div",{className:"space-y-3 rounded-xl border border-border/70 bg-card p-4 text-card-foreground shadow-2xs",children:[o("div",{className:"flex items-center justify-between gap-3",children:[o("div",{className:"flex min-w-0 items-center gap-3",children:[N?t("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary",children:t(io,{className:"h-5 w-5"})}):o(Ce,{className:"h-9 w-9 shrink-0 border border-border/50",children:[t(Ie,{src:s.user?.image||void 0}),t(Te,{className:"text-xs font-semibold",children:s.user?.name?.[0]?.toUpperCase()||"U"})]}),o("div",{className:"min-w-0",children:[t("div",{className:"truncate text-sm font-semibold text-foreground",children:v}),!N&&s.user?.email&&t("div",{className:"truncate text-xs text-muted-foreground",children:s.user.email})]})]}),o("div",{className:"flex shrink-0 items-center gap-2",children:[s.isWindowActive&&s.periodEnd?o(be,{variant:"outline",className:"hidden gap-1 border-primary/30 bg-primary/5 text-xs text-primary sm:flex",children:[t(_r,{className:"h-3 w-3"}),t("span",{children:bg({time:qp(s.periodEnd,p)})})]}):o(be,{variant:"secondary",className:"hidden gap-1 text-xs text-muted-foreground sm:flex",children:[t(vr,{className:"h-3 w-3 text-primary"}),t("span",{children:_g()})]}),o(E,{type:"button",variant:"outline",size:"sm",className:"gap-1.5",onClick:()=>r(!0),disabled:y.isPending,children:[y.isPending?t(F,{className:"h-3.5 w-3.5 animate-spin"}):t(Hs,{className:"h-3.5 w-3.5"}),vg()]})]})]}),o("div",{className:"space-y-1.5 pt-1",children:[t(Kd,{value:Math.min(100,Math.max(0,s.percent)),className:"h-2"}),o("div",{className:"flex items-center justify-between gap-2 text-xs font-medium",children:[o("span",{className:c?"font-bold text-destructive":"text-foreground",children:[Ra(e.resource,s.consumed)," /"," ",Ra(e.resource,e.limit)," ",g?.unit]}),o("span",{className:c?"font-bold text-destructive":"text-muted-foreground",children:[s.percent,"%"]})]})]}),o("div",{className:"flex items-center justify-between gap-2 text-xs text-muted-foreground sm:hidden",children:[s.isWindowActive&&s.periodEnd?o("span",{className:"flex items-center gap-1 text-primary",children:[t(_r,{className:"h-3 w-3"}),bg({time:qp(s.periodEnd,p)})]}):o("span",{className:"flex items-center gap-1",children:[t(vr,{className:"h-3 w-3 text-primary"}),_g()]}),o("span",{children:[iE(),": ",Ra(e.resource,s.remaining)," ",g?.unit]})]})]}),t(Je,{open:m,onOpenChange:r,children:o(Xe,{children:[o(et,{children:[t(rt,{children:vg()}),t(nt,{children:cE({target:v})})]}),o(tt,{children:[t(st,{disabled:y.isPending,children:Ne()}),o(ot,{onClick:(n)=>{n.preventDefault(),y.mutate()},disabled:y.isPending,children:[y.isPending&&t(F,{className:"mr-2 h-4 w-4 animate-spin"}),Xa()]})]})]})})]})}function je({teamId:a,rule:e}){let[s,i]=u(!1),[m,r]=u(""),p=Hi[e.resource],f=p?.icon||Bo,{data:g,isLoading:N,isError:c}=L({queryKey:["teams",a,"quotas",e.id,"records"],queryFn:async()=>{let n=await A.api.teams[":teamId"].quotas[":id"].records.$get({param:{teamId:a,id:e.id}});if(!n.ok)throw Error(hh());return await n.json()},enabled:s,refetchInterval:s?1e4:!1}),v=g?.records??[],y=v.filter((n)=>{if(!m.trim())return!0;let w=m.toLowerCase();return n.user?.name.toLowerCase().includes(w)||n.user?.email.toLowerCase().includes(w)});return o(de,{open:s,onOpenChange:i,className:"rounded-xl border border-border/70",children:[t(me,{asChild:!0,children:o("button",{type:"button","aria-label":s?JS():rE(),className:"flex w-full items-center justify-between gap-4 p-4 text-left transition-colors hover:bg-muted/40",children:[o("div",{className:"flex min-w-0 items-start gap-3",children:[t("div",{className:"mt-0.5 rounded-lg bg-primary/10 p-2 text-primary",children:t(f,{className:"h-5 w-5"})}),o("div",{className:"min-w-0",children:[o("div",{className:"flex flex-wrap items-center gap-2",children:[t("span",{className:"font-semibold text-foreground",children:p?.label()||e.resource}),!e.enabled&&t(be,{variant:"secondary",children:cp()})]}),o("div",{className:"mt-1 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground",children:[t(Me,{rule:e}),o(be,{variant:"outline",className:"gap-1 text-xs",children:[t(_r,{className:"h-3 w-3"}),Ra(e.resource,e.limit)," ",p?.unit," /"," ",Vl(e.period)]}),t(Be,{rule:e})]})]})]}),t(ve,{className:`h-5 w-5 shrink-0 text-muted-foreground transition-transform ${s?"rotate-180":""}`})]})}),t(ce,{children:o("div",{className:"space-y-3 border-t border-border/60 bg-muted/10 p-4",children:[e.scopeMode!=="all_members"&&v.length>3&&o("div",{className:"relative",children:[t(Bt,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t(H,{value:m,onChange:(n)=>r(n.target.value),placeholder:hp(),className:"h-9 pl-9 text-sm"})]}),N?t("div",{className:"flex justify-center py-10",children:t(F,{className:"h-7 w-7 animate-spin text-primary"})}):c?t("div",{className:"py-8 text-center text-sm text-destructive",children:hh()}):y.length===0?t("div",{className:"py-8 text-center text-sm text-muted-foreground",children:sE()}):y.map((n,w)=>t(Fe,{teamId:a,rule:e,record:n},n.id||n.userId||`record-${w}`))]})})]})}function ue({teamId:a}){let{data:e,isLoading:s,isError:i}=L({queryKey:["teams",a,"quotas"],queryFn:async()=>{let r=await A.api.teams[":teamId"].quotas.$get({param:{teamId:a}});if(!r.ok)throw Error(Wo());return await r.json()},enabled:!!a}),m=e?.rules??[];return o(Et,{className:"border-border/60 shadow-sm",children:[o(kt,{children:[o(Rt,{className:"flex items-center gap-2 text-xl font-semibold tracking-tight",children:[t(Bo,{className:"h-5 w-5 text-primary"}),Rd()]}),t(Ut,{children:eE()})]}),t(Mt,{children:s?t("div",{className:"flex h-48 items-center justify-center",children:t(F,{className:"h-7 w-7 animate-spin text-muted-foreground"})}):i?t("div",{className:"py-10 text-center text-sm text-destructive",children:Wo()}):m.length===0?o("div",{className:"flex flex-col items-center justify-center rounded-xl border-2 border-dashed border-border py-12 text-center",children:[t(Bo,{className:"mb-3 h-10 w-10 text-muted-foreground/50"}),t("p",{className:"text-base font-medium text-foreground",children:ep()}),t("p",{className:"mt-1 max-w-md text-sm text-muted-foreground",children:Xf()})]}):t("div",{className:"space-y-3",children:m.map((r)=>t(je,{teamId:a,rule:r},r.id))})})]})}S();var $e=Object.values(kl);function pe({teamId:a}){let[e,s]=u([]),[i,m]=u([]),[r,p]=u(""),{ref:f,inView:g}=Nt(),{data:N}=L({queryKey:["teams",a,"members"],queryFn:async()=>{let l=await A.api.teams[":teamId"].members.$get({param:{teamId:a},query:{}});if(!l.ok)return[];return await l.json()},enabled:!!a}),c=N||[],{data:v,isLoading:y,isError:n,fetchNextPage:w,hasNextPage:d,isFetchingNextPage:x}=ft({queryKey:["teams",a,"audit-logs",e,i,r],queryFn:async({pageParam:l})=>{let T=await A.api.teams[":teamId"]["audit-logs"].$get({param:{teamId:a},query:{first:"20",after:l?String(l):void 0,actions:e.length>0?e:void 0,userIds:i.length>0?i:void 0,itemId:r.trim()||void 0}});if(!T.ok)throw Error("Failed to fetch audit logs");return await T.json()},initialPageParam:"",getNextPageParam:(l)=>l.pageInfo.endCursor||void 0,enabled:!!a});h(()=>{if(g&&d&&!x)w()},[g,d,x,w]);let _=v?.pages.flatMap((l)=>l.nodes)||[],Q=v?.pages[0]?.total??0,R=(l)=>{s((T)=>T.includes(l)?T.filter((q)=>q!==l):[...T,l])},U=(l)=>{m((T)=>T.includes(l)?T.filter((q)=>q!==l):[...T,l])},fe=(l)=>{if(l.includes("delete")||l.includes("remove")||l.includes("revoke"))return t(be,{variant:"outline",className:"bg-destructive/10 text-destructive border-destructive/20 font-mono text-xs",children:l});if(l.includes("create")||l.includes("add"))return t(be,{variant:"outline",className:"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/20 font-mono text-xs",children:l});if(l.includes("update")||l.includes("reparent")||l.includes("copy"))return t(be,{variant:"outline",className:"bg-blue-500/10 text-blue-600 dark:text-blue-400 border-blue-500/20 font-mono text-xs",children:l});return t(be,{variant:"outline",className:"bg-muted text-muted-foreground border-border font-mono text-xs",children:l})},ge=new Map(c.map((l)=>[l.userId||l.id,l]));return t("div",{className:"space-y-6",children:o(Et,{className:"border border-border/50 shadow-xs",children:[o(kt,{className:"pb-4",children:[o("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[o("div",{children:[o(Rt,{className:"text-xl font-bold flex items-center gap-2",children:[t(Hs,{className:"h-5 w-5 text-primary"}),bf()]}),t(Ut,{className:"mt-1",children:Q0()})]}),Q>0&&o(be,{variant:"secondary",className:"w-fit text-xs font-normal",children:[Q," ",bf()]})]}),o("div",{className:"mt-4 flex flex-wrap items-center gap-3 pt-4 border-t border-border/40",children:[o(mt,{children:[t(ht,{asChild:!0,children:o(E,{variant:"outline",size:"sm",className:"h-9 gap-2 text-xs border-dashed",children:[t(J,{className:"h-3.5 w-3.5"}),Jb(),e.length>0&&t(be,{variant:"secondary",className:"ml-1 px-1.5 py-0 text-[10px]",children:e.length})]})}),o(gt,{className:"w-64 p-2",align:"start",children:[t("div",{className:"text-xs font-semibold text-muted-foreground px-2 py-1 mb-1",children:sC()}),t("div",{className:"max-h-60 overflow-y-auto space-y-1 pr-1",children:$e.map((l)=>o("label",{className:"flex items-center gap-2 px-2 py-1.5 hover:bg-accent rounded-md cursor-pointer text-xs",children:[t(Pr,{checked:e.includes(l),onCheckedChange:()=>R(l)}),t("span",{className:"font-mono",children:l})]},l))}),e.length>0&&t(E,{variant:"ghost",size:"sm",className:"w-full mt-2 h-7 text-xs text-muted-foreground hover:text-foreground",onClick:()=>s([]),children:"Clear Actions"})]})]}),o(mt,{children:[t(ht,{asChild:!0,children:o(E,{variant:"outline",size:"sm",className:"h-9 gap-2 text-xs border-dashed",children:[t(J,{className:"h-3.5 w-3.5"}),Xb(),i.length>0&&t(be,{variant:"secondary",className:"ml-1 px-1.5 py-0 text-[10px]",children:i.length})]})}),o(gt,{className:"w-64 p-2",align:"start",children:[t("div",{className:"text-xs font-semibold text-muted-foreground px-2 py-1 mb-1",children:bC()}),t("div",{className:"max-h-60 overflow-y-auto space-y-1 pr-1",children:c.map((l)=>{let T=l.userId||l.user?.id||l.id,q=l.user?.name||l.name||T,V=l.user?.image||l.image;return o("label",{className:"flex items-center gap-2 px-2 py-1.5 hover:bg-accent rounded-md cursor-pointer text-xs",children:[t(Pr,{checked:i.includes(T),onCheckedChange:()=>U(T)}),o(Ce,{className:"h-5 w-5",children:[t(Ie,{src:V||void 0}),t(Te,{className:"text-[10px]",children:q.slice(0,2).toUpperCase()})]}),t("span",{className:"truncate",children:q})]},T)})}),i.length>0&&t(E,{variant:"ghost",size:"sm",className:"w-full mt-2 h-7 text-xs text-muted-foreground hover:text-foreground",onClick:()=>m([]),children:"Clear Users"})]})]}),o("div",{className:"relative flex-1 min-w-[200px] max-w-xs",children:[t(Bt,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),t(H,{type:"text",placeholder:rC(),value:r,onChange:(l)=>p(l.target.value),className:"pl-8 pr-8 h-9 text-xs"}),r&&t("button",{onClick:()=>p(""),className:"absolute right-2.5 top-2.5 text-muted-foreground hover:text-foreground",children:t(Re,{className:"h-4 w-4"})})]}),(e.length>0||i.length>0||r)&&t(E,{variant:"ghost",size:"sm",className:"h-9 px-2 text-xs text-muted-foreground hover:text-foreground",onClick:()=>{s([]),m([]),p("")},children:"Clear all"})]})]}),o(Mt,{className:"p-0",children:[y?t("div",{className:"flex h-64 items-center justify-center",children:t(F,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):n?t("div",{className:"p-8 text-center text-sm text-destructive",children:"Failed to load audit logs."}):_.length===0?t("div",{className:"p-12 text-center text-sm text-muted-foreground",children:px()}):o(Rn,{children:[t(Nn,{children:o(br,{className:"hover:bg-transparent border-b border-border/50",children:[t(xt,{className:"w-[180px] text-xs font-semibold",children:AA()}),t(xt,{className:"w-[200px] text-xs font-semibold",children:rI()}),t(xt,{className:"text-xs font-semibold",children:Lv()}),t(xt,{className:"text-xs font-semibold",children:NS()}),t(xt,{className:"w-[160px] text-right text-xs font-semibold",children:N1()})]})}),t(Dn,{children:_.map((l)=>{let T=l.userId?ge.get(l.userId):null,q=T?.user?.name||T?.name||l.userId||"System",V=T?.user?.image||T?.image;return o(br,{className:"hover:bg-muted/40 transition-colors",children:[t(_t,{className:"py-3 font-medium",children:fe(l.action)}),t(_t,{className:"py-3",children:o("div",{className:"flex items-center gap-2",children:[o(Ce,{className:"h-6 w-6",children:[t(Ie,{src:V||void 0}),t(Te,{className:"text-[10px]",children:q.slice(0,2).toUpperCase()})]}),t("span",{className:"text-xs font-medium text-foreground truncate max-w-[160px]",children:l.agent?$c({user:q,agent:l.agent.name}):q}),l.agent&&t(St,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"})]})}),t(_t,{className:"py-3 text-xs font-mono text-muted-foreground",children:l.itemId||"-"}),t(_t,{className:"py-3 text-xs font-mono text-muted-foreground",children:l.projectId||"-"}),t(_t,{className:"py-3 text-right text-xs text-muted-foreground",children:Mn(l.createdAt)})]},l.id)})})]}),t("div",{ref:f,className:"py-4 flex justify-center",children:x&&t(F,{className:"h-6 w-6 animate-spin text-muted-foreground"})})]})]})})}function ze(){let{teamId:a}=Ge.useParams(),[e,s]=u("audit-logs"),{data:i,isLoading:m}=L({queryKey:["teams",a,"me"],queryFn:async()=>{let r=await A.api.teams[":teamId"].me.$get({param:{teamId:a}});if(!r.ok)throw Error("Failed to fetch me");return await r.json()},enabled:!!a});if(m)return t("div",{className:"flex h-screen items-center justify-center",children:t(F,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(i?.role?.toLowerCase()!=="owner")return o("div",{className:"flex h-full flex-col items-center justify-center p-8 text-center",children:[t(Gl,{className:"h-12 w-12 text-destructive mb-4"}),t("h2",{className:"text-xl font-bold tracking-tight mb-2",children:gA()}),t("p",{className:"text-sm text-muted-foreground max-w-md",children:Bx()})]});return t("div",{className:"h-full bg-background font-sans selection:bg-primary/20 transition-colors duration-300",children:o("div",{className:"flex flex-col md:flex-row h-full",children:[t("div",{className:"w-full h-full md:w-72 bg-sidebar border-b md:border-b-0 md:border-r border-sidebar-border z-10 md:left-16 overflow-y-auto transition-colors duration-300",children:o("nav",{className:"p-4 space-y-1 mt-4",children:[t("div",{className:"mb-2 px-4 text-xs font-semibold text-sidebar-foreground/60 uppercase tracking-wider",children:nh()}),t("div",{className:"mt-4 mb-2 px-4 text-xs font-semibold text-sidebar-foreground/60 uppercase tracking-wider pt-4 border-t border-sidebar-border",children:h1()}),o("button",{onClick:()=>s("audit-logs"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",e==="audit-logs"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(Hs,{className:"w-5 h-5"}),bf(),e==="audit-logs"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]}),o("button",{onClick:()=>s("quotas"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",e==="quotas"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(Bo,{className:"w-5 h-5"}),Rd(),e==="quotas"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]}),t("div",{className:"mt-4 mb-2 px-4 text-xs font-semibold text-sidebar-foreground/60 uppercase tracking-wider pt-4 border-t border-sidebar-border",children:_0()}),o("button",{onClick:()=>s("ai-usage"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",e==="ai-usage"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(ie,{className:"w-5 h-5"}),tI(),e==="ai-usage"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]}),o("button",{onClick:()=>s("ai-sessions"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",e==="ai-sessions"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(j,{className:"w-5 h-5"}),Ug(),e==="ai-sessions"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]})]})}),t("div",{className:"flex-1 overflow-y-auto p-4 md:p-8",children:o("div",{className:"max-w-6xl mx-auto space-y-8",children:[e==="audit-logs"&&t(pe,{teamId:a}),e==="ai-usage"&&t(ne,{teamId:a}),e==="ai-sessions"&&t(le,{teamId:a}),e==="quotas"&&t(ue,{teamId:a})]})})]})})}var Ge=Ue("/teams/$teamId/dashboard")({component:ze});export{Ge as Route};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import"./chunk-dbw8c1jj.js";import{af,vI}from"./chunk-t7bvde99.js";export{af as createKyselyAdapter,vI as kyselyAdapter};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{Oe}from"./chunk-fnmwksnb.js";var ye=new TextEncoder,q=new TextDecoder,re=new TextDecoder("utf-8",{fatal:!0});function A(...e){let t=e.reduce((o,{length:a})=>o+a,0),r=new Uint8Array(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}function tt(e,t,r){if(t<0||t>=4294967296)throw RangeError(`value must be >= 0 and <= 4294967295. Received ${t}`);e.set([t>>>24,t>>>16,t>>>8,t&255],r)}function rt(e){let t=Math.floor(e/4294967296),r=e%4294967296,n=new Uint8Array(8);return tt(n,t,0),tt(n,r,4),n}function Te(e){let t=new Uint8Array(4);return tt(t,e),t}function b(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++){let n=e.charCodeAt(r);if(n>127)throw TypeError("non-ASCII string encountered in encode()");t[r]=n}return t}var Pe=(e,t="algorithm.name")=>TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);function nt(e,t){if(t&&!e.usages.includes(t))throw TypeError(`CryptoKey does not support this operation, its usages must include ${t}.`)}function Ie(e,t){let{modulusLength:r}=t.algorithm;if(typeof r!=="number"||r<2048)throw TypeError(`${e} requires key modulusLength to be 2048 bits or larger`)}function k(e,t,r){let n=e.algorithm;if(n.name!==t.name)throw Pe(t.name);if(t.hash&&n.hash?.name!==t.hash)throw Pe(t.hash,"algorithm.hash");if(t.namedCurve&&n.namedCurve!==t.namedCurve)throw Pe(t.namedCurve,"algorithm.namedCurve");if(t.length!==void 0&&n.length!==t.length)throw Pe(t.length,"algorithm.length");nt(e,r)}function Ot(e,t,...r){if(r.length>2){let n=r.pop();e+=`one of type ${r.join(", ")}, or ${n}.`}else if(r.length===2)e+=`one of type ${r[0]} or ${r[1]}.`;else e+=`of type ${r[0]}.`;if(t==null)e+=` Received ${t}`;else if(typeof t==="function"&&t.name)e+=` Received function ${t.name}`;else if(typeof t==="object"&&t!=null){if(t.constructor?.name)e+=` Received an instance of ${t.constructor.name}`}return e}var B=(e,...t)=>Ot("Key must be ",e,...t),he=(e,t,...r)=>Ot(`Key for the ${e} algorithm must be `,t,...r);class x extends Error{static code="ERR_JOSE_GENERIC";code="ERR_JOSE_GENERIC";constructor(e,t){super(e,t);this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}}class _ extends x{static code="ERR_JWT_CLAIM_VALIDATION_FAILED";code="ERR_JWT_CLAIM_VALIDATION_FAILED";claim;reason;payload;constructor(e,t,r="unspecified",n="unspecified"){super(e,{cause:{claim:r,reason:n,payload:t}});this.claim=r,this.reason=n,this.payload=t}}class $i extends x{static code="ERR_JWT_EXPIRED";code="ERR_JWT_EXPIRED";claim;reason;payload;constructor(e,t,r="unspecified",n="unspecified"){super(e,{cause:{claim:r,reason:n,payload:t}});this.claim=r,this.reason=n,this.payload=t}}class ne extends x{static code="ERR_JOSE_ALG_NOT_ALLOWED";code="ERR_JOSE_ALG_NOT_ALLOWED"}class m extends x{static code="ERR_JOSE_NOT_SUPPORTED";code="ERR_JOSE_NOT_SUPPORTED"}class _e extends x{static code="ERR_JWE_DECRYPTION_FAILED";code="ERR_JWE_DECRYPTION_FAILED";constructor(e="decryption operation failed",t){super(e,t)}}class f extends x{static code="ERR_JWE_INVALID";code="ERR_JWE_INVALID"}class w extends x{static code="ERR_JWS_INVALID";code="ERR_JWS_INVALID"}class E extends x{static code="ERR_JWT_INVALID";code="ERR_JWT_INVALID"}class De extends x{static code="ERR_JWK_INVALID";code="ERR_JWK_INVALID"}class Ue extends x{static code="ERR_JWKS_INVALID";code="ERR_JWKS_INVALID"}class we extends x{static code="ERR_JWKS_NO_MATCHING_KEY";code="ERR_JWKS_NO_MATCHING_KEY";constructor(e="no applicable key found in the JSON Web Key Set",t){super(e,t)}}class ot extends x{[Symbol.asyncIterator]=async function*(){};static code="ERR_JWKS_MULTIPLE_MATCHING_KEYS";code="ERR_JWKS_MULTIPLE_MATCHING_KEYS";constructor(e="multiple matching keys found in the JSON Web Key Set",t){super(e,t)}}class it extends x{static code="ERR_JWKS_TIMEOUT";code="ERR_JWKS_TIMEOUT";constructor(e="request timed out",t){super(e,t)}}class at extends x{static code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";constructor(e="signature verification failed",t){super(e,t)}}function Re(e){if(!M(e))throw Error("CryptoKey instance expected")}var M=(e)=>{if(e?.[Symbol.toStringTag]==="CryptoKey")return!0;try{return e instanceof CryptoKey}catch{return!1}},st=(e)=>e?.[Symbol.toStringTag]==="KeyObject",Ne=(e)=>M(e)||st(e);var L=(e)=>crypto.getRandomValues(new Uint8Array(e.cekBits>>3));function _t(e,t){let r=e.byteLength<<3;if(r!==t)throw new f(`Invalid Content Encryption Key length. Expected ${t} bits, got ${r} bits`)}var Wr=(e)=>crypto.getRandomValues(new Uint8Array(e.ivBits>>3));function Dt(e,t){if(t.length<<3!==e.ivBits)throw new f("Invalid Initialization Vector length")}async function Ut(e,t,r){if(!(t instanceof Uint8Array))throw TypeError(B(t,"Uint8Array"));let n=e.cekBits>>1,o=await crypto.subtle.importKey("raw",t.subarray(n>>3),"AES-CBC",!1,[r]),a=await crypto.subtle.importKey("raw",t.subarray(0,n>>3),{hash:`SHA-${n<<1}`,name:"HMAC"},!1,["sign"]);return[o,a,n]}async function Rt(e,t,r){return new Uint8Array((await crypto.subtle.sign("HMAC",e,t)).slice(0,r>>3))}async function Cr(e,t,r,n,o){let[a,i,s]=await Ut(e,r,"encrypt"),c=new Uint8Array(await crypto.subtle.encrypt({iv:n,name:"AES-CBC"},a,t)),p=A(o,n,c,rt(o.length*8)),d=await Rt(i,p,s);return{ciphertext:c,tag:d,iv:n}}async function vr(e,t){let r={name:"HMAC",hash:"SHA-256"},n=await crypto.subtle.generateKey(r,!1,["sign","verify"]),o=await crypto.subtle.sign(r,n,e);return crypto.subtle.verify(r,n,o,t)}async function Tr(e,t,r,n,o,a){let[i,s,c]=await Ut(e,t,"decrypt"),p=A(a,n,r,rt(a.length*8)),d=await Rt(s,p,c);try{if(await vr(o,d))return new Uint8Array(await crypto.subtle.decrypt({iv:n,name:"AES-CBC"},i,r))}catch{}throw new _e}async function Pr(e,t,r,n,o){let a=r instanceof Uint8Array?await crypto.subtle.importKey("raw",r,"AES-GCM",!1,["encrypt"]):(k(r,e.subtle,"encrypt"),r),i=new Uint8Array(await crypto.subtle.encrypt({additionalData:o,iv:n,name:"AES-GCM",tagLength:128},a,t)),s=i.slice(-16);return{ciphertext:i.slice(0,-16),tag:s,iv:n}}async function Ir(e,t,r,n,o,a){let i=t instanceof Uint8Array?await crypto.subtle.importKey("raw",t,"AES-GCM",!1,["decrypt"]):(k(t,e.subtle,"decrypt"),t);try{return new Uint8Array(await crypto.subtle.decrypt({additionalData:a,iv:n,name:"AES-GCM",tagLength:128},i,A(r,o)))}catch{throw new _e}}async function He(e,t,r,n,o){if(!M(r)&&!(r instanceof Uint8Array))throw TypeError(B(r,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(n)Dt(e,n);else n=Wr(e);if(r instanceof Uint8Array)_t(r,e.cekBits);return e.cbc?Cr(e,t,r,n,o):Pr(e,t,r,n,o)}async function ke(e,t,r,n,o,a){if(!M(t)&&!(t instanceof Uint8Array))throw TypeError(B(t,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(!n)throw new f("JWE Initialization Vector missing");if(!o)throw new f("JWE Authentication Tag missing");if(!e.cbc&&o.length!==16)throw new f("Invalid Authentication Tag length");if(Dt(e,n),t instanceof Uint8Array)_t(t,e.cekBits);return e.cbc?Tr(e,t,r,n,o,a):Ir(e,t,r,n,o,a)}var Jd={};Oe(Jd,{decode:()=>D,encode:()=>ir});function ct(e){if(Uint8Array.prototype.toBase64)return e.toBase64();let t=32768,r=[];for(let n=0;n<e.length;n+=t)r.push(String.fromCharCode.apply(null,e.subarray(n,n+t)));return btoa(r.join(""))}function Be(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(e);let t=atob(e),r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return r}var pt="The input to be decoded is not correctly encoded.";function D(e){if(Uint8Array.fromBase64)try{return Uint8Array.fromBase64(typeof e==="string"?e:q.decode(e),{alphabet:"base64url"})}catch(r){throw TypeError(pt,{cause:r})}let t=e;if(t instanceof Uint8Array)t=q.decode(t);if(t.includes("+")||t.includes("/"))throw TypeError(pt);t=t.replace(/-/g,"+").replace(/_/g,"/");try{return Be(t)}catch{throw TypeError(pt)}}function ir(e){let t=e;if(typeof t==="string")t=ye.encode(t);if(Uint8Array.prototype.toBase64)return t.toBase64({alphabet:"base64url",omitPadding:!0});return ct(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function Z(e,t){if(!(e instanceof Uint8Array))throw TypeError(`${t} must be an instance of Uint8Array`)}function S(e){if(typeof e!=="object"||e===null||Object.prototype.toString.call(e)!=="[object Object]")return!1;let t=Object.getPrototypeOf(e);return t===null||Object.getPrototypeOf(t)===null}function Me(e){return S(e)&&Array.isArray(e.keys)&&Array.from(e.keys).every(S)}function Nt(...e){let t=new Set;for(let r of e){if(!r)continue;for(let n of Object.keys(r)){if(t.has(n))return!1;t.add(n)}}return!0}var Ht=Symbol();function Q(e,t){if(e!==void 0)throw TypeError(`${t} can only be called once`)}function W(e,t,r){try{return D(e)}catch{throw new r(`Failed to base64url decode the ${t}`)}}function dt(e,t,r){try{return b(e)}catch{throw new r(`The ${t} is not a valid base64url string`)}}async function $e(e,t){let r=`SHA-${e.slice(-3)}`;return new Uint8Array(await crypto.subtle.digest(r,t))}function F(e,t,r){let n;try{n=JSON.parse(re.decode(D(e)))}catch{throw new t(r)}if(!S(n))throw new t(r);return n}async function j(e,t){if(t.kty==="RSA"&&"oth"in t&&t.oth!==void 0)throw new m('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');if(!e.kty.includes(t.kty))throw new m('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');let r=e.resolve?.({kty:t.kty,crv:t.crv})??e.subtle,n=!!(t.d||t.priv),o={...t};if(o.kty!=="AKP")delete o.alg;return delete o.use,crypto.subtle.importKey("jwk",o,r,t.ext??!n,t.key_ops??e.usages[n?1:0])}function oe(e){return{__proto__:null,...e}}function Le(e){let t=oe(e);if(t.ext!==void 0&&typeof t.ext!=="boolean")throw TypeError('"ext" (Extractable) Parameter must be a boolean');if(t.key_ops!==void 0){let r=t.key_ops,n=Array.isArray(r)?[...r]:void 0;if(!n||n.some((o)=>typeof o!=="string")||new Set(n).size!==n.length)throw TypeError('"key_ops" (Key Operations) Parameter must be an array of unique strings');t.key_ops=n}return t}var ft=(e)=>e[Symbol.toStringTag],Or=(e,t,r)=>{let{alg:n}=e;if(t.use!==void 0){let o=r==="sign"||r==="verify"?"sig":"enc";if(t.use!==o)throw TypeError(`Invalid key for this operation, its "use" must be "${o}" when present`)}if(t.alg!==void 0&&t.alg!==n)throw TypeError(`Invalid key for this operation, its "alg" must be "${n}" when present`);if(Array.isArray(t.key_ops)){let o=r==="encrypt"||r==="decrypt"?e.ops?.[r==="encrypt"?0:1]:r;if(o&&!t.key_ops.includes(o))throw TypeError(`Invalid key for this operation, its "key_ops" must include "${o}" when present`)}};function _r(e,t,r){let{alg:n,secret:o}=e,a=r==="decrypt"||r==="sign";if(o&&t instanceof Uint8Array)return[Bt,t];if(S(t)){let i=Le(t);if(typeof i.kty!=="string")throw TypeError(o?he(n,t,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"):he(n,t,"CryptoKey","KeyObject","JSON Web Key"));if(!(o?i.kty==="oct"&&typeof i.k==="string":i.kty!=="oct"&&(a?i.kty==="AKP"&&typeof i.priv==="string"||typeof i.d==="string":i.d===void 0&&i.priv===void 0)))throw TypeError(o?'JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present':`JSON Web Key for this operation must be a ${a?"private":"public"} JWK`);return Or(e,i,r),[Lt,t,i]}if(!Ne(t))throw TypeError(o?he(n,t,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"):he(n,t,"CryptoKey","KeyObject","JSON Web Key"));if(o){if(t.type!=="secret")throw TypeError(`${ft(t)} instances for symmetric algorithms must be of type "secret"`)}else{if(t.type==="secret")throw TypeError(`${ft(t)} instances for asymmetric algorithms must not be of type "secret"`);let i=a?"private":"public";if((t.type==="public"||t.type==="private")&&t.type!==i){let s=r==="sign"?"signing":r==="verify"?"verifying":`${r.slice(0,-1)}tion`;throw TypeError(`${ft(t)} instances for asymmetric algorithm ${s} must be of type "${i}"`)}}return M(t)?[Mt,t]:[$t,t]}var Bt=0,Mt=1,$t=2,Lt=3,ut,Dr={__proto__:null,prime256v1:"P-256",secp384r1:"P-384",secp521r1:"P-521"};function je(e,t,r){ut||=new WeakMap;let n=ut.get(e);if(r)if(n)n[t]=r;else ut.set(e,{[t]:r});return r??n?.[t]}var kt=async(e,t,r)=>je(e,r.alg)??je(e,r.alg,await j(r,{...t,alg:r.alg})),Ur=(e,t)=>{let r=je(e,t.alg);if(r)return r;let n=e.type==="public",o=t.usages[n?0:1],{asymmetricKeyType:a}=e,i=Dr[e.asymmetricKeyDetails?.namedCurve],s=t.resolve?.({crv:i,asymmetricKeyType:a})??t.subtle;return je(e,t.alg,e.toCryptoKey(s,n,o))};async function U(e,t,r){let n=_r(e,t,r);switch(n[0]){case Bt:case Mt:return n[1];case Lt:{let o=n[1],a=n[2];if(a.kty==="oct")return D(a.k);if(!Object.isFrozen(o)){let{key_ops:i}=o;if(Array.isArray(i))Object.freeze(i);Object.freeze(o)}return kt(o,a,e)}case $t:{let o=n[1];if(o.type==="secret")return o.export();if("toCryptoKey"in o&&typeof o.toCryptoKey==="function")return Ur(o,e);return kt(o,o.export({format:"jwk"}),e)}}}function ge(e){let t={__proto__:null};for(let r in e)t[r]={...e[r],alg:r};return t}var Rr=[["encrypt","wrapKey"],["decrypt","unwrapKey"]],Nr=[[],["deriveBits"]],Ge=[[],[]];function ze(e){return{kty:["RSA"],subtle:{name:"RSA-OAEP",hash:`SHA-${e}`},usages:Rr,ops:["wrapKey","unwrapKey"]}}function Ve(){return{kty:["EC","OKP"],subtle:{name:"ECDH"},resolve:({kty:e,crv:t,asymmetricKeyType:r})=>{if(t==="X25519"||r==="x25519")return{name:"X25519"};if(e==="OKP")throw new m('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');return{name:"ECDH",namedCurve:t}},usages:Nr,ops:[void 0,"deriveBits"]}}function ie(e,t=!1){return{kty:["oct"],secret:!0,subtle:{name:t?"AES-GCM":"AES-KW",length:e},usages:Ge,ops:t?["encrypt","decrypt"]:["wrapKey","unwrapKey"]}}function lt(){return{kty:["oct"],secret:!0,subtle:{name:"PBKDF2"},usages:Ge,ops:["deriveBits","deriveBits"]}}var mt=ge({dir:{kty:["oct"],secret:!0,subtle:{name:"AES-GCM"},usages:Ge,ops:["encrypt","decrypt"]},"RSA-OAEP":ze(1),"RSA-OAEP-256":ze(256),"RSA-OAEP-384":ze(384),"RSA-OAEP-512":ze(512),"ECDH-ES":Ve(),"ECDH-ES+A128KW":Ve(),"ECDH-ES+A192KW":Ve(),"ECDH-ES+A256KW":Ve(),A128KW:ie(128),A192KW:ie(192),A256KW:ie(256),A128GCMKW:ie(128,!0),A192GCMKW:ie(192,!0),A256GCMKW:ie(256,!0),"PBES2-HS256+A128KW":lt(),"PBES2-HS384+A192KW":lt(),"PBES2-HS512+A256KW":lt()}),Hr=["encrypt","decrypt"];function ae(e,t=!1){return{kty:["oct"],secret:!0,subtle:{name:t?"AES-CBC":"AES-GCM",length:e},usages:Ge,ops:Hr,cekBits:e,ivBits:t?128:96,cbc:t}}var kr=ge({A128GCM:ae(128),A192GCM:ae(192),A256GCM:ae(256),"A128CBC-HS256":ae(256,!0),"A192CBC-HS384":ae(384,!0),"A256CBC-HS512":ae(512,!0)});function jt(e,t){throw new m(`Invalid or unsupported "${e}" (JWE ${t}) header value`)}function R(e){return(typeof e==="string"?mt[e]:void 0)??jt("alg","Algorithm")}function ee(e){return(typeof e==="string"?kr[e]:void 0)??jt("enc","Encryption Algorithm")}function zt(e,t){if(e.algorithm.name!=="ECDH"&&e.algorithm.name!=="X25519")throw TypeError("CryptoKey does not support this operation, its algorithm.name must be ECDH or X25519");nt(e,t)}async function Gt(e,t,r){let n=R(t).subtle,o=e instanceof Uint8Array?await crypto.subtle.importKey("raw",e,"AES-KW",!0,[r]):e;return k(o,n,r),o}async function yt(e,t,r){let n=await Gt(t,e,"wrapKey"),o=await crypto.subtle.importKey("raw",r,{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.wrapKey("raw",o,n,"AES-KW"))}async function ht(e,t,r){let n=await Gt(t,e,"unwrapKey"),o=await crypto.subtle.unwrapKey("raw",r,n,"AES-KW",{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.exportKey("raw",o))}function Ft(e,t,r){k(t,R(e).subtle,r),Ie(e,t)}function Br(e,t){if(e instanceof Uint8Array)return crypto.subtle.importKey("raw",e,"PBKDF2",!1,["deriveBits"]);return k(e,R(t).subtle,"deriveBits"),e}async function Xt(e,t,r,n){if(!(e instanceof Uint8Array)||e.length<8)throw new f("PBES2 Salt Input must be 8 or more octets");if(!Number.isSafeInteger(r)||Math.sign(r)!==1)throw new f("PBES2 Count Input must be a positive integer");let o=A(b(t),Uint8Array.of(0),e),a=parseInt(t.slice(13,16),10),i={hash:`SHA-${t.slice(8,11)}`,iterations:r,name:"PBKDF2",salt:o},s=await Br(n,t);return new Uint8Array(await crypto.subtle.deriveBits(i,s,a))}function wt(e){return A(Te(e.length),e)}async function Mr(e,t,r){let n=t>>3,o=32,a=Math.ceil(n/32),i=new Uint8Array(a*32);for(let s=1;s<=a;s++){let c=await $e("sha256",A(Te(s),e,r));i.set(c,(s-1)*32)}return i.slice(0,n)}async function Yt(e,t,r,n,o=new Uint8Array,a=new Uint8Array){zt(e),zt(t,"deriveBits");let i=A(wt(b(r)),wt(o),wt(a),Te(n)),s=new Uint8Array(await crypto.subtle.deriveBits({name:e.algorithm.name,public:e},t,e.algorithm.name==="X25519"?256:Math.ceil(parseInt(e.algorithm.namedCurve.slice(-3),10)/8)<<3));return Mr(s,n,i)}function qt(e){Re(e);let t=e.algorithm.namedCurve;if(t!=="P-256"&&t!=="P-384"&&t!=="P-521"&&e.algorithm.name!=="X25519")throw new m("ECDH with the provided key is not allowed or not supported by your javascript runtime")}function Ee(e){if(e===void 0)throw new f("JWE Encrypted Key missing")}function Vt(e){if(e!==void 0)throw new f("Encountered unexpected JWE Encrypted Key")}async function Zt(e,t,r,n,o,a){let i=R(e);if(e==="dir")return Vt(n),r;switch(i.subtle.name){case"ECDH":{if(e==="ECDH-ES")Vt(n);if(!S(o.epk))throw new f('JOSE Header "epk" (Ephemeral Public Key) missing or invalid');qt(r);let s=await j(i,o.epk),c,p;if(o.apu!==void 0){if(typeof o.apu!=="string")throw new f('JOSE Header "apu" (Agreement PartyUInfo) invalid');c=W(o.apu,"apu",f)}if(o.apv!==void 0){if(typeof o.apv!=="string")throw new f('JOSE Header "apv" (Agreement PartyVInfo) invalid');p=W(o.apv,"apv",f)}let d=await Yt(s,r,e==="ECDH-ES"?t.alg:e,e==="ECDH-ES"?t.cekBits:parseInt(e.slice(-5,-2),10),c,p);if(e==="ECDH-ES")return d;return Ee(n),ht(e.slice(-6),d,n)}case"RSA-OAEP":return Ee(n),Re(r),Ft(e,r,"decrypt"),new Uint8Array(await crypto.subtle.decrypt("RSA-OAEP",r,n));case"PBKDF2":{if(Ee(n),typeof o.p2c!=="number")throw new f('JOSE Header "p2c" (PBES2 Count) missing or invalid');let s=a||1e4;if(o.p2c>s)throw new f('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');if(typeof o.p2s!=="string")throw new f('JOSE Header "p2s" (PBES2 Salt) missing or invalid');let c=W(o.p2s,"p2s",f),p=await Xt(c,e,o.p2c,r);return ht(e.slice(-6),p,n)}case"AES-KW":return Ee(n),ht(e,r,n);case"AES-GCM":{if(Ee(n),typeof o.iv!=="string")throw new f('JOSE Header "iv" (Initialization Vector) missing or invalid');if(typeof o.tag!=="string")throw new f('JOSE Header "tag" (Authentication Tag) missing or invalid');let s;s=W(o.iv,"iv",f);let c;return c=W(o.tag,"tag",f),ke(ee(e.slice(0,-2)),r,n,s,c,new Uint8Array)}}}async function Qt(e,t,r,n,o={}){let a,i,s,c=R(e);if(e==="dir")return[r,void 0,void 0];switch(c.subtle.name){case"ECDH":{qt(r);let{apu:p,apv:d}=o;if(p!==void 0)Z(p,'"apu"');if(d!==void 0)Z(d,'"apv"');let u;if(o.epk!==void 0)u=await U(c,o.epk,"decrypt");else u=(await crypto.subtle.generateKey(r.algorithm,!0,["deriveBits"])).privateKey;let l=crypto.subtle,K=u;if(!K.extractable){if(typeof l.getPublicKey!=="function")throw TypeError('CryptoKey for "epk" must be extractable');K=await l.getPublicKey(u,[])}let{x:T,y:g,crv:h,kty:v}=await l.exportKey("jwk",K),y=await Yt(r,u,e==="ECDH-ES"?t.alg:e,e==="ECDH-ES"?t.cekBits:parseInt(e.slice(-5,-2),10),p,d);if(i={epk:{x:T,crv:h,kty:v}},v==="EC")i.epk.y=g;if(p)i.apu=ir(p);if(d)i.apv=ir(d);if(e==="ECDH-ES"){s=y;break}s=n||L(t);let J=e.slice(-6);a=await yt(J,y,s);break}case"RSA-OAEP":{s=n||L(t),Re(r),Ft(e,r,"encrypt"),a=new Uint8Array(await crypto.subtle.encrypt("RSA-OAEP",r,s));break}case"PBKDF2":{s=n||L(t);let{p2c:p=2048,p2s:d=crypto.getRandomValues(new Uint8Array(16))}=o,u=await Xt(d,e,p,r);a=await yt(e.slice(-6),u,s),i={p2c:p,p2s:ir(d)};break}case"AES-KW":{s=n||L(t),a=await yt(e,r,s);break}case"AES-GCM":{s=n||L(t);let{iv:p}=o,d=await He(ee(e.slice(0,-2)),s,r,p,new Uint8Array);a=d.ciphertext,i={iv:ir(d.iv),tag:ir(d.tag)};break}}return[s,a,i]}var se={__proto__:null,b64:!0},Fe={__proto__:null};function be(e,t){if(t!==void 0&&(!Array.isArray(t)||t.some((r)=>typeof r!=="string")))throw TypeError(`"${e}" option must be an array of strings`);if(!t)return;return new Set(t)}function Xe(e,t){let{crit:r}=t??{};if(Array.isArray(r)&&new Set(r).size!==r.length)throw new e('"crit" (Critical) Header Parameter MUST NOT contain duplicate values')}function N(e,t,r,n,o){if(o.crit!==void 0&&n?.crit===void 0)throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');if(!n||n.crit===void 0)return[];if(!Array.isArray(n.crit)||n.crit.length===0||n.crit.some((i)=>typeof i!=="string"||i.length===0))throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');let a=r===void 0?t:{__proto__:null,...r,...t};for(let i of n.crit){if(!(i in a))throw new m(`Extension Header Parameter "${i}" is not recognized`);if(!Object.hasOwn(o,i)||o[i]===void 0)throw new e(`Extension Header Parameter "${i}" is missing`);if(a[i]&&(!Object.hasOwn(n,i)||n[i]===void 0))throw new e(`Extension Header Parameter "${i}" MUST be integrity protected`)}return n.crit}function ce(e,t){if(t.includes("b64")){let r=e.b64;if(typeof r!=="boolean")throw new w('The "b64" (base64url-encode payload) Header Parameter must be a boolean');return r}return!0}function pe(e,t){let r,n;try{r=JSON.stringify(t),n=JSON.parse(r)}catch(o){throw new e("JOSE Header is not valid JSON",{cause:o})}if(!S(n))throw new e("JOSE Header is not a JSON object");return[n,r]}function Ye(e,t){if(e.zip!==void 0&&e.zip!=="DEF")throw new m('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(e.zip!==void 0&&!t?.zip)throw new f('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.')}function er(e){if(typeof globalThis[e]>"u")throw new m(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${e} API.`)}async function tr(e){er("CompressionStream");let t=new CompressionStream("deflate-raw"),r=t.writable.getWriter();r.write(e).catch(()=>{}),r.close().catch(()=>{});let n=[],o=t.readable.getReader();for(;;){let{value:a,done:i}=await o.read();if(i)break;n.push(a)}return A(...n)}async function rr(e,t){er("DecompressionStream");let r=new DecompressionStream("deflate-raw"),n=r.writable.getWriter();n.write(e).catch(()=>{}),n.close().catch(()=>{});let o=[],a=0,i=r.readable.getReader();for(;;){let{value:s,done:c}=await i.read();if(c)break;if(o.push(s),a+=s.byteLength,t!==1/0&&a>t)throw new f("Decompressed plaintext exceeded the configured limit")}return A(...o)}function nr(e){return[e&&be("keyManagementAlgorithms",e.keyManagementAlgorithms),e&&be("contentEncryptionAlgorithms",e.contentEncryptionAlgorithms),e?.crit,e?.maxPBES2Count,e?.maxDecompressedLength]}async function $r(e,t,r,n,o){let[a,i,s,c,p]=r,[d,u,l,K,T]=t,{encrypted_key:g}=e;N(f,Fe,s,d,o),Ye(o,d);let{alg:h,enc:v}=o;if(typeof h!=="string"||!h)throw new f("missing JWE Algorithm (alg) in JWE Header");if(typeof v!=="string"||!v)throw new f("missing JWE Encryption Algorithm (enc) in JWE Header");if(a&&!a.has(h)||!a&&h.startsWith("PBES2"))throw new ne('"alg" (Algorithm) Header Parameter value not allowed');if(i&&!i.has(v))throw new ne('"enc" (Encryption Algorithm) Header Parameter value not allowed');let y=ee(v),J;if(g!==void 0)J=W(g,"encrypted_key",f);let P=!1;if(typeof n==="function")n=await n(d,e),P=!0;let H=R(h),O=await U(h==="dir"?y:H,n,"decrypt"),I;try{if(I=await Zt(h,y,O,J,o,c),g!==void 0&&I instanceof Uint8Array&&I.byteLength<<3!==y.cekBits)I=L(y)}catch(C){if(C instanceof TypeError||C instanceof f||C instanceof m)throw C;I=L(y)}let X=await ke(y,I,u,l,K,T);if(o.zip==="DEF"){let C=p??250000;if(C===0)throw new m('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');if(C!==1/0&&(!Number.isSafeInteger(C)||C<1))throw TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");X=await rr(X,C).catch((Y)=>{if(Y instanceof f)throw Y;throw new f("Failed to decompress plaintext",{cause:Y})})}return[X,d,O,P]}async function or(e,t,r){if(e instanceof Uint8Array)e=q.decode(e);if(typeof e!=="string")throw new f("Compact JWE must be a string or Uint8Array");let{0:n,1:o,2:a,3:i,4:s,length:c}=e.split(".");if(c!==5)throw new f("Invalid Compact JWE");let p={ciphertext:i,iv:a||void 0,protected:n,tag:s||void 0,encrypted_key:o||void 0},d=F(n,f,"JWE Protected Header is invalid"),u=b(n),l=[d,W(i,"ciphertext",f),a?W(a,"iv",f):void 0,s?W(s,"tag",f):void 0,u];return $r(p,l,t,r,d)}function ar(e,t,r){if(!Nt(e,t,r))throw new f("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint")}function Lr(e){let[,t,r,n,o,a,i,s,c]=e;if(o!==void 0)Z(o,"JWE Additional Authenticated Data");if(a!==void 0)Z(a,"JWE Content Encryption Key");if(i!==void 0)Z(i,"JWE Initialization Vector");if(t!==void 0)t=pe(f,t)[0],e[1]=t;if(r!==void 0)r=pe(f,r)[0],e[2]=r;if(n!==void 0)n=pe(f,n)[0],e[3]=n;if(s!==void 0&&!S(s))throw TypeError("JWE Key Management Parameters must be an object");ar(t,r,n);let p={...t,...r,...n};Xe(f,t),N(f,Fe,c,t,p),Ye(p,t);let{alg:d,enc:u}=p;if(typeof d!=="string"||!d)throw new f('JWE "alg" (Algorithm) Header Parameter missing or invalid');if(typeof u!=="string"||!u)throw new f('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');return[p,d,u,ee(u)]}async function jr(e,t,r){let[n,o,,a]=t,[i,s,c,p,d,u,l,K,,T]=e,g=s,h=c;if(u&&(o==="dir"||o==="ECDH-ES"))throw TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${o}`);let v=R(o),y=await U(o==="dir"?a:v,r,"encrypt"),[J,P,H]=await Qt(o,a,y,u,K);if(H){if(T)h=h?{...h,...H}:H;else g=g?{...g,...H}:H;ar(g,h,p)}let O,I;if(g)O=ir(JSON.stringify(g)),I=b(O);else O="",I=new Uint8Array;let X,C;if(d?.byteLength)C=ir(d),X=A(I,b("."),b(C));else X=I;let Y=i;if(n.zip==="DEF")Y=await tr(Y).catch((Jr)=>{throw new f("Failed to compress plaintext",{cause:Jr})});let{ciphertext:Kr,tag:Pt,iv:It}=await He(a,Y,J,l,X),G={ciphertext:ir(Kr)};if(It)G.iv=ir(It);if(Pt)G.tag=ir(Pt);if(P)G.encrypted_key=ir(P);if(C)G.aad=C;if(g)G.protected=O;if(p)G.unprotected=p;if(h)G.header=h;return G}async function sr(e,t,r){if(!e[1]&&!e[2]&&!e[3])throw new f("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");if(r!==void 0)e[8]=r?.crit,e[9]=r?Ht in r:!1;return jr(e,Lr(e),t)}async function cr(e,t,r){if(t instanceof Uint8Array)return crypto.subtle.importKey("raw",t,e.subtle,!1,[r]);if(k(t,e.subtle,r),e.minRsaBits)Ie(e.alg,t);return t}async function pr(e,t,r){let n=await cr(e,t,"sign"),o=await crypto.subtle.sign(e.signing,n,r);return new Uint8Array(o)}async function dr(e,t,r,n){let o=await cr(e,t,"verify");try{return await crypto.subtle.verify(e.signing,o,r,n)}catch{return!1}}var Se=[["verify"],["sign"]];function gt(e){let t={name:"HMAC",hash:`SHA-${e}`};return{kty:["oct"],secret:!0,subtle:t,signing:t,usages:Se}}function de(e,t){let n={name:t?"RSA-PSS":"RSASSA-PKCS1-v1_5",hash:`SHA-${e}`};return{kty:["RSA"],subtle:n,signing:t?{...n,saltLength:t}:n,usages:Se,minRsaBits:2048}}function Et(e,t){return{kty:["EC"],crv:e,subtle:{name:"ECDSA",namedCurve:e},signing:{name:"ECDSA",hash:`SHA-${t}`},usages:Se}}function fr(){let e={name:"Ed25519"};return{kty:["OKP"],crv:"Ed25519",subtle:e,signing:e,usages:Se}}function bt(e){let r={name:`ML-DSA-${e}`};return{kty:["AKP"],subtle:r,signing:r,usages:Se}}var Ae=ge({HS256:gt(256),HS384:gt(384),HS512:gt(512),RS256:de(256),RS384:de(384),RS512:de(512),PS256:de(256,32),PS384:de(384,48),PS512:de(512,64),ES256:Et("P-256",256),ES384:Et("P-384",384),ES512:Et("P-521",512),EdDSA:fr(),Ed25519:fr(),"ML-DSA-44":bt(44),"ML-DSA-65":bt(65),"ML-DSA-87":bt(87)});function qe(e){let t=typeof e==="string"?Ae[e]:void 0;if(!t)throw new m(`alg ${e} is not supported either by JOSE or your javascript runtime`);return t}function ur(e){return[e&&be("algorithms",e.algorithms),e?.crit]}function zr(e,t=e===void 0?{}:F(e,w,"JWS Protected Header is invalid")){return t}function Vr(e,t,r){let n=ce(e,N(w,se,r[1],e,t)),o=t.alg;if(typeof o!=="string"||!o)throw new w('JWS "alg" (Algorithm) Header Parameter missing or invalid');if(r[0]&&!r[0].has(o))throw new ne('"alg" (Algorithm) Header Parameter value not allowed');return[n,o]}function Gr(e){try{return b(e)}catch{throw new w("JWS Compact Serialization payload must use only ASCII characters")}}async function Xr(e,t,r,n,o,a,i){let s=!1;if(typeof r==="function")r=await r(o,e),s=!0;let c=typeof i==="string",p=qe(a),d=A(n!==void 0?b(n):new Uint8Array,b("."),c?t[2]??=dt(i,"payload",w):i),u=W(e.signature,"signature",w),l=await U(p,r,"verify");if(!await dr(p,l,u,d))throw new at;return[c?W(i,"payload",w):i,o,c,l,s]}async function lr(e,t,r){if(e instanceof Uint8Array)e=q.decode(e);if(typeof e!=="string")throw new w("Compact JWS must be a string or Uint8Array");let{0:n,1:o,2:a,length:i}=e.split(".");if(i!==3)throw new w("Invalid Compact JWS");let s={payload:o,protected:n,signature:a},c=zr(n),[p,d]=Vr(c,c,t),u=p?o:Gr(o);return Xr(s,t,r,n,c,d,u)}var xe=(e)=>Math.floor(e.getTime()/1000),Yr={s:1,m:60,h:3600,d:86400,w:604800,y:31557600},qr=/^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i,fe="check_failed";function St(){throw TypeError("Invalid time period format")}function Ze(e){if(typeof e!=="string")St();let t=qr.exec(e);if(!t||t[4]&&t[1])St();let r=parseFloat(t[2]),n=Math.round(r*Yr[t[3][0].toLowerCase()]);if(!Number.isFinite(n))St();if(t[1]==="-"||t[4]==="ago")return-n;return n}function ue(e,t){if(!Number.isFinite(t))throw TypeError(`Invalid ${e} input`);return t}function At(e,t){if(typeof t!=="string")throw TypeError(`"${e}" claim must be a string`)}function Zr(e){if(typeof e!=="string"&&(!Array.isArray(e)||Array.from(e).some((t)=>typeof t!=="string")))throw TypeError('"aud" claim must be a string or an array of strings')}function xt(e,t){if(typeof e==="number")return ue(t,e);if(e instanceof Date)return ue(t,xe(e));return xe(new Date)+Ze(e)}var mr=(e)=>{let t=e.toLowerCase();return e.includes("/")?t:`application/${t}`},Qr=(e,t)=>{if(typeof e==="string")return t.includes(e);if(Array.isArray(e))return t.some((r)=>e.includes(r));return!1};function Kt(e,t,r=!1){let n=e[t];if(n===void 0&&!r)return;if(typeof n!=="number")throw new _(`"${t}" claim must be a number`,e,t,"invalid");return n}function Jt(e,t){throw new _(`unexpected "${t}" claim value`,e,t,fe)}function le(e,t,r={}){let n;try{n=JSON.parse(re.decode(t))}catch{}if(!S(n))throw new E("JWT Claims Set must be a top-level JSON object");let{typ:o}=r;if(o!==void 0&&(typeof e.typ!=="string"||mr(e.typ)!==mr(o)))throw new _('unexpected "typ" JWT header value',n,"typ",fe);let{requiredClaims:a=[],issuer:i,subject:s,audience:c,maxTokenAge:p}=r,d=[...a];if(p!==void 0)d.push("iat");if(c!==void 0)d.push("aud");if(s!==void 0)d.push("sub");if(i!==void 0)d.push("iss");for(let y of new Set(d.reverse()))if(!Object.hasOwn(n,y))throw new _(`missing required "${y}" claim`,n,y,"missing");if(i!==void 0&&!(Array.isArray(i)?i:[i]).includes(n.iss))Jt(n,"iss");if(s!==void 0&&n.sub!==s)Jt(n,"sub");if(c!==void 0&&!Qr(n.aud,typeof c==="string"?[c]:c))Jt(n,"aud");let{clockTolerance:u}=r,l=0;if(typeof u==="string")l=Ze(u);else if(u!==void 0){if(typeof u!=="number")throw TypeError("Invalid clockTolerance option type");l=u}ue("clockTolerance option",l);let{currentDate:K}=r,T=ue("currentDate option",xe(K===void 0?new Date:K)),g=Kt(n,"iat",p!==void 0),h=Kt(n,"nbf");if(h!==void 0){if(h>T+l)throw new _('"nbf" claim timestamp check failed',n,"nbf",fe)}let v=Kt(n,"exp");if(v!==void 0){if(v<=T-l)throw new $i('"exp" claim timestamp check failed',n,"exp",fe)}if(p!==void 0){let y=T-g,J=ue("maxTokenAge option",typeof p==="number"?p:Ze(p));if(y-l>J)throw new $i('"iat" claim timestamp check failed (too far in the past)',n,"iat",fe);if(y<-l)throw new _('"iat" claim timestamp check failed (it should be in the past)',n,"iat",fe)}return n}var yr;function z(e){return yr.get(e)}function me(e){let t=z(e);for(let r of["iat","nbf","exp"]){let n=t[r];if(typeof n==="number"&&!Number.isFinite(n))throw TypeError(`"${r}" claim must be a finite number`)}return ye.encode(JSON.stringify(t))}function Qe(e,t){return z(e)[t]}class te{constructor(e={}){if(!S(e))throw TypeError("JWT Claims Set MUST be an object");(yr||=new WeakMap).set(this,structuredClone(e))}setIssuer(e){return At("iss",e),z(this).iss=e,this}setSubject(e){return At("sub",e),z(this).sub=e,this}setAudience(e){return Zr(e),z(this).aud=e,this}setJti(e){return At("jti",e),z(this).jti=e,this}setNotBefore(e){return z(this).nbf=xt(e,"setNotBefore"),this}setExpirationTime(e){return z(this).exp=xt(e,"setExpirationTime"),this}setIssuedAt(e){let t=z(this);if(e===void 0)t.iat=xe(new Date);else if(typeof e==="string")t.iat=ue("setIssuedAt",xe(new Date)+Ze(e));else t.iat=xt(e,"setIssuedAt");return this}}async function kn(e,t,r){let n=await lr(e,ur(r),t);if(!n[2])throw new E("JWTs MUST NOT use unencoded payload");let a={payload:le(n[1],n[0],r),protectedHeader:n[1]};if(typeof t==="function")return{...a,key:n[3]};return a}async function nc(e,t,r){let n=await or(e,nr(r),t),o=n[1],a=le(o,n[0],r);for(let s of["iss","sub","aud"])if(o[s]!==void 0&&(s==="aud"?JSON.stringify(o.aud)!==JSON.stringify(a.aud):o[s]!==a[s]))throw new _(`replicated "${s}" claim header parameter mismatch`,a,s,"mismatch");let i={payload:a,protectedHeader:o};if(typeof t==="function")return{...i,key:n[2]};return i}function en(e){if(e===void 0)return[void 0,""];let t=pe(w,e);return[t[0],ir(t[1])]}function tn(e,t,r){return Xe(w,e),ce(e,N(w,se,r,e,t))}function rn(e){let t=e.alg;if(typeof t!=="string"||!t)throw new w('JWS "alg" (Algorithm) Header Parameter missing or invalid');return qe(t)}async function nn(e,t,r,n){let o=A(b(e),b("."),t),a=await U(r,n,"sign");return ir(await pr(r,a,o))}async function hr(e,t,r,n,o){let[a,i]=en(t);if(!a)throw new w("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!tn(a,a,r))o();let c=rn(a),p=ir(e),d=await nn(i,b(p),c,n);return`${i}.${p}.${d}`}var on=te;class oc extends on{#e;setProtectedHeader(e){return Q(this.#e,"setProtectedHeader"),this.#e=e,this}async sign(e,t){return hr(me(this),this.#e,t?.crit,e,()=>{throw new E("JWTs MUST NOT use unencoded payload")})}}var an=te;class sc extends an{#e;#r;#n;#t;#o;#i;#a;setProtectedHeader(e){return Q(this.#t,"setProtectedHeader"),this.#t=e,this}setKeyManagementParameters(e){return Q(this.#n,"setKeyManagementParameters"),this.#n=e,this}setContentEncryptionKey(e){return Q(this.#e,"setContentEncryptionKey"),this.#e=e,this}setInitializationVector(e){return Q(this.#r,"setInitializationVector"),this.#r=e,this}replicateIssuerAsHeader(){return this.#o=!0,this}replicateSubjectAsHeader(){return this.#i=!0,this}replicateAudienceAsHeader(){return this.#a=!0,this}async encrypt(e,t){let r=me(this);if(this.#t&&(this.#o||this.#i||this.#a))this.#t={...this.#t,iss:this.#o?Qe(this,"iss"):void 0,sub:this.#i?Qe(this,"sub"):void 0,aud:this.#a?Qe(this,"aud"):void 0};let n=await sr([r,this.#t,void 0,void 0,void 0,this.#e,this.#r,this.#n,void 0,!1],e,t);return[n.protected,n.encrypted_key,n.iv,n.ciphertext,n.tag].join(".")}}var Wt='"alg" (Algorithm)';function Ct(e='JWK "alg" (Algorithm) Parameter'){throw new m(`Invalid or unsupported ${e} value`)}function Ke(e,t){return(typeof e==="string"?Ae[e]??mt[e]:void 0)??Ct(t)}function et(e){if(e!==void 0&&typeof e!=="boolean")throw TypeError('"extractable" option must be a boolean');return e}var Je=(e,t)=>{if(e.byteLength!==t.length)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0},sn=(e)=>({data:e,pos:0}),vt=(e)=>{let t=e.data[e.pos++];if(t===void 0)throw Error("Unexpected end of ASN.1 input");return t},We=(e)=>{let t=vt(e);if(t&128){let r=t&127,n=0;for(let o=0;o<r;o++)n=n<<8|vt(e);return n}return t};var Ce=(e,t,r)=>{if(vt(e)!==t)throw Error(r)},wr=(e,t)=>{if(t<0||e.pos+t>e.data.length)throw Error("Unexpected end of ASN.1 input");let r=e.data.subarray(e.pos,e.pos+t);return e.pos+=t,r},cn=(e)=>{Ce(e,6,"Expected algorithm OID");let t=We(e);return wr(e,t)};function pn(e,t){if(Ce(e,48,`Invalid ${t==="spki"?"SPKI":"PKCS#8"} structure`),We(e),t==="pkcs8"){Ce(e,2,"Expected version field");let r=We(e);e.pos+=r}Ce(e,48,"Expected algorithm identifier"),We(e)}var dn=(e)=>{let t=cn(e);if(Je(t,[43,101,110]))return"X25519";if(!Je(t,[42,134,72,206,61,2,1]))throw Error("Unsupported key algorithm");Ce(e,6,"Expected curve OID");let r=We(e),n=wr(e,r);if(Je(n,[42,134,72,206,61,3,1,7]))return"P-256";if(Je(n,[43,129,4,0,34]))return"P-384";if(Je(n,[43,129,4,0,35]))return"P-521";throw Error("Unsupported named curve")},fn=async(e,t,r,n)=>{let o=et(n?.extractable),a=Ke(r,Wt);if(a.secret)Ct(Wt);let i=e==="spki",s;if(a.resolve)try{let c=sn(t);pn(c,e),s=a.resolve({crv:dn(c)})}catch{throw new m("Invalid or unsupported key format")}else s=a.subtle;return crypto.subtle.importKey(e,t,s,o??i,a.usages[i?0:1])},un=(e,t)=>Be(e.replace(t,"")),gr=(e,t,r)=>{let n=un(e,/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);return fn("pkcs8",n,t,r)};function ln(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}async function mn(e){if(st(e))if(e.type==="secret")e=e.export();else return e.export({format:"jwk"});if(e instanceof Uint8Array)return{kty:"oct",k:ir(e)};if(!M(e))throw TypeError(B(e,"CryptoKey","KeyObject","Uint8Array"));if(!e.extractable)throw TypeError("non-extractable CryptoKey cannot be exported as a JWK");let{ext:t,key_ops:r,alg:n,use:o,...a}=ln(await crypto.subtle.exportKey("jwk",e));if(a.kty==="AKP")a.alg=n;return a}function Er(e){return mn(e)}var V=(e,t)=>{if(typeof e!=="string"||!e)throw new De(`${t} missing or invalid`)};async function ac(e,t){let r;if(S(e)){if(r=oe(e),typeof r.kty!=="string")throw TypeError(B(e,"CryptoKey","KeyObject","JSON Web Key"))}else if(Ne(e))r=oe(await Er(e));else throw TypeError(B(e,"CryptoKey","KeyObject","JSON Web Key"));if(t??="sha256",t!=="sha256"&&t!=="sha384"&&t!=="sha512")throw TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');let n;switch(r.kty){case"AKP":V(r.alg,'"alg" (Algorithm) Parameter'),V(r.pub,'"pub" (Public key) Parameter'),n={alg:r.alg,kty:r.kty,pub:r.pub};break;case"EC":V(r.crv,'"crv" (Curve) Parameter'),V(r.x,'"x" (X Coordinate) Parameter'),V(r.y,'"y" (Y Coordinate) Parameter'),n={crv:r.crv,kty:r.kty,x:r.x,y:r.y};break;case"OKP":V(r.crv,'"crv" (Subtype of Key Pair) Parameter'),V(r.x,'"x" (Public Key) Parameter'),n={crv:r.crv,kty:r.kty,x:r.x};break;case"RSA":V(r.e,'"e" (Exponent) Parameter'),V(r.n,'"n" (Modulus) Parameter'),n={e:r.e,kty:r.kty,n:r.n};break;case"oct":if(typeof r.k!=="string")throw new De('"k" (Key Value) Parameter missing or invalid');n={k:r.k,kty:r.kty};break;default:throw new m('"kty" (Key Type) Parameter missing or unsupported')}let o=b(JSON.stringify(n));return ir(await $e(t,o))}function yn(e,t,r,n){let{kty:o,key_ops:a,ext:i,kid:s,alg:c,use:p,crv:d}=oe(e),u=Array.isArray(a)?[...a]:a;return(i===void 0||typeof i==="boolean")&&(u===void 0||Array.isArray(u)&&u.every((l,K)=>typeof l==="string"&&u.indexOf(l)===K)&&u.includes("verify"))&&t.kty.includes(o)&&(n===void 0||typeof n==="string"&&n===s)&&(c===void 0?o!=="AKP":r===c)&&(p===void 0||p==="sig")&&(!t.crv||d===t.crv)}async function br(e,t,r){let n=e.get(t)||e.set(t,{}).get(t),{alg:o}=r;if(n[o]===void 0){let a=await j(r,{...t,alg:o,ext:!0});if(a.type!=="public")throw new Ue("JSON Web Key Set members must be public keys");n[o]=a}return n[o]}function mu(e){let t;try{t=structuredClone(e)}catch{}if(!Me(t))throw new Ue("JSON Web Key Set malformed");let r=new WeakMap;return Object.defineProperty(async(o,a)=>{let{alg:i,kid:s}={...o,...a?.header},c=typeof i==="string"?Ae[i]:void 0;if(!c||c.secret)throw new m('Unsupported "alg" value for a JSON Web Key Set');let p=t.keys.filter((l)=>yn(l,c,i,s)),{0:d,length:u}=p;if(!u)throw new we;if(u!==1){let l=new ot;throw l[Symbol.asyncIterator]=async function*(){for(let K of p)try{yield await br(r,K,c)}catch{}},l}return br(r,d,c)},"jwks",{value:()=>structuredClone(t)})}function hn(){return typeof WebSocketPair<"u"||typeof navigator<"u"&&navigator.userAgent==="Cloudflare-Workers"||typeof EdgeRuntime<"u"&&EdgeRuntime==="vercel"}var Tt;if(typeof navigator>"u"||!navigator.userAgent?.startsWith?.("Mozilla/5.0 "))Tt="jose/v6.2.10";var Ar=Symbol();async function wn(e,t,r,n=fetch){let o=await n(e,{method:"GET",signal:r,redirect:"manual",headers:t}).catch((a)=>{if(a.name==="TimeoutError")throw new it;throw a});if(o.status!==200)throw new x("Expected 200 OK from the JSON Web Key Set HTTP response");try{return await o.json()}catch{throw new x("Failed to parse the JSON Web Key Set HTTP response as JSON")}}var xr=Symbol();function ve(e,t){return Number.isFinite(e)&&Date.now()<e+t}function Sr(e,t,r){if(Number.isNaN(e))throw TypeError(`"${r}" option must not be NaN`);return typeof e==="number"?e:t}function hu(e,t){if(!(e instanceof URL))throw TypeError("url must be an instance of URL");let r=new URL(e.href).href,n=t??{},o=n.timeoutDuration;if(typeof o==="number"&&(!Number.isInteger(o)||o<0))throw TypeError('"timeoutDuration" option must be a non-negative integer');let a=typeof o==="number"?o:5000,i=Sr(n.cooldownDuration,30000,"cooldownDuration"),s=Sr(n.cacheMaxAge,600000,"cacheMaxAge"),c=new Headers(n.headers);if(Tt&&!c.has("User-Agent"))c.set("User-Agent",Tt);if(!c.has("accept"))c.set("accept","application/json, application/jwk-set+json");let p=n[Ar],d=n[xr],u,l,K=0,T=0,g;if(d&&typeof d==="object"){let{uat:y,jwks:J}=d;if(ve(y,s)&&Me(J))u=y,g=mu(J)}let h=async()=>{if(l&&hn())l=void 0;if(!l){let y=++K,J=l=wn(r,c,AbortSignal.timeout(a),p).then((P)=>{let H=mu(P);if(y<=T)return;g=H;let O=Date.now();if(d)d.uat=O,d.jwks=P;u=O,T=y}).finally(()=>{if(l===J)l=void 0})}await l};return Object.defineProperties(async(y,J)=>{if(!g||!ve(u,s))await h();try{return await g(y,J)}catch(P){if(P instanceof we&&!ve(u,i))return await h(),g(y,J);throw P}},{coolingDown:{get:()=>ve(u,i),enumerable:!0},fresh:{get:()=>ve(u,s),enumerable:!0},reload:{value:h,enumerable:!0},reloading:{get:()=>!!l,enumerable:!0},jwks:{value:()=>g?.jwks(),enumerable:!0}})}var gn=te;class em extends gn{encode(){let e=ir(JSON.stringify({alg:"none"})),t=ir(me(this));return`${e}.${t}.`}static decode(e,t){if(typeof e!=="string")throw new E("Unsecured JWT must be a string");let{0:r,1:n,2:o,length:a}=e.split(".");if(a!==3||o!=="")throw new E("Invalid Unsecured JWT");let i,s;try{i=F(r,w,"JWS Protected Header is invalid");let p=N(w,se,void 0,i,i);s=ce(i,p)}catch(p){if(!(p instanceof w))throw p;throw new E("Invalid Unsecured JWT",{cause:p})}if(i.alg!=="none")throw new E("Invalid Unsecured JWT");if(!s)throw new E("JWTs MUST NOT use unencoded payload");return{payload:le(i,W(n,"payload",E),t),header:i}}}async function nA(e,t,r){if(typeof e!=="string"||e.indexOf("-----BEGIN PRIVATE KEY-----")!==0)throw TypeError('"pkcs8" must be PKCS#8 formatted string');return gr(e,t,r)}async function ys(e,t,r){if(!S(e))throw TypeError("JWK must be an object");let n=Le(e),o=et(r?.extractable),{alg:a}=n;t??=a;let i=o??n.ext;if(n.kty!=="oct"&&!t)throw TypeError('"alg" argument is required when "jwk.alg" is not present');switch(n.kty){case"oct":if(typeof n.k!=="string")throw TypeError('missing "k" (Key Value) Parameter value');return D(n.k);case"AKP":{if(typeof a!=="string"||!a)throw TypeError('missing "alg" (Algorithm) Parameter value');if(t!==a)throw TypeError("JWK alg and alg option value mismatch");return j(Ke(t),{...n,ext:i})}case"RSA":case"EC":case"OKP":return j(Ke(t),{...n,alg:t,ext:i});default:throw new m('Unsupported "kty" (Key Type) Parameter value')}}function zo(e){let t;if(typeof e==="string"){let n=e.split(".");if(n.length===3||n.length===5)[t]=n}else if(typeof e==="object"&&e)if("protected"in e)t=e.protected;else throw TypeError("Token does not contain a Protected Header");let r="Invalid Token or Protected Header formatting";if(typeof t!=="string"||!t)throw TypeError(r);return F(t,TypeError,r)}function Fr(e){if(typeof e!=="string")throw new E("JWTs must use Compact JWS serialization, JWT must be a string");let{1:t,length:r}=e.split(".");if(r===5)throw new E("Only JWTs using Compact JWS serialization can be decoded");if(r!==3)throw new E("Invalid JWT");if(!t)throw new E("JWTs must contain a payload");let n;try{n=D(t)}catch{throw new E("Failed to base64url decode the payload")}let o;try{o=JSON.parse(re.decode(n))}catch{throw new E("Failed to parse the decoded payload as JSON")}if(!S(o))throw new E("Invalid JWT Claims Set");return o}export{$i,ir,Jd,kn,nc,oc,sc,ac,mu,hu,em,nA,ys,zo,Fr};
2
+ import{Oe}from"./chunk-qbqym9m6.js";var ye=new TextEncoder,q=new TextDecoder,re=new TextDecoder("utf-8",{fatal:!0});function A(...e){let t=e.reduce((o,{length:a})=>o+a,0),r=new Uint8Array(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}function tt(e,t,r){if(t<0||t>=4294967296)throw RangeError(`value must be >= 0 and <= 4294967295. Received ${t}`);e.set([t>>>24,t>>>16,t>>>8,t&255],r)}function rt(e){let t=Math.floor(e/4294967296),r=e%4294967296,n=new Uint8Array(8);return tt(n,t,0),tt(n,r,4),n}function Te(e){let t=new Uint8Array(4);return tt(t,e),t}function b(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++){let n=e.charCodeAt(r);if(n>127)throw TypeError("non-ASCII string encountered in encode()");t[r]=n}return t}var Pe=(e,t="algorithm.name")=>TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);function nt(e,t){if(t&&!e.usages.includes(t))throw TypeError(`CryptoKey does not support this operation, its usages must include ${t}.`)}function Ie(e,t){let{modulusLength:r}=t.algorithm;if(typeof r!=="number"||r<2048)throw TypeError(`${e} requires key modulusLength to be 2048 bits or larger`)}function k(e,t,r){let n=e.algorithm;if(n.name!==t.name)throw Pe(t.name);if(t.hash&&n.hash?.name!==t.hash)throw Pe(t.hash,"algorithm.hash");if(t.namedCurve&&n.namedCurve!==t.namedCurve)throw Pe(t.namedCurve,"algorithm.namedCurve");if(t.length!==void 0&&n.length!==t.length)throw Pe(t.length,"algorithm.length");nt(e,r)}function Ot(e,t,...r){if(r.length>2){let n=r.pop();e+=`one of type ${r.join(", ")}, or ${n}.`}else if(r.length===2)e+=`one of type ${r[0]} or ${r[1]}.`;else e+=`of type ${r[0]}.`;if(t==null)e+=` Received ${t}`;else if(typeof t==="function"&&t.name)e+=` Received function ${t.name}`;else if(typeof t==="object"&&t!=null){if(t.constructor?.name)e+=` Received an instance of ${t.constructor.name}`}return e}var B=(e,...t)=>Ot("Key must be ",e,...t),he=(e,t,...r)=>Ot(`Key for the ${e} algorithm must be `,t,...r);class x extends Error{static code="ERR_JOSE_GENERIC";code="ERR_JOSE_GENERIC";constructor(e,t){super(e,t);this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}}class _ extends x{static code="ERR_JWT_CLAIM_VALIDATION_FAILED";code="ERR_JWT_CLAIM_VALIDATION_FAILED";claim;reason;payload;constructor(e,t,r="unspecified",n="unspecified"){super(e,{cause:{claim:r,reason:n,payload:t}});this.claim=r,this.reason=n,this.payload=t}}class Qi extends x{static code="ERR_JWT_EXPIRED";code="ERR_JWT_EXPIRED";claim;reason;payload;constructor(e,t,r="unspecified",n="unspecified"){super(e,{cause:{claim:r,reason:n,payload:t}});this.claim=r,this.reason=n,this.payload=t}}class ne extends x{static code="ERR_JOSE_ALG_NOT_ALLOWED";code="ERR_JOSE_ALG_NOT_ALLOWED"}class m extends x{static code="ERR_JOSE_NOT_SUPPORTED";code="ERR_JOSE_NOT_SUPPORTED"}class _e extends x{static code="ERR_JWE_DECRYPTION_FAILED";code="ERR_JWE_DECRYPTION_FAILED";constructor(e="decryption operation failed",t){super(e,t)}}class f extends x{static code="ERR_JWE_INVALID";code="ERR_JWE_INVALID"}class w extends x{static code="ERR_JWS_INVALID";code="ERR_JWS_INVALID"}class E extends x{static code="ERR_JWT_INVALID";code="ERR_JWT_INVALID"}class De extends x{static code="ERR_JWK_INVALID";code="ERR_JWK_INVALID"}class Ue extends x{static code="ERR_JWKS_INVALID";code="ERR_JWKS_INVALID"}class we extends x{static code="ERR_JWKS_NO_MATCHING_KEY";code="ERR_JWKS_NO_MATCHING_KEY";constructor(e="no applicable key found in the JSON Web Key Set",t){super(e,t)}}class ot extends x{[Symbol.asyncIterator]=async function*(){};static code="ERR_JWKS_MULTIPLE_MATCHING_KEYS";code="ERR_JWKS_MULTIPLE_MATCHING_KEYS";constructor(e="multiple matching keys found in the JSON Web Key Set",t){super(e,t)}}class it extends x{static code="ERR_JWKS_TIMEOUT";code="ERR_JWKS_TIMEOUT";constructor(e="request timed out",t){super(e,t)}}class at extends x{static code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";constructor(e="signature verification failed",t){super(e,t)}}function Re(e){if(!M(e))throw Error("CryptoKey instance expected")}var M=(e)=>{if(e?.[Symbol.toStringTag]==="CryptoKey")return!0;try{return e instanceof CryptoKey}catch{return!1}},st=(e)=>e?.[Symbol.toStringTag]==="KeyObject",Ne=(e)=>M(e)||st(e);var L=(e)=>crypto.getRandomValues(new Uint8Array(e.cekBits>>3));function _t(e,t){let r=e.byteLength<<3;if(r!==t)throw new f(`Invalid Content Encryption Key length. Expected ${t} bits, got ${r} bits`)}var Wr=(e)=>crypto.getRandomValues(new Uint8Array(e.ivBits>>3));function Dt(e,t){if(t.length<<3!==e.ivBits)throw new f("Invalid Initialization Vector length")}async function Ut(e,t,r){if(!(t instanceof Uint8Array))throw TypeError(B(t,"Uint8Array"));let n=e.cekBits>>1,o=await crypto.subtle.importKey("raw",t.subarray(n>>3),"AES-CBC",!1,[r]),a=await crypto.subtle.importKey("raw",t.subarray(0,n>>3),{hash:`SHA-${n<<1}`,name:"HMAC"},!1,["sign"]);return[o,a,n]}async function Rt(e,t,r){return new Uint8Array((await crypto.subtle.sign("HMAC",e,t)).slice(0,r>>3))}async function Cr(e,t,r,n,o){let[a,i,s]=await Ut(e,r,"encrypt"),c=new Uint8Array(await crypto.subtle.encrypt({iv:n,name:"AES-CBC"},a,t)),p=A(o,n,c,rt(o.length*8)),d=await Rt(i,p,s);return{ciphertext:c,tag:d,iv:n}}async function vr(e,t){let r={name:"HMAC",hash:"SHA-256"},n=await crypto.subtle.generateKey(r,!1,["sign","verify"]),o=await crypto.subtle.sign(r,n,e);return crypto.subtle.verify(r,n,o,t)}async function Tr(e,t,r,n,o,a){let[i,s,c]=await Ut(e,t,"decrypt"),p=A(a,n,r,rt(a.length*8)),d=await Rt(s,p,c);try{if(await vr(o,d))return new Uint8Array(await crypto.subtle.decrypt({iv:n,name:"AES-CBC"},i,r))}catch{}throw new _e}async function Pr(e,t,r,n,o){let a=r instanceof Uint8Array?await crypto.subtle.importKey("raw",r,"AES-GCM",!1,["encrypt"]):(k(r,e.subtle,"encrypt"),r),i=new Uint8Array(await crypto.subtle.encrypt({additionalData:o,iv:n,name:"AES-GCM",tagLength:128},a,t)),s=i.slice(-16);return{ciphertext:i.slice(0,-16),tag:s,iv:n}}async function Ir(e,t,r,n,o,a){let i=t instanceof Uint8Array?await crypto.subtle.importKey("raw",t,"AES-GCM",!1,["decrypt"]):(k(t,e.subtle,"decrypt"),t);try{return new Uint8Array(await crypto.subtle.decrypt({additionalData:a,iv:n,name:"AES-GCM",tagLength:128},i,A(r,o)))}catch{throw new _e}}async function He(e,t,r,n,o){if(!M(r)&&!(r instanceof Uint8Array))throw TypeError(B(r,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(n)Dt(e,n);else n=Wr(e);if(r instanceof Uint8Array)_t(r,e.cekBits);return e.cbc?Cr(e,t,r,n,o):Pr(e,t,r,n,o)}async function ke(e,t,r,n,o,a){if(!M(t)&&!(t instanceof Uint8Array))throw TypeError(B(t,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(!n)throw new f("JWE Initialization Vector missing");if(!o)throw new f("JWE Authentication Tag missing");if(!e.cbc&&o.length!==16)throw new f("Invalid Authentication Tag length");if(Dt(e,n),t instanceof Uint8Array)_t(t,e.cekBits);return e.cbc?Tr(e,t,r,n,o,a):Ir(e,t,r,n,o,a)}var tf={};Oe(tf,{decode:()=>D,encode:()=>cr});function ct(e){if(Uint8Array.prototype.toBase64)return e.toBase64();let t=32768,r=[];for(let n=0;n<e.length;n+=t)r.push(String.fromCharCode.apply(null,e.subarray(n,n+t)));return btoa(r.join(""))}function Be(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(e);let t=atob(e),r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return r}var pt="The input to be decoded is not correctly encoded.";function D(e){if(Uint8Array.fromBase64)try{return Uint8Array.fromBase64(typeof e==="string"?e:q.decode(e),{alphabet:"base64url"})}catch(r){throw TypeError(pt,{cause:r})}let t=e;if(t instanceof Uint8Array)t=q.decode(t);if(t.includes("+")||t.includes("/"))throw TypeError(pt);t=t.replace(/-/g,"+").replace(/_/g,"/");try{return Be(t)}catch{throw TypeError(pt)}}function cr(e){let t=e;if(typeof t==="string")t=ye.encode(t);if(Uint8Array.prototype.toBase64)return t.toBase64({alphabet:"base64url",omitPadding:!0});return ct(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function Z(e,t){if(!(e instanceof Uint8Array))throw TypeError(`${t} must be an instance of Uint8Array`)}function S(e){if(typeof e!=="object"||e===null||Object.prototype.toString.call(e)!=="[object Object]")return!1;let t=Object.getPrototypeOf(e);return t===null||Object.getPrototypeOf(t)===null}function Me(e){return S(e)&&Array.isArray(e.keys)&&Array.from(e.keys).every(S)}function Nt(...e){let t=new Set;for(let r of e){if(!r)continue;for(let n of Object.keys(r)){if(t.has(n))return!1;t.add(n)}}return!0}var Ht=Symbol();function Q(e,t){if(e!==void 0)throw TypeError(`${t} can only be called once`)}function W(e,t,r){try{return D(e)}catch{throw new r(`Failed to base64url decode the ${t}`)}}function dt(e,t,r){try{return b(e)}catch{throw new r(`The ${t} is not a valid base64url string`)}}async function $e(e,t){let r=`SHA-${e.slice(-3)}`;return new Uint8Array(await crypto.subtle.digest(r,t))}function F(e,t,r){let n;try{n=JSON.parse(re.decode(D(e)))}catch{throw new t(r)}if(!S(n))throw new t(r);return n}async function j(e,t){if(t.kty==="RSA"&&"oth"in t&&t.oth!==void 0)throw new m('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');if(!e.kty.includes(t.kty))throw new m('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');let r=e.resolve?.({kty:t.kty,crv:t.crv})??e.subtle,n=!!(t.d||t.priv),o={...t};if(o.kty!=="AKP")delete o.alg;return delete o.use,crypto.subtle.importKey("jwk",o,r,t.ext??!n,t.key_ops??e.usages[n?1:0])}function oe(e){return{__proto__:null,...e}}function Le(e){let t=oe(e);if(t.ext!==void 0&&typeof t.ext!=="boolean")throw TypeError('"ext" (Extractable) Parameter must be a boolean');if(t.key_ops!==void 0){let r=t.key_ops,n=Array.isArray(r)?[...r]:void 0;if(!n||n.some((o)=>typeof o!=="string")||new Set(n).size!==n.length)throw TypeError('"key_ops" (Key Operations) Parameter must be an array of unique strings');t.key_ops=n}return t}var ft=(e)=>e[Symbol.toStringTag],Or=(e,t,r)=>{let{alg:n}=e;if(t.use!==void 0){let o=r==="sign"||r==="verify"?"sig":"enc";if(t.use!==o)throw TypeError(`Invalid key for this operation, its "use" must be "${o}" when present`)}if(t.alg!==void 0&&t.alg!==n)throw TypeError(`Invalid key for this operation, its "alg" must be "${n}" when present`);if(Array.isArray(t.key_ops)){let o=r==="encrypt"||r==="decrypt"?e.ops?.[r==="encrypt"?0:1]:r;if(o&&!t.key_ops.includes(o))throw TypeError(`Invalid key for this operation, its "key_ops" must include "${o}" when present`)}};function _r(e,t,r){let{alg:n,secret:o}=e,a=r==="decrypt"||r==="sign";if(o&&t instanceof Uint8Array)return[Bt,t];if(S(t)){let i=Le(t);if(typeof i.kty!=="string")throw TypeError(o?he(n,t,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"):he(n,t,"CryptoKey","KeyObject","JSON Web Key"));if(!(o?i.kty==="oct"&&typeof i.k==="string":i.kty!=="oct"&&(a?i.kty==="AKP"&&typeof i.priv==="string"||typeof i.d==="string":i.d===void 0&&i.priv===void 0)))throw TypeError(o?'JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present':`JSON Web Key for this operation must be a ${a?"private":"public"} JWK`);return Or(e,i,r),[Lt,t,i]}if(!Ne(t))throw TypeError(o?he(n,t,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"):he(n,t,"CryptoKey","KeyObject","JSON Web Key"));if(o){if(t.type!=="secret")throw TypeError(`${ft(t)} instances for symmetric algorithms must be of type "secret"`)}else{if(t.type==="secret")throw TypeError(`${ft(t)} instances for asymmetric algorithms must not be of type "secret"`);let i=a?"private":"public";if((t.type==="public"||t.type==="private")&&t.type!==i){let s=r==="sign"?"signing":r==="verify"?"verifying":`${r.slice(0,-1)}tion`;throw TypeError(`${ft(t)} instances for asymmetric algorithm ${s} must be of type "${i}"`)}}return M(t)?[Mt,t]:[$t,t]}var Bt=0,Mt=1,$t=2,Lt=3,ut,Dr={__proto__:null,prime256v1:"P-256",secp384r1:"P-384",secp521r1:"P-521"};function je(e,t,r){ut||=new WeakMap;let n=ut.get(e);if(r)if(n)n[t]=r;else ut.set(e,{[t]:r});return r??n?.[t]}var kt=async(e,t,r)=>je(e,r.alg)??je(e,r.alg,await j(r,{...t,alg:r.alg})),Ur=(e,t)=>{let r=je(e,t.alg);if(r)return r;let n=e.type==="public",o=t.usages[n?0:1],{asymmetricKeyType:a}=e,i=Dr[e.asymmetricKeyDetails?.namedCurve],s=t.resolve?.({crv:i,asymmetricKeyType:a})??t.subtle;return je(e,t.alg,e.toCryptoKey(s,n,o))};async function U(e,t,r){let n=_r(e,t,r);switch(n[0]){case Bt:case Mt:return n[1];case Lt:{let o=n[1],a=n[2];if(a.kty==="oct")return D(a.k);if(!Object.isFrozen(o)){let{key_ops:i}=o;if(Array.isArray(i))Object.freeze(i);Object.freeze(o)}return kt(o,a,e)}case $t:{let o=n[1];if(o.type==="secret")return o.export();if("toCryptoKey"in o&&typeof o.toCryptoKey==="function")return Ur(o,e);return kt(o,o.export({format:"jwk"}),e)}}}function ge(e){let t={__proto__:null};for(let r in e)t[r]={...e[r],alg:r};return t}var Rr=[["encrypt","wrapKey"],["decrypt","unwrapKey"]],Nr=[[],["deriveBits"]],Ge=[[],[]];function ze(e){return{kty:["RSA"],subtle:{name:"RSA-OAEP",hash:`SHA-${e}`},usages:Rr,ops:["wrapKey","unwrapKey"]}}function Ve(){return{kty:["EC","OKP"],subtle:{name:"ECDH"},resolve:({kty:e,crv:t,asymmetricKeyType:r})=>{if(t==="X25519"||r==="x25519")return{name:"X25519"};if(e==="OKP")throw new m('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');return{name:"ECDH",namedCurve:t}},usages:Nr,ops:[void 0,"deriveBits"]}}function ie(e,t=!1){return{kty:["oct"],secret:!0,subtle:{name:t?"AES-GCM":"AES-KW",length:e},usages:Ge,ops:t?["encrypt","decrypt"]:["wrapKey","unwrapKey"]}}function lt(){return{kty:["oct"],secret:!0,subtle:{name:"PBKDF2"},usages:Ge,ops:["deriveBits","deriveBits"]}}var mt=ge({dir:{kty:["oct"],secret:!0,subtle:{name:"AES-GCM"},usages:Ge,ops:["encrypt","decrypt"]},"RSA-OAEP":ze(1),"RSA-OAEP-256":ze(256),"RSA-OAEP-384":ze(384),"RSA-OAEP-512":ze(512),"ECDH-ES":Ve(),"ECDH-ES+A128KW":Ve(),"ECDH-ES+A192KW":Ve(),"ECDH-ES+A256KW":Ve(),A128KW:ie(128),A192KW:ie(192),A256KW:ie(256),A128GCMKW:ie(128,!0),A192GCMKW:ie(192,!0),A256GCMKW:ie(256,!0),"PBES2-HS256+A128KW":lt(),"PBES2-HS384+A192KW":lt(),"PBES2-HS512+A256KW":lt()}),Hr=["encrypt","decrypt"];function ae(e,t=!1){return{kty:["oct"],secret:!0,subtle:{name:t?"AES-CBC":"AES-GCM",length:e},usages:Ge,ops:Hr,cekBits:e,ivBits:t?128:96,cbc:t}}var kr=ge({A128GCM:ae(128),A192GCM:ae(192),A256GCM:ae(256),"A128CBC-HS256":ae(256,!0),"A192CBC-HS384":ae(384,!0),"A256CBC-HS512":ae(512,!0)});function jt(e,t){throw new m(`Invalid or unsupported "${e}" (JWE ${t}) header value`)}function R(e){return(typeof e==="string"?mt[e]:void 0)??jt("alg","Algorithm")}function ee(e){return(typeof e==="string"?kr[e]:void 0)??jt("enc","Encryption Algorithm")}function zt(e,t){if(e.algorithm.name!=="ECDH"&&e.algorithm.name!=="X25519")throw TypeError("CryptoKey does not support this operation, its algorithm.name must be ECDH or X25519");nt(e,t)}async function Gt(e,t,r){let n=R(t).subtle,o=e instanceof Uint8Array?await crypto.subtle.importKey("raw",e,"AES-KW",!0,[r]):e;return k(o,n,r),o}async function yt(e,t,r){let n=await Gt(t,e,"wrapKey"),o=await crypto.subtle.importKey("raw",r,{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.wrapKey("raw",o,n,"AES-KW"))}async function ht(e,t,r){let n=await Gt(t,e,"unwrapKey"),o=await crypto.subtle.unwrapKey("raw",r,n,"AES-KW",{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.exportKey("raw",o))}function Ft(e,t,r){k(t,R(e).subtle,r),Ie(e,t)}function Br(e,t){if(e instanceof Uint8Array)return crypto.subtle.importKey("raw",e,"PBKDF2",!1,["deriveBits"]);return k(e,R(t).subtle,"deriveBits"),e}async function Xt(e,t,r,n){if(!(e instanceof Uint8Array)||e.length<8)throw new f("PBES2 Salt Input must be 8 or more octets");if(!Number.isSafeInteger(r)||Math.sign(r)!==1)throw new f("PBES2 Count Input must be a positive integer");let o=A(b(t),Uint8Array.of(0),e),a=parseInt(t.slice(13,16),10),i={hash:`SHA-${t.slice(8,11)}`,iterations:r,name:"PBKDF2",salt:o},s=await Br(n,t);return new Uint8Array(await crypto.subtle.deriveBits(i,s,a))}function wt(e){return A(Te(e.length),e)}async function Mr(e,t,r){let n=t>>3,o=32,a=Math.ceil(n/32),i=new Uint8Array(a*32);for(let s=1;s<=a;s++){let c=await $e("sha256",A(Te(s),e,r));i.set(c,(s-1)*32)}return i.slice(0,n)}async function Yt(e,t,r,n,o=new Uint8Array,a=new Uint8Array){zt(e),zt(t,"deriveBits");let i=A(wt(b(r)),wt(o),wt(a),Te(n)),s=new Uint8Array(await crypto.subtle.deriveBits({name:e.algorithm.name,public:e},t,e.algorithm.name==="X25519"?256:Math.ceil(parseInt(e.algorithm.namedCurve.slice(-3),10)/8)<<3));return Mr(s,n,i)}function qt(e){Re(e);let t=e.algorithm.namedCurve;if(t!=="P-256"&&t!=="P-384"&&t!=="P-521"&&e.algorithm.name!=="X25519")throw new m("ECDH with the provided key is not allowed or not supported by your javascript runtime")}function Ee(e){if(e===void 0)throw new f("JWE Encrypted Key missing")}function Vt(e){if(e!==void 0)throw new f("Encountered unexpected JWE Encrypted Key")}async function Zt(e,t,r,n,o,a){let i=R(e);if(e==="dir")return Vt(n),r;switch(i.subtle.name){case"ECDH":{if(e==="ECDH-ES")Vt(n);if(!S(o.epk))throw new f('JOSE Header "epk" (Ephemeral Public Key) missing or invalid');qt(r);let s=await j(i,o.epk),c,p;if(o.apu!==void 0){if(typeof o.apu!=="string")throw new f('JOSE Header "apu" (Agreement PartyUInfo) invalid');c=W(o.apu,"apu",f)}if(o.apv!==void 0){if(typeof o.apv!=="string")throw new f('JOSE Header "apv" (Agreement PartyVInfo) invalid');p=W(o.apv,"apv",f)}let d=await Yt(s,r,e==="ECDH-ES"?t.alg:e,e==="ECDH-ES"?t.cekBits:parseInt(e.slice(-5,-2),10),c,p);if(e==="ECDH-ES")return d;return Ee(n),ht(e.slice(-6),d,n)}case"RSA-OAEP":return Ee(n),Re(r),Ft(e,r,"decrypt"),new Uint8Array(await crypto.subtle.decrypt("RSA-OAEP",r,n));case"PBKDF2":{if(Ee(n),typeof o.p2c!=="number")throw new f('JOSE Header "p2c" (PBES2 Count) missing or invalid');let s=a||1e4;if(o.p2c>s)throw new f('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');if(typeof o.p2s!=="string")throw new f('JOSE Header "p2s" (PBES2 Salt) missing or invalid');let c=W(o.p2s,"p2s",f),p=await Xt(c,e,o.p2c,r);return ht(e.slice(-6),p,n)}case"AES-KW":return Ee(n),ht(e,r,n);case"AES-GCM":{if(Ee(n),typeof o.iv!=="string")throw new f('JOSE Header "iv" (Initialization Vector) missing or invalid');if(typeof o.tag!=="string")throw new f('JOSE Header "tag" (Authentication Tag) missing or invalid');let s;s=W(o.iv,"iv",f);let c;return c=W(o.tag,"tag",f),ke(ee(e.slice(0,-2)),r,n,s,c,new Uint8Array)}}}async function Qt(e,t,r,n,o={}){let a,i,s,c=R(e);if(e==="dir")return[r,void 0,void 0];switch(c.subtle.name){case"ECDH":{qt(r);let{apu:p,apv:d}=o;if(p!==void 0)Z(p,'"apu"');if(d!==void 0)Z(d,'"apv"');let u;if(o.epk!==void 0)u=await U(c,o.epk,"decrypt");else u=(await crypto.subtle.generateKey(r.algorithm,!0,["deriveBits"])).privateKey;let l=crypto.subtle,K=u;if(!K.extractable){if(typeof l.getPublicKey!=="function")throw TypeError('CryptoKey for "epk" must be extractable');K=await l.getPublicKey(u,[])}let{x:T,y:g,crv:h,kty:v}=await l.exportKey("jwk",K),y=await Yt(r,u,e==="ECDH-ES"?t.alg:e,e==="ECDH-ES"?t.cekBits:parseInt(e.slice(-5,-2),10),p,d);if(i={epk:{x:T,crv:h,kty:v}},v==="EC")i.epk.y=g;if(p)i.apu=cr(p);if(d)i.apv=cr(d);if(e==="ECDH-ES"){s=y;break}s=n||L(t);let J=e.slice(-6);a=await yt(J,y,s);break}case"RSA-OAEP":{s=n||L(t),Re(r),Ft(e,r,"encrypt"),a=new Uint8Array(await crypto.subtle.encrypt("RSA-OAEP",r,s));break}case"PBKDF2":{s=n||L(t);let{p2c:p=2048,p2s:d=crypto.getRandomValues(new Uint8Array(16))}=o,u=await Xt(d,e,p,r);a=await yt(e.slice(-6),u,s),i={p2c:p,p2s:cr(d)};break}case"AES-KW":{s=n||L(t),a=await yt(e,r,s);break}case"AES-GCM":{s=n||L(t);let{iv:p}=o,d=await He(ee(e.slice(0,-2)),s,r,p,new Uint8Array);a=d.ciphertext,i={iv:cr(d.iv),tag:cr(d.tag)};break}}return[s,a,i]}var se={__proto__:null,b64:!0},Fe={__proto__:null};function be(e,t){if(t!==void 0&&(!Array.isArray(t)||t.some((r)=>typeof r!=="string")))throw TypeError(`"${e}" option must be an array of strings`);if(!t)return;return new Set(t)}function Xe(e,t){let{crit:r}=t??{};if(Array.isArray(r)&&new Set(r).size!==r.length)throw new e('"crit" (Critical) Header Parameter MUST NOT contain duplicate values')}function N(e,t,r,n,o){if(o.crit!==void 0&&n?.crit===void 0)throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');if(!n||n.crit===void 0)return[];if(!Array.isArray(n.crit)||n.crit.length===0||n.crit.some((i)=>typeof i!=="string"||i.length===0))throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');let a=r===void 0?t:{__proto__:null,...r,...t};for(let i of n.crit){if(!(i in a))throw new m(`Extension Header Parameter "${i}" is not recognized`);if(!Object.hasOwn(o,i)||o[i]===void 0)throw new e(`Extension Header Parameter "${i}" is missing`);if(a[i]&&(!Object.hasOwn(n,i)||n[i]===void 0))throw new e(`Extension Header Parameter "${i}" MUST be integrity protected`)}return n.crit}function ce(e,t){if(t.includes("b64")){let r=e.b64;if(typeof r!=="boolean")throw new w('The "b64" (base64url-encode payload) Header Parameter must be a boolean');return r}return!0}function pe(e,t){let r,n;try{r=JSON.stringify(t),n=JSON.parse(r)}catch(o){throw new e("JOSE Header is not valid JSON",{cause:o})}if(!S(n))throw new e("JOSE Header is not a JSON object");return[n,r]}function Ye(e,t){if(e.zip!==void 0&&e.zip!=="DEF")throw new m('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(e.zip!==void 0&&!t?.zip)throw new f('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.')}function er(e){if(typeof globalThis[e]>"u")throw new m(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${e} API.`)}async function tr(e){er("CompressionStream");let t=new CompressionStream("deflate-raw"),r=t.writable.getWriter();r.write(e).catch(()=>{}),r.close().catch(()=>{});let n=[],o=t.readable.getReader();for(;;){let{value:a,done:i}=await o.read();if(i)break;n.push(a)}return A(...n)}async function rr(e,t){er("DecompressionStream");let r=new DecompressionStream("deflate-raw"),n=r.writable.getWriter();n.write(e).catch(()=>{}),n.close().catch(()=>{});let o=[],a=0,i=r.readable.getReader();for(;;){let{value:s,done:c}=await i.read();if(c)break;if(o.push(s),a+=s.byteLength,t!==1/0&&a>t)throw new f("Decompressed plaintext exceeded the configured limit")}return A(...o)}function nr(e){return[e&&be("keyManagementAlgorithms",e.keyManagementAlgorithms),e&&be("contentEncryptionAlgorithms",e.contentEncryptionAlgorithms),e?.crit,e?.maxPBES2Count,e?.maxDecompressedLength]}async function $r(e,t,r,n,o){let[a,i,s,c,p]=r,[d,u,l,K,T]=t,{encrypted_key:g}=e;N(f,Fe,s,d,o),Ye(o,d);let{alg:h,enc:v}=o;if(typeof h!=="string"||!h)throw new f("missing JWE Algorithm (alg) in JWE Header");if(typeof v!=="string"||!v)throw new f("missing JWE Encryption Algorithm (enc) in JWE Header");if(a&&!a.has(h)||!a&&h.startsWith("PBES2"))throw new ne('"alg" (Algorithm) Header Parameter value not allowed');if(i&&!i.has(v))throw new ne('"enc" (Encryption Algorithm) Header Parameter value not allowed');let y=ee(v),J;if(g!==void 0)J=W(g,"encrypted_key",f);let P=!1;if(typeof n==="function")n=await n(d,e),P=!0;let H=R(h),O=await U(h==="dir"?y:H,n,"decrypt"),I;try{if(I=await Zt(h,y,O,J,o,c),g!==void 0&&I instanceof Uint8Array&&I.byteLength<<3!==y.cekBits)I=L(y)}catch(C){if(C instanceof TypeError||C instanceof f||C instanceof m)throw C;I=L(y)}let X=await ke(y,I,u,l,K,T);if(o.zip==="DEF"){let C=p??250000;if(C===0)throw new m('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');if(C!==1/0&&(!Number.isSafeInteger(C)||C<1))throw TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");X=await rr(X,C).catch((Y)=>{if(Y instanceof f)throw Y;throw new f("Failed to decompress plaintext",{cause:Y})})}return[X,d,O,P]}async function or(e,t,r){if(e instanceof Uint8Array)e=q.decode(e);if(typeof e!=="string")throw new f("Compact JWE must be a string or Uint8Array");let{0:n,1:o,2:a,3:i,4:s,length:c}=e.split(".");if(c!==5)throw new f("Invalid Compact JWE");let p={ciphertext:i,iv:a||void 0,protected:n,tag:s||void 0,encrypted_key:o||void 0},d=F(n,f,"JWE Protected Header is invalid"),u=b(n),l=[d,W(i,"ciphertext",f),a?W(a,"iv",f):void 0,s?W(s,"tag",f):void 0,u];return $r(p,l,t,r,d)}function ir(e,t,r){if(!Nt(e,t,r))throw new f("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint")}function Lr(e){let[,t,r,n,o,a,i,s,c]=e;if(o!==void 0)Z(o,"JWE Additional Authenticated Data");if(a!==void 0)Z(a,"JWE Content Encryption Key");if(i!==void 0)Z(i,"JWE Initialization Vector");if(t!==void 0)t=pe(f,t)[0],e[1]=t;if(r!==void 0)r=pe(f,r)[0],e[2]=r;if(n!==void 0)n=pe(f,n)[0],e[3]=n;if(s!==void 0&&!S(s))throw TypeError("JWE Key Management Parameters must be an object");ir(t,r,n);let p={...t,...r,...n};Xe(f,t),N(f,Fe,c,t,p),Ye(p,t);let{alg:d,enc:u}=p;if(typeof d!=="string"||!d)throw new f('JWE "alg" (Algorithm) Header Parameter missing or invalid');if(typeof u!=="string"||!u)throw new f('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');return[p,d,u,ee(u)]}async function jr(e,t,r){let[n,o,,a]=t,[i,s,c,p,d,u,l,K,,T]=e,g=s,h=c;if(u&&(o==="dir"||o==="ECDH-ES"))throw TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${o}`);let v=R(o),y=await U(o==="dir"?a:v,r,"encrypt"),[J,P,H]=await Qt(o,a,y,u,K);if(H){if(T)h=h?{...h,...H}:H;else g=g?{...g,...H}:H;ir(g,h,p)}let O,I;if(g)O=cr(JSON.stringify(g)),I=b(O);else O="",I=new Uint8Array;let X,C;if(d?.byteLength)C=cr(d),X=A(I,b("."),b(C));else X=I;let Y=i;if(n.zip==="DEF")Y=await tr(Y).catch((Jr)=>{throw new f("Failed to compress plaintext",{cause:Jr})});let{ciphertext:Kr,tag:Pt,iv:It}=await He(a,Y,J,l,X),G={ciphertext:cr(Kr)};if(It)G.iv=cr(It);if(Pt)G.tag=cr(Pt);if(P)G.encrypted_key=cr(P);if(C)G.aad=C;if(g)G.protected=O;if(p)G.unprotected=p;if(h)G.header=h;return G}async function ar(e,t,r){if(!e[1]&&!e[2]&&!e[3])throw new f("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");if(r!==void 0)e[8]=r?.crit,e[9]=r?Ht in r:!1;return jr(e,Lr(e),t)}async function sr(e,t,r){if(t instanceof Uint8Array)return crypto.subtle.importKey("raw",t,e.subtle,!1,[r]);if(k(t,e.subtle,r),e.minRsaBits)Ie(e.alg,t);return t}async function pr(e,t,r){let n=await sr(e,t,"sign"),o=await crypto.subtle.sign(e.signing,n,r);return new Uint8Array(o)}async function dr(e,t,r,n){let o=await sr(e,t,"verify");try{return await crypto.subtle.verify(e.signing,o,r,n)}catch{return!1}}var Se=[["verify"],["sign"]];function gt(e){let t={name:"HMAC",hash:`SHA-${e}`};return{kty:["oct"],secret:!0,subtle:t,signing:t,usages:Se}}function de(e,t){let n={name:t?"RSA-PSS":"RSASSA-PKCS1-v1_5",hash:`SHA-${e}`};return{kty:["RSA"],subtle:n,signing:t?{...n,saltLength:t}:n,usages:Se,minRsaBits:2048}}function Et(e,t){return{kty:["EC"],crv:e,subtle:{name:"ECDSA",namedCurve:e},signing:{name:"ECDSA",hash:`SHA-${t}`},usages:Se}}function fr(){let e={name:"Ed25519"};return{kty:["OKP"],crv:"Ed25519",subtle:e,signing:e,usages:Se}}function bt(e){let r={name:`ML-DSA-${e}`};return{kty:["AKP"],subtle:r,signing:r,usages:Se}}var Ae=ge({HS256:gt(256),HS384:gt(384),HS512:gt(512),RS256:de(256),RS384:de(384),RS512:de(512),PS256:de(256,32),PS384:de(384,48),PS512:de(512,64),ES256:Et("P-256",256),ES384:Et("P-384",384),ES512:Et("P-521",512),EdDSA:fr(),Ed25519:fr(),"ML-DSA-44":bt(44),"ML-DSA-65":bt(65),"ML-DSA-87":bt(87)});function qe(e){let t=typeof e==="string"?Ae[e]:void 0;if(!t)throw new m(`alg ${e} is not supported either by JOSE or your javascript runtime`);return t}function ur(e){return[e&&be("algorithms",e.algorithms),e?.crit]}function Vr(e,t=e===void 0?{}:F(e,w,"JWS Protected Header is invalid")){return t}function Gr(e,t,r){let n=ce(e,N(w,se,r[1],e,t)),o=t.alg;if(typeof o!=="string"||!o)throw new w('JWS "alg" (Algorithm) Header Parameter missing or invalid');if(r[0]&&!r[0].has(o))throw new ne('"alg" (Algorithm) Header Parameter value not allowed');return[n,o]}function Fr(e){try{return b(e)}catch{throw new w("JWS Compact Serialization payload must use only ASCII characters")}}async function Xr(e,t,r,n,o,a,i){let s=!1;if(typeof r==="function")r=await r(o,e),s=!0;let c=typeof i==="string",p=qe(a),d=A(n!==void 0?b(n):new Uint8Array,b("."),c?t[2]??=dt(i,"payload",w):i),u=W(e.signature,"signature",w),l=await U(p,r,"verify");if(!await dr(p,l,u,d))throw new at;return[c?W(i,"payload",w):i,o,c,l,s]}async function lr(e,t,r){if(e instanceof Uint8Array)e=q.decode(e);if(typeof e!=="string")throw new w("Compact JWS must be a string or Uint8Array");let{0:n,1:o,2:a,length:i}=e.split(".");if(i!==3)throw new w("Invalid Compact JWS");let s={payload:o,protected:n,signature:a},c=Vr(n),[p,d]=Gr(c,c,t),u=p?o:Fr(o);return Xr(s,t,r,n,c,d,u)}var xe=(e)=>Math.floor(e.getTime()/1000),Yr={s:1,m:60,h:3600,d:86400,w:604800,y:31557600},qr=/^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i,fe="check_failed";function St(){throw TypeError("Invalid time period format")}function Ze(e){if(typeof e!=="string")St();let t=qr.exec(e);if(!t||t[4]&&t[1])St();let r=parseFloat(t[2]),n=Math.round(r*Yr[t[3][0].toLowerCase()]);if(!Number.isFinite(n))St();if(t[1]==="-"||t[4]==="ago")return-n;return n}function ue(e,t){if(!Number.isFinite(t))throw TypeError(`Invalid ${e} input`);return t}function At(e,t){if(typeof t!=="string")throw TypeError(`"${e}" claim must be a string`)}function Zr(e){if(typeof e!=="string"&&(!Array.isArray(e)||Array.from(e).some((t)=>typeof t!=="string")))throw TypeError('"aud" claim must be a string or an array of strings')}function xt(e,t){if(typeof e==="number")return ue(t,e);if(e instanceof Date)return ue(t,xe(e));return xe(new Date)+Ze(e)}var mr=(e)=>{let t=e.toLowerCase();return e.includes("/")?t:`application/${t}`},Qr=(e,t)=>{if(typeof e==="string")return t.includes(e);if(Array.isArray(e))return t.some((r)=>e.includes(r));return!1};function Kt(e,t,r=!1){let n=e[t];if(n===void 0&&!r)return;if(typeof n!=="number")throw new _(`"${t}" claim must be a number`,e,t,"invalid");return n}function Jt(e,t){throw new _(`unexpected "${t}" claim value`,e,t,fe)}function le(e,t,r={}){let n;try{n=JSON.parse(re.decode(t))}catch{}if(!S(n))throw new E("JWT Claims Set must be a top-level JSON object");let{typ:o}=r;if(o!==void 0&&(typeof e.typ!=="string"||mr(e.typ)!==mr(o)))throw new _('unexpected "typ" JWT header value',n,"typ",fe);let{requiredClaims:a=[],issuer:i,subject:s,audience:c,maxTokenAge:p}=r,d=[...a];if(p!==void 0)d.push("iat");if(c!==void 0)d.push("aud");if(s!==void 0)d.push("sub");if(i!==void 0)d.push("iss");for(let y of new Set(d.reverse()))if(!Object.hasOwn(n,y))throw new _(`missing required "${y}" claim`,n,y,"missing");if(i!==void 0&&!(Array.isArray(i)?i:[i]).includes(n.iss))Jt(n,"iss");if(s!==void 0&&n.sub!==s)Jt(n,"sub");if(c!==void 0&&!Qr(n.aud,typeof c==="string"?[c]:c))Jt(n,"aud");let{clockTolerance:u}=r,l=0;if(typeof u==="string")l=Ze(u);else if(u!==void 0){if(typeof u!=="number")throw TypeError("Invalid clockTolerance option type");l=u}ue("clockTolerance option",l);let{currentDate:K}=r,T=ue("currentDate option",xe(K===void 0?new Date:K)),g=Kt(n,"iat",p!==void 0),h=Kt(n,"nbf");if(h!==void 0){if(h>T+l)throw new _('"nbf" claim timestamp check failed',n,"nbf",fe)}let v=Kt(n,"exp");if(v!==void 0){if(v<=T-l)throw new Qi('"exp" claim timestamp check failed',n,"exp",fe)}if(p!==void 0){let y=T-g,J=ue("maxTokenAge option",typeof p==="number"?p:Ze(p));if(y-l>J)throw new Qi('"iat" claim timestamp check failed (too far in the past)',n,"iat",fe);if(y<-l)throw new _('"iat" claim timestamp check failed (it should be in the past)',n,"iat",fe)}return n}var yr;function z(e){return yr.get(e)}function me(e){let t=z(e);for(let r of["iat","nbf","exp"]){let n=t[r];if(typeof n==="number"&&!Number.isFinite(n))throw TypeError(`"${r}" claim must be a finite number`)}return ye.encode(JSON.stringify(t))}function Qe(e,t){return z(e)[t]}class te{constructor(e={}){if(!S(e))throw TypeError("JWT Claims Set MUST be an object");(yr||=new WeakMap).set(this,structuredClone(e))}setIssuer(e){return At("iss",e),z(this).iss=e,this}setSubject(e){return At("sub",e),z(this).sub=e,this}setAudience(e){return Zr(e),z(this).aud=e,this}setJti(e){return At("jti",e),z(this).jti=e,this}setNotBefore(e){return z(this).nbf=xt(e,"setNotBefore"),this}setExpirationTime(e){return z(this).exp=xt(e,"setExpirationTime"),this}setIssuedAt(e){let t=z(this);if(e===void 0)t.iat=xe(new Date);else if(typeof e==="string")t.iat=ue("setIssuedAt",xe(new Date)+Ze(e));else t.iat=xt(e,"setIssuedAt");return this}}async function Pn(e,t,r){let n=await lr(e,ur(r),t);if(!n[2])throw new E("JWTs MUST NOT use unencoded payload");let a={payload:le(n[1],n[0],r),protectedHeader:n[1]};if(typeof t==="function")return{...a,key:n[3]};return a}async function ic(e,t,r){let n=await or(e,nr(r),t),o=n[1],a=le(o,n[0],r);for(let s of["iss","sub","aud"])if(o[s]!==void 0&&(s==="aud"?JSON.stringify(o.aud)!==JSON.stringify(a.aud):o[s]!==a[s]))throw new _(`replicated "${s}" claim header parameter mismatch`,a,s,"mismatch");let i={payload:a,protectedHeader:o};if(typeof t==="function")return{...i,key:n[2]};return i}function en(e){if(e===void 0)return[void 0,""];let t=pe(w,e);return[t[0],cr(t[1])]}function tn(e,t,r){return Xe(w,e),ce(e,N(w,se,r,e,t))}function rn(e){let t=e.alg;if(typeof t!=="string"||!t)throw new w('JWS "alg" (Algorithm) Header Parameter missing or invalid');return qe(t)}async function nn(e,t,r,n){let o=A(b(e),b("."),t),a=await U(r,n,"sign");return cr(await pr(r,a,o))}async function hr(e,t,r,n,o){let[a,i]=en(t);if(!a)throw new w("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!tn(a,a,r))o();let c=rn(a),p=cr(e),d=await nn(i,b(p),c,n);return`${i}.${p}.${d}`}var on=te;class lc extends on{#e;setProtectedHeader(e){return Q(this.#e,"setProtectedHeader"),this.#e=e,this}async sign(e,t){return hr(me(this),this.#e,t?.crit,e,()=>{throw new E("JWTs MUST NOT use unencoded payload")})}}var an=te;class cc extends an{#e;#r;#n;#t;#o;#i;#a;setProtectedHeader(e){return Q(this.#t,"setProtectedHeader"),this.#t=e,this}setKeyManagementParameters(e){return Q(this.#n,"setKeyManagementParameters"),this.#n=e,this}setContentEncryptionKey(e){return Q(this.#e,"setContentEncryptionKey"),this.#e=e,this}setInitializationVector(e){return Q(this.#r,"setInitializationVector"),this.#r=e,this}replicateIssuerAsHeader(){return this.#o=!0,this}replicateSubjectAsHeader(){return this.#i=!0,this}replicateAudienceAsHeader(){return this.#a=!0,this}async encrypt(e,t){let r=me(this);if(this.#t&&(this.#o||this.#i||this.#a))this.#t={...this.#t,iss:this.#o?Qe(this,"iss"):void 0,sub:this.#i?Qe(this,"sub"):void 0,aud:this.#a?Qe(this,"aud"):void 0};let n=await ar([r,this.#t,void 0,void 0,void 0,this.#e,this.#r,this.#n,void 0,!1],e,t);return[n.protected,n.encrypted_key,n.iv,n.ciphertext,n.tag].join(".")}}var Wt='"alg" (Algorithm)';function Ct(e='JWK "alg" (Algorithm) Parameter'){throw new m(`Invalid or unsupported ${e} value`)}function Ke(e,t){return(typeof e==="string"?Ae[e]??mt[e]:void 0)??Ct(t)}function et(e){if(e!==void 0&&typeof e!=="boolean")throw TypeError('"extractable" option must be a boolean');return e}var Je=(e,t)=>{if(e.byteLength!==t.length)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0},sn=(e)=>({data:e,pos:0}),vt=(e)=>{let t=e.data[e.pos++];if(t===void 0)throw Error("Unexpected end of ASN.1 input");return t},We=(e)=>{let t=vt(e);if(t&128){let r=t&127,n=0;for(let o=0;o<r;o++)n=n<<8|vt(e);return n}return t};var Ce=(e,t,r)=>{if(vt(e)!==t)throw Error(r)},wr=(e,t)=>{if(t<0||e.pos+t>e.data.length)throw Error("Unexpected end of ASN.1 input");let r=e.data.subarray(e.pos,e.pos+t);return e.pos+=t,r},cn=(e)=>{Ce(e,6,"Expected algorithm OID");let t=We(e);return wr(e,t)};function pn(e,t){if(Ce(e,48,`Invalid ${t==="spki"?"SPKI":"PKCS#8"} structure`),We(e),t==="pkcs8"){Ce(e,2,"Expected version field");let r=We(e);e.pos+=r}Ce(e,48,"Expected algorithm identifier"),We(e)}var dn=(e)=>{let t=cn(e);if(Je(t,[43,101,110]))return"X25519";if(!Je(t,[42,134,72,206,61,2,1]))throw Error("Unsupported key algorithm");Ce(e,6,"Expected curve OID");let r=We(e),n=wr(e,r);if(Je(n,[42,134,72,206,61,3,1,7]))return"P-256";if(Je(n,[43,129,4,0,34]))return"P-384";if(Je(n,[43,129,4,0,35]))return"P-521";throw Error("Unsupported named curve")},fn=async(e,t,r,n)=>{let o=et(n?.extractable),a=Ke(r,Wt);if(a.secret)Ct(Wt);let i=e==="spki",s;if(a.resolve)try{let c=sn(t);pn(c,e),s=a.resolve({crv:dn(c)})}catch{throw new m("Invalid or unsupported key format")}else s=a.subtle;return crypto.subtle.importKey(e,t,s,o??i,a.usages[i?0:1])},un=(e,t)=>Be(e.replace(t,"")),gr=(e,t,r)=>{let n=un(e,/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);return fn("pkcs8",n,t,r)};function ln(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}async function mn(e){if(st(e))if(e.type==="secret")e=e.export();else return e.export({format:"jwk"});if(e instanceof Uint8Array)return{kty:"oct",k:cr(e)};if(!M(e))throw TypeError(B(e,"CryptoKey","KeyObject","Uint8Array"));if(!e.extractable)throw TypeError("non-extractable CryptoKey cannot be exported as a JWK");let{ext:t,key_ops:r,alg:n,use:o,...a}=ln(await crypto.subtle.exportKey("jwk",e));if(a.kty==="AKP")a.alg=n;return a}function Er(e){return mn(e)}var V=(e,t)=>{if(typeof e!=="string"||!e)throw new De(`${t} missing or invalid`)};async function uc(e,t){let r;if(S(e)){if(r=oe(e),typeof r.kty!=="string")throw TypeError(B(e,"CryptoKey","KeyObject","JSON Web Key"))}else if(Ne(e))r=oe(await Er(e));else throw TypeError(B(e,"CryptoKey","KeyObject","JSON Web Key"));if(t??="sha256",t!=="sha256"&&t!=="sha384"&&t!=="sha512")throw TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');let n;switch(r.kty){case"AKP":V(r.alg,'"alg" (Algorithm) Parameter'),V(r.pub,'"pub" (Public key) Parameter'),n={alg:r.alg,kty:r.kty,pub:r.pub};break;case"EC":V(r.crv,'"crv" (Curve) Parameter'),V(r.x,'"x" (X Coordinate) Parameter'),V(r.y,'"y" (Y Coordinate) Parameter'),n={crv:r.crv,kty:r.kty,x:r.x,y:r.y};break;case"OKP":V(r.crv,'"crv" (Subtype of Key Pair) Parameter'),V(r.x,'"x" (Public Key) Parameter'),n={crv:r.crv,kty:r.kty,x:r.x};break;case"RSA":V(r.e,'"e" (Exponent) Parameter'),V(r.n,'"n" (Modulus) Parameter'),n={e:r.e,kty:r.kty,n:r.n};break;case"oct":if(typeof r.k!=="string")throw new De('"k" (Key Value) Parameter missing or invalid');n={k:r.k,kty:r.kty};break;default:throw new m('"kty" (Key Type) Parameter missing or unsupported')}let o=b(JSON.stringify(n));return cr(await $e(t,o))}function yn(e,t,r,n){let{kty:o,key_ops:a,ext:i,kid:s,alg:c,use:p,crv:d}=oe(e),u=Array.isArray(a)?[...a]:a;return(i===void 0||typeof i==="boolean")&&(u===void 0||Array.isArray(u)&&u.every((l,K)=>typeof l==="string"&&u.indexOf(l)===K)&&u.includes("verify"))&&t.kty.includes(o)&&(n===void 0||typeof n==="string"&&n===s)&&(c===void 0?o!=="AKP":r===c)&&(p===void 0||p==="sig")&&(!t.crv||d===t.crv)}async function br(e,t,r){let n=e.get(t)||e.set(t,{}).get(t),{alg:o}=r;if(n[o]===void 0){let a=await j(r,{...t,alg:o,ext:!0});if(a.type!=="public")throw new Ue("JSON Web Key Set members must be public keys");n[o]=a}return n[o]}function Au(e){let t;try{t=structuredClone(e)}catch{}if(!Me(t))throw new Ue("JSON Web Key Set malformed");let r=new WeakMap;return Object.defineProperty(async(o,a)=>{let{alg:i,kid:s}={...o,...a?.header},c=typeof i==="string"?Ae[i]:void 0;if(!c||c.secret)throw new m('Unsupported "alg" value for a JSON Web Key Set');let p=t.keys.filter((l)=>yn(l,c,i,s)),{0:d,length:u}=p;if(!u)throw new we;if(u!==1){let l=new ot;throw l[Symbol.asyncIterator]=async function*(){for(let K of p)try{yield await br(r,K,c)}catch{}},l}return br(r,d,c)},"jwks",{value:()=>structuredClone(t)})}function hn(){return typeof WebSocketPair<"u"||typeof navigator<"u"&&navigator.userAgent==="Cloudflare-Workers"||typeof EdgeRuntime<"u"&&EdgeRuntime==="vercel"}var Tt;if(typeof navigator>"u"||!navigator.userAgent?.startsWith?.("Mozilla/5.0 "))Tt="jose/v6.2.10";var Ar=Symbol();async function wn(e,t,r,n=fetch){let o=await n(e,{method:"GET",signal:r,redirect:"manual",headers:t}).catch((a)=>{if(a.name==="TimeoutError")throw new it;throw a});if(o.status!==200)throw new x("Expected 200 OK from the JSON Web Key Set HTTP response");try{return await o.json()}catch{throw new x("Failed to parse the JSON Web Key Set HTTP response as JSON")}}var xr=Symbol();function ve(e,t){return Number.isFinite(e)&&Date.now()<e+t}function Sr(e,t,r){if(Number.isNaN(e))throw TypeError(`"${r}" option must not be NaN`);return typeof e==="number"?e:t}function _u(e,t){if(!(e instanceof URL))throw TypeError("url must be an instance of URL");let r=new URL(e.href).href,n=t??{},o=n.timeoutDuration;if(typeof o==="number"&&(!Number.isInteger(o)||o<0))throw TypeError('"timeoutDuration" option must be a non-negative integer');let a=typeof o==="number"?o:5000,i=Sr(n.cooldownDuration,30000,"cooldownDuration"),s=Sr(n.cacheMaxAge,600000,"cacheMaxAge"),c=new Headers(n.headers);if(Tt&&!c.has("User-Agent"))c.set("User-Agent",Tt);if(!c.has("accept"))c.set("accept","application/json, application/jwk-set+json");let p=n[Ar],d=n[xr],u,l,K=0,T=0,g;if(d&&typeof d==="object"){let{uat:y,jwks:J}=d;if(ve(y,s)&&Me(J))u=y,g=Au(J)}let h=async()=>{if(l&&hn())l=void 0;if(!l){let y=++K,J=l=wn(r,c,AbortSignal.timeout(a),p).then((P)=>{let H=Au(P);if(y<=T)return;g=H;let O=Date.now();if(d)d.uat=O,d.jwks=P;u=O,T=y}).finally(()=>{if(l===J)l=void 0})}await l};return Object.defineProperties(async(y,J)=>{if(!g||!ve(u,s))await h();try{return await g(y,J)}catch(P){if(P instanceof we&&!ve(u,i))return await h(),g(y,J);throw P}},{coolingDown:{get:()=>ve(u,i),enumerable:!0},fresh:{get:()=>ve(u,s),enumerable:!0},reload:{value:h,enumerable:!0},reloading:{get:()=>!!l,enumerable:!0},jwks:{value:()=>g?.jwks(),enumerable:!0}})}var gn=te;class am extends gn{encode(){let e=cr(JSON.stringify({alg:"none"})),t=cr(me(this));return`${e}.${t}.`}static decode(e,t){if(typeof e!=="string")throw new E("Unsecured JWT must be a string");let{0:r,1:n,2:o,length:a}=e.split(".");if(a!==3||o!=="")throw new E("Invalid Unsecured JWT");let i,s;try{i=F(r,w,"JWS Protected Header is invalid");let p=N(w,se,void 0,i,i);s=ce(i,p)}catch(p){if(!(p instanceof w))throw p;throw new E("Invalid Unsecured JWT",{cause:p})}if(i.alg!=="none")throw new E("Invalid Unsecured JWT");if(!s)throw new E("JWTs MUST NOT use unencoded payload");return{payload:le(i,W(n,"payload",E),t),header:i}}}async function mA(e,t,r){if(typeof e!=="string"||e.indexOf("-----BEGIN PRIVATE KEY-----")!==0)throw TypeError('"pkcs8" must be PKCS#8 formatted string');return gr(e,t,r)}async function xs(e,t,r){if(!S(e))throw TypeError("JWK must be an object");let n=Le(e),o=et(r?.extractable),{alg:a}=n;t??=a;let i=o??n.ext;if(n.kty!=="oct"&&!t)throw TypeError('"alg" argument is required when "jwk.alg" is not present');switch(n.kty){case"oct":if(typeof n.k!=="string")throw TypeError('missing "k" (Key Value) Parameter value');return D(n.k);case"AKP":{if(typeof a!=="string"||!a)throw TypeError('missing "alg" (Algorithm) Parameter value');if(t!==a)throw TypeError("JWK alg and alg option value mismatch");return j(Ke(t),{...n,ext:i})}case"RSA":case"EC":case"OKP":return j(Ke(t),{...n,alg:t,ext:i});default:throw new m('Unsupported "kty" (Key Type) Parameter value')}}function zo(e){let t;if(typeof e==="string"){let n=e.split(".");if(n.length===3||n.length===5)[t]=n}else if(typeof e==="object"&&e)if("protected"in e)t=e.protected;else throw TypeError("Token does not contain a Protected Header");let r="Invalid Token or Protected Header formatting";if(typeof t!=="string"||!t)throw TypeError(r);return F(t,TypeError,r)}function zr(e){if(typeof e!=="string")throw new E("JWTs must use Compact JWS serialization, JWT must be a string");let{1:t,length:r}=e.split(".");if(r===5)throw new E("Only JWTs using Compact JWS serialization can be decoded");if(r!==3)throw new E("Invalid JWT");if(!t)throw new E("JWTs must contain a payload");let n;try{n=D(t)}catch{throw new E("Failed to base64url decode the payload")}let o;try{o=JSON.parse(re.decode(n))}catch{throw new E("Failed to parse the decoded payload as JSON")}if(!S(o))throw new E("Invalid JWT Claims Set");return o}export{Qi,cr,tf,Pn,ic,lc,cc,uc,Au,_u,am,mA,xs,zo,zr};