@stacksjs/ts-cloud 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/dist/aws/index.js +1 -1
  2. package/dist/bin/chunk-0djsffn6.js +1 -0
  3. package/dist/bin/chunk-0t3sev1j.js +1 -0
  4. package/dist/{chunk-cp54a0qn.js → bin/chunk-0y89hs67.js} +1 -1
  5. package/dist/bin/{chunk-6eat8ezk.js → chunk-21gggxvf.js} +2 -2
  6. package/dist/bin/{chunk-wewcjam5.js → chunk-26cj89s6.js} +1 -1
  7. package/dist/bin/{chunk-eh40fpvj.js → chunk-35xstvnq.js} +1 -1
  8. package/dist/bin/{chunk-d6zzgvtn.js → chunk-4a85nk2q.js} +2 -2
  9. package/dist/bin/{chunk-anm3ae6z.js → chunk-4a97kbk1.js} +2 -2
  10. package/dist/bin/{chunk-svyd4v6c.js → chunk-4kbhbfq8.js} +2 -2
  11. package/dist/bin/{chunk-35ttwn26.js → chunk-4vdv41nh.js} +1 -1
  12. package/dist/bin/{chunk-dvkj4k6h.js → chunk-67jsyn0g.js} +1 -1
  13. package/dist/bin/chunk-6tct7e89.js +1 -0
  14. package/dist/bin/{chunk-jnx4jgw8.js → chunk-6vjrts39.js} +1 -1
  15. package/dist/bin/chunk-7v5ff3vc.js +1 -0
  16. package/dist/bin/chunk-80nra92y.js +1 -0
  17. package/dist/bin/{chunk-sbejksrh.js → chunk-9mydnqr6.js} +1 -1
  18. package/dist/bin/{chunk-m3nqw76h.js → chunk-9rsn48qg.js} +1 -1
  19. package/dist/bin/{chunk-q46zr2tv.js → chunk-a2t1e5yb.js} +1 -1
  20. package/dist/bin/chunk-akbfefwq.js +1 -0
  21. package/dist/bin/chunk-b704nznp.js +1 -0
  22. package/dist/bin/{chunk-8rwhsp5b.js → chunk-c1j9v7ee.js} +1 -1
  23. package/dist/bin/chunk-cjz36ths.js +1 -0
  24. package/dist/bin/{chunk-nb0yjkv5.js → chunk-cxd5cevb.js} +1 -1
  25. package/dist/bin/{chunk-b35989e3.js → chunk-dbv8w56s.js} +2 -2
  26. package/dist/bin/chunk-dxchg0g1.js +1 -0
  27. package/dist/bin/{chunk-axvr7dwa.js → chunk-e1bfd1yv.js} +2 -2
  28. package/dist/bin/{chunk-g90nqfgv.js → chunk-fpcghdr3.js} +47 -47
  29. package/dist/bin/{chunk-dj9a67c3.js → chunk-ftse39wf.js} +2 -2
  30. package/dist/bin/chunk-g0ewbkbq.js +1 -0
  31. package/dist/bin/{chunk-6zjy949y.js → chunk-gskbezam.js} +1 -1
  32. package/dist/bin/chunk-gvs85t2j.js +1 -0
  33. package/dist/bin/{chunk-pkgkfe6s.js → chunk-hej39dwr.js} +2 -2
  34. package/dist/bin/{chunk-b0hj9m5e.js → chunk-jce28gnz.js} +1 -1
  35. package/dist/bin/{chunk-80ar3aty.js → chunk-kbtrr0c3.js} +1 -1
  36. package/dist/bin/chunk-khrye4x9.js +1 -0
  37. package/dist/bin/{chunk-b2ymh8k0.js → chunk-ks4ewy1s.js} +1 -1
  38. package/dist/bin/{chunk-kybdb0ws.js → chunk-mbnwt3r5.js} +2 -2
  39. package/dist/{chunk-xtwjt370.js → bin/chunk-md2k3n21.js} +1 -1
  40. package/dist/bin/chunk-memfxrcn.js +1 -0
  41. package/dist/{chunk-cd0zpxhf.js → bin/chunk-mwgxyc0z.js} +1 -1
  42. package/dist/bin/{chunk-9px3rg4a.js → chunk-neampxq1.js} +2 -2
  43. package/dist/bin/{chunk-da8zpf82.js → chunk-nkpf91d3.js} +1 -1
  44. package/dist/bin/{chunk-pjpa4x52.js → chunk-nmkm1f68.js} +1 -1
  45. package/dist/bin/{chunk-7wzdaqh6.js → chunk-nyc2jxd8.js} +1 -1
  46. package/dist/bin/chunk-pqr8jqnd.js +1 -0
  47. package/dist/bin/{chunk-ckxpgwxw.js → chunk-q182t9ba.js} +2 -2
  48. package/dist/bin/{chunk-pnz5hk8n.js → chunk-r6x7beew.js} +2 -2
  49. package/dist/bin/chunk-rfqk5xym.js +1 -0
  50. package/dist/bin/{chunk-jnsbzqzz.js → chunk-ww770qpn.js} +2 -2
  51. package/dist/bin/chunk-wy20ztb6.js +1 -0
  52. package/dist/bin/{chunk-y9f8649w.js → chunk-wzepfqf4.js} +5 -5
  53. package/dist/bin/chunk-xcqmwphz.js +1 -0
  54. package/dist/bin/{chunk-jt1tndm2.js → chunk-xev7qr2h.js} +1 -1
  55. package/dist/bin/{chunk-1v6bt68w.js → chunk-y3rm37z1.js} +3 -3
  56. package/dist/bin/{chunk-mn6j22zn.js → chunk-zejwh9cy.js} +2 -2
  57. package/dist/bin/{chunk-ezftw2q4.js → chunk-zwwnt4x1.js} +1 -1
  58. package/dist/bin/cli.js +93 -90
  59. package/dist/bin/dashboard-server.js +1 -1
  60. package/dist/{chunk-06jk7ba9.js → chunk-0hj552t7.js} +2 -2
  61. package/dist/{chunk-0e16qt6k.js → chunk-1ypkh8g6.js} +1 -1
  62. package/dist/{chunk-9a22225r.js → chunk-2m09t0c0.js} +2 -2
  63. package/dist/chunk-7fkyfh65.js +1 -0
  64. package/dist/{chunk-hhdx5k96.js → chunk-7xpxzbkr.js} +49 -49
  65. package/dist/{chunk-e1666vjv.js → chunk-8e0az001.js} +2 -2
  66. package/dist/{bin/chunk-936vp7dx.js → chunk-b10cbk8z.js} +1 -1
  67. package/dist/{bin/chunk-ey9fagrr.js → chunk-gk58959n.js} +1 -1
  68. package/dist/{chunk-88z37ey4.js → chunk-h1rc94df.js} +1 -1
  69. package/dist/{chunk-zmxffmmq.js → chunk-hbhxk5a0.js} +2 -2
  70. package/dist/chunk-hz7k9ymh.js +1 -0
  71. package/dist/chunk-kj7gzdj6.js +1 -0
  72. package/dist/{chunk-dckz9xve.js → chunk-ky5c6t5y.js} +1 -1
  73. package/dist/chunk-mch30cyc.js +1 -0
  74. package/dist/chunk-n04a3bgf.js +1 -0
  75. package/dist/{chunk-13hxhzaz.js → chunk-nnqxmh7f.js} +1 -1
  76. package/dist/{chunk-snak8s7m.js → chunk-p6vszgc2.js} +2 -2
  77. package/dist/{chunk-d67xbk4v.js → chunk-q2njk4hx.js} +1 -1
  78. package/dist/{chunk-xd6w0c11.js → chunk-qjk1v1gs.js} +1 -1
  79. package/dist/{chunk-2p89vt3b.js → chunk-qtp90j44.js} +1 -1
  80. package/dist/{bin/chunk-c2b6nk0q.js → chunk-r5natbed.js} +1 -1
  81. package/dist/{chunk-qh9ep11z.js → chunk-rcxq9aaa.js} +5 -5
  82. package/dist/{chunk-kv2ztkp4.js → chunk-s3rpd72x.js} +2 -2
  83. package/dist/{chunk-77t2ctwn.js → chunk-spx89gaw.js} +1 -1
  84. package/dist/{chunk-8c4715hz.js → chunk-t0kh8haz.js} +1 -1
  85. package/dist/{chunk-y26yh5zp.js → chunk-vz95qy3n.js} +1 -1
  86. package/dist/deploy/index.js +1 -1
  87. package/dist/dns/index.js +1 -1
  88. package/dist/drivers/index.js +1 -1
  89. package/dist/drivers/shared/app-updates.d.ts +36 -0
  90. package/dist/index.js +24 -21
  91. package/dist/protection/index.js +1 -1
  92. package/dist/push/index.js +1 -1
  93. package/dist/spend/index.js +1 -1
  94. package/dist/ui/404.html +1 -1
  95. package/dist/ui/accept-invitation.html +1 -1
  96. package/dist/ui/access-denied.html +1 -1
  97. package/dist/ui/account/automation.html +6 -6
  98. package/dist/ui/account/security.html +2 -2
  99. package/dist/ui/applications/compose.html +6 -6
  100. package/dist/ui/applications/new.html +2 -2
  101. package/dist/ui/data/backups.html +6 -6
  102. package/dist/ui/data/services.html +6 -6
  103. package/dist/ui/data/volumes.html +6 -6
  104. package/dist/ui/index.html +6 -6
  105. package/dist/ui/infrastructure/topology.html +5 -5
  106. package/dist/ui/integrations.html +2 -2
  107. package/dist/ui/operations/alerts.html +6 -6
  108. package/dist/ui/operations/configuration.html +6 -6
  109. package/dist/ui/operations/jobs.html +6 -6
  110. package/dist/ui/operations/maintenance.html +6 -6
  111. package/dist/ui/operations/observability.html +6 -6
  112. package/dist/ui/operations/previews.html +6 -6
  113. package/dist/ui/operations/queue.html +5 -5
  114. package/dist/ui/operations/regions.html +6 -6
  115. package/dist/ui/operations/releases.html +5 -5
  116. package/dist/ui/operations/spend.html +6 -6
  117. package/dist/ui/operations/workloads.html +6 -6
  118. package/dist/ui/security.html +2 -2
  119. package/dist/ui/server/actions.html +6 -6
  120. package/dist/ui/server/activity.html +1 -1
  121. package/dist/ui/server/capacity.html +6 -6
  122. package/dist/ui/server/database.html +6 -6
  123. package/dist/ui/server/deployments.html +5 -5
  124. package/dist/ui/server/diagnostics.html +2 -2
  125. package/dist/ui/server/firewall.html +6 -6
  126. package/dist/ui/server/fleet.html +6 -6
  127. package/dist/ui/server/logs.html +6 -6
  128. package/dist/ui/server/metrics.html +5 -5
  129. package/dist/ui/server/security.html +2 -2
  130. package/dist/ui/server/services.html +2 -2
  131. package/dist/ui/server/sites.html +6 -6
  132. package/dist/ui/server/ssh-keys.html +6 -6
  133. package/dist/ui/server/team.html +6 -6
  134. package/dist/ui/server/terminal.html +2 -2
  135. package/dist/ui/serverless/alarms.html +6 -6
  136. package/dist/ui/serverless/assets.html +2 -2
  137. package/dist/ui/serverless/cost.html +2 -2
  138. package/dist/ui/serverless/data.html +6 -6
  139. package/dist/ui/serverless/deployments.html +2 -2
  140. package/dist/ui/serverless/firewall.html +1 -1
  141. package/dist/ui/serverless/functions.html +6 -6
  142. package/dist/ui/serverless/logs.html +6 -6
  143. package/dist/ui/serverless/metrics.html +2 -2
  144. package/dist/ui/serverless/queues.html +6 -6
  145. package/dist/ui/serverless/secrets.html +6 -6
  146. package/dist/ui/serverless/traces.html +6 -6
  147. package/dist/ui/serverless.html +6 -6
  148. package/package.json +3 -3
  149. package/dist/bin/chunk-08c0pzkb.js +0 -1
  150. package/dist/bin/chunk-12210qvj.js +0 -1
  151. package/dist/bin/chunk-3r3be05z.js +0 -1
  152. package/dist/bin/chunk-5rv31chh.js +0 -1
  153. package/dist/bin/chunk-6gktf2m2.js +0 -1
  154. package/dist/bin/chunk-ddmjjstg.js +0 -1
  155. package/dist/bin/chunk-dhhz4zyj.js +0 -1
  156. package/dist/bin/chunk-ds1z880f.js +0 -1
  157. package/dist/bin/chunk-g6a4n3rh.js +0 -1
  158. package/dist/bin/chunk-gs40j75w.js +0 -1
  159. package/dist/bin/chunk-jjjts1vt.js +0 -1
  160. package/dist/bin/chunk-qtdngvs8.js +0 -1
  161. package/dist/bin/chunk-tna7ay8d.js +0 -1
  162. package/dist/bin/chunk-tp4c2mv1.js +0 -1
  163. package/dist/bin/chunk-w5d6tr2x.js +0 -1
  164. package/dist/bin/chunk-xv4bscrm.js +0 -1
  165. package/dist/bin/chunk-y9eyc5pw.js +0 -1
  166. package/dist/chunk-as6by62d.js +0 -1
  167. package/dist/chunk-nrz6zypg.js +0 -1
  168. package/dist/chunk-q816js1y.js +0 -1
  169. package/dist/chunk-rg720cqg.js +0 -1
  170. package/dist/chunk-vq737g82.js +0 -1
@@ -1,2 +1,2 @@
1
- import{Tf as y}from"./chunk-xd6w0c11.js";import{Xh as M}from"./chunk-cp54a0qn.js";var I=new Set(["A","AAAA","CNAME"]);function E(t,e=""){return t===408||t===409||t===425||t===429||t>=500||/rate limit|temporar|timed? ?out|try again/i.test(e)}async function N(t,e){let r=e?.headers.get("retry-after"),n=r===null||r===void 0?void 0:Number(r)*1000,s=Number.isFinite(n)?Math.max(0,n):Math.min(1000*2**(t-1),30000);await new Promise((o)=>setTimeout(o,s))}class h{name="porkbun";apiKey;secretKey;requestTimeoutMs;constructor(t,e,r=15000){this.apiKey=t,this.secretKey=e,this.requestTimeoutMs=r}async request(t,e={}){let r;for(let n=1;n<=8;n+=1){let s,o=new AbortController,i=setTimeout(()=>{o.abort(Error(`Porkbun API request timed out after ${this.requestTimeoutMs}ms`))},this.requestTimeoutMs);try{s=await fetch(`https://api.porkbun.com/api/json/v3${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apikey:this.apiKey,secretapikey:this.secretKey,...e}),signal:o.signal})}catch(c){if(r=c,n===8)throw c;await N(n);continue}finally{clearTimeout(i)}if(!s.ok){if(r=Error(`Porkbun API error: ${s.status} ${s.statusText}`),!E(s.status)||n===8)throw r;await N(n,s);continue}let a=await s.json();if(a.status==="ERROR"){if(r=Error(`Porkbun API error: ${a.message||"Unknown error"}`),!E(0,a.message)||n===8)throw r;await N(n,s);continue}return a}throw r}getSubdomain(t,e){let r=t.replace(/\.$/,""),n=e.replace(/\.$/,"");if(r===n)return"";if(r.endsWith(`.${n}`))return r.slice(0,-(n.length+1));return r}getRootDomain(t){let e=t.replace(/\.$/,"").split(".");if(e.length>=2)return e.slice(-2).join(".");return t}static ADDRESS_TYPES=new Set(["A","AAAA"]);async clearConflictingAliases(t,e){if(!h.ADDRESS_TYPES.has(e.type))return[];let r=this.getRootDomain(t),n=this.getSubdomain(e.name,r),s=await this.listRecords(t);if(!s.success)return[`could not list records to clear ALIAS/CNAME conflicts: ${s.message??"unknown provider error"}`];let o=[];for(let i of s.records){if(i.type!=="ALIAS"&&i.type!=="CNAME")continue;if(this.getSubdomain(i.name,r)!==n)continue;let a=await this.deleteRecord(t,i);if(!a.success)o.push(`could not remove conflicting ${i.type} on ${i.name}: ${a.message??"unknown provider error"}`)}return o}async addressRecordExists(t,e){let r=this.getRootDomain(t),n=this.getSubdomain(e.name,r),s=await this.listRecords(t);if(!s.success)return!0;return s.records.some((o)=>o.type===e.type&&this.getSubdomain(o.name,r)===n&&o.content===e.content)}async createRecord(t,e){try{let r=this.getRootDomain(t),n=this.getSubdomain(e.name,r),s={type:e.type,content:e.content,ttl:String(e.ttl||600)};if(n)s.name=n;if((e.type==="MX"||e.type==="SRV")&&e.priority!==void 0)s.prio=String(e.priority);if(e.type==="SRV"&&e.weight!==void 0&&e.port!==void 0)s.content=`${e.weight} ${e.port} ${e.content}`;let o=await this.clearConflictingAliases(t,e),i=await this.request(`/dns/create/${r}`,s);if(h.ADDRESS_TYPES.has(e.type)&&!await this.addressRecordExists(t,e))return{success:!1,message:`Porkbun reported success but no ${e.type} record for ${e.name} exists${o.length>0?` (${o.join("; ")})`:""}. A conflicting ALIAS/CNAME on the same name silently voids the write.`};return{success:!0,id:i.id?.toString(),message:"Record created successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async upsertRecord(t,e){try{let r=this.getRootDomain(t),n=this.getSubdomain(e.name,r),s=await this.listRecords(t,e.type);if(s.success){let o=s.records.find((i)=>this.getSubdomain(i.name,r)===n&&i.type===e.type);if(o?.id){let i={type:e.type,content:e.content,ttl:String(e.ttl||600)};if(n)i.name=n;if((e.type==="MX"||e.type==="SRV")&&e.priority!==void 0)i.prio=String(e.priority);if(e.type==="SRV"&&e.weight!==void 0&&e.port!==void 0)i.content=`${e.weight} ${e.port} ${e.content}`;return await this.request(`/dns/edit/${r}/${o.id}`,i),{success:!0,id:o.id,message:"Record updated successfully"}}}return this.createRecord(t,e)}catch(r){return this.createRecord(t,e)}}async deleteRecord(t,e){try{let r=this.getRootDomain(t);if("id"in e&&e.id)return await this.request(`/dns/delete/${r}/${e.id}`),{success:!0,message:"Record deleted successfully"};let n=this.getSubdomain(e.name,r),s=await this.listRecords(t);if(!s.success)return{success:!1,message:"Failed to list records"};let o=s.records.find((i)=>this.getSubdomain(i.name,r)===n&&i.type===e.type&&i.content===e.content);if(!o?.id)return{success:!1,message:"Record not found"};return await this.request(`/dns/delete/${r}/${o.id}`),{success:!0,message:"Record deleted successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async listRecords(t,e){try{let r=this.getRootDomain(t),n=`/dns/retrieve/${r}`;if(e)n=`/dns/retrieveByNameType/${r}/${e}`;return{success:!0,records:((await this.request(n)).records||[]).map((i)=>({id:i.id,name:i.name||r,type:i.type,content:i.content,ttl:Number.parseInt(i.ttl,10),priority:i.prio?Number.parseInt(i.prio,10):void 0}))}}catch(r){return{success:!1,records:[],message:r instanceof Error?r.message:"Unknown error"}}}async canManageDomain(t){try{let e=this.getRootDomain(t);return await this.request(`/dns/retrieve/${e}`),!0}catch{return!1}}async listDomains(){try{return((await this.request("/domain/listAll")).domains||[]).map((e)=>e.domain)}catch{return[]}}async getNameServers(t){try{let e=this.getRootDomain(t);return(await this.request(`/dns/getNS/${e}`)).ns||[]}catch{return[]}}async updateNameServers(t,e){try{let r=this.getRootDomain(t);return await this.request(`/dns/updateNS/${r}`,{ns:e}),!0}catch{return!1}}}class v{name="godaddy";apiKey;apiSecret;baseUrl;constructor(t,e,r="production"){this.apiKey=t,this.apiSecret=e,this.baseUrl=r==="ote"?"https://api.ote-godaddy.com":"https://api.godaddy.com"}async request(t,e,r){let n=`${this.baseUrl}${e}`,s={Authorization:`sso-key ${this.apiKey}:${this.apiSecret}`,"Content-Type":"application/json",Accept:"application/json"},o={method:t,headers:s};if(r)o.body=JSON.stringify(r);let i=await fetch(n,o);if(i.status===204)return{};if(i.ok){let c=await i.text();if(c)return JSON.parse(c);return{}}let a=`GoDaddy API error: ${i.status} ${i.statusText}`;try{let c=await i.json();if(c.message)a=`GoDaddy API error: ${c.message}`;if(c.fields)a+=` - Fields: ${JSON.stringify(c.fields)}`}catch{}throw Error(a)}getSubdomain(t,e){let r=t.replace(/\.$/,""),n=e.replace(/\.$/,"");if(r===n)return"@";if(r.endsWith(`.${n}`))return r.slice(0,-(n.length+1));return r}getRootDomain(t){let e=t.replace(/\.$/,"").split(".");if(e.length>=2)return e.slice(-2).join(".");return t}toGoDaddyRecord(t,e){let r=this.getRootDomain(e),n=this.getSubdomain(t.name,r),s={type:t.type,name:n,data:t.content,ttl:t.ttl||600};if(t.type==="MX"&&t.priority!==void 0)s.priority=t.priority;return s}fromGoDaddyRecord(t,e){let r=this.getRootDomain(e),n=t.name;if(n==="@")n=r;else if(!n.endsWith(r))n=`${n}.${r}`;return{name:n,type:t.type,content:t.data,ttl:t.ttl,priority:t.priority}}async createRecord(t,e){try{let r=this.getRootDomain(t),n=this.toGoDaddyRecord(e,t);return await this.request("PATCH",`/v1/domains/${r}/records`,[n]),{success:!0,message:"Record created successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async upsertRecord(t,e){try{let r=this.getRootDomain(t),n=this.toGoDaddyRecord(e,t);return await this.request("PUT",`/v1/domains/${r}/records/${e.type}/${n.name}`,[n]),{success:!0,message:"Record upserted successfully"}}catch(r){return this.createRecord(t,e)}}async deleteRecord(t,e){try{let r=this.getRootDomain(t),n=this.getSubdomain(e.name,r),s=await this.request("GET",`/v1/domains/${r}/records/${e.type}/${n}`),o=s.filter((i)=>i.data!==e.content);if(o.length===s.length)return{success:!1,message:"Record not found"};if(o.length===0)try{await this.request("DELETE",`/v1/domains/${r}/records/${e.type}/${n}`)}catch{}else await this.request("PUT",`/v1/domains/${r}/records/${e.type}/${n}`,o);return{success:!0,message:"Record deleted successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async listRecords(t,e){try{let r=this.getRootDomain(t),n=`/v1/domains/${r}/records`;if(e)n=`/v1/domains/${r}/records/${e}`;return{success:!0,records:(await this.request("GET",n)).map((o)=>this.fromGoDaddyRecord(o,t))}}catch(r){return{success:!1,records:[],message:r instanceof Error?r.message:"Unknown error"}}}async canManageDomain(t){try{let e=this.getRootDomain(t);return await this.request("GET",`/v1/domains/${e}`),!0}catch{return!1}}async listDomains(){try{return(await this.request("GET","/v1/domains")).map((e)=>e.domain)}catch{return[]}}async getDomainDetails(t){try{let e=this.getRootDomain(t),r=await this.request("GET",`/v1/domains/${e}`);return{domain:r.domain,status:r.status,nameServers:r.nameServers,expires:r.expires}}catch{return null}}async getNameServers(t){return(await this.getDomainDetails(t))?.nameServers??[]}async updateNameServers(t,e){try{let r=this.getRootDomain(t);return await this.request("PATCH",`/v1/domains/${r}`,{nameServers:e}),!0}catch{return!1}}async checkDomainAvailability(t){try{let e=await this.request("GET",`/v1/domains/available?domain=${encodeURIComponent(t)}`);return{available:e.available,price:e.price,currency:e.currency}}catch{return{available:!1}}}}var _="https://api.cloudflare.com/client/v4",S="[ts-cloud]";class w{name="cloudflare";apiToken;zoneCache=new Map;configuredZoneId;accountId;configuredZoneName;constructor(t,e={}){this.apiToken=t,this.configuredZoneId=e.zoneId,this.accountId=e.accountId}async request(t,e,r){let n=`${_}${e}`,s={Authorization:`Bearer ${this.apiToken}`,"Content-Type":"application/json"},o={method:t,headers:s};if(r)o.body=JSON.stringify(r);let a=await(await fetch(n,o)).json();if(!a.success){let c=a.errors.map((d)=>d.message).join(", ");throw Error(`Cloudflare API error: ${c}`)}return a}getRootDomain(t){let e=t.replace(/\.$/,"").split(".");if(e.length>=2)return e.slice(-2).join(".");return t}async resolveZone(t){let e=t.replace(/\.$/,"").toLowerCase();if(this.configuredZoneId){let i=await this.resolveConfiguredZoneName();if(i&&(e===i||e.endsWith(`.${i}`)))return{id:this.configuredZoneId,name:i}}let r=this.getRootDomain(e),n=this.zoneCache.get(r);if(n)return{id:n,name:r};let s=await this.request("GET",`/zones?name=${encodeURIComponent(r)}`);if(!s.result||s.result.length===0)throw Error(`Zone not found for domain: ${r}. `+"If the API token is scoped to a single zone, set its zone id (CLOUDFLARE_ZONE_ID) — "+"zone lookup by name needs account-wide Zone:Read.");let o=s.result[0].id;return this.zoneCache.set(r,o),{id:o,name:s.result[0].name||r}}async resolveConfiguredZoneName(){if(!this.configuredZoneId)return;if(this.configuredZoneName)return this.configuredZoneName;try{let e=(await this.request("GET",`/zones/${this.configuredZoneId}`)).result?.name?.toLowerCase();if(!e)return;return this.configuredZoneName=e,this.zoneCache.set(e,this.configuredZoneId),e}catch{return}}async getZoneId(t){return(await this.resolveZone(t)).id}getFullRecordName(t,e){let r=t.replace(/\.$/,"");if(!r||r===e||r==="@")return e;if(r.endsWith(`.${e}`))return r;return`${r}.${e}`}toCloudflareRecord(t,e,r){let n={type:t.type,name:this.getFullRecordName(t.name,e),content:t.content||t.value||"",ttl:t.ttl||1},s=r??t.proxied;if(s!==void 0&&I.has(t.type)){if(n.proxied=s,s)n.ttl=1}if(t.type==="MX"&&t.priority!==void 0)n.priority=t.priority;if(t.type==="SRV"){let o=O(t);if(o)n.data=o,delete n.content,delete n.priority;else if(t.priority!==void 0)n.priority=t.priority}return n}fromCloudflareRecord(t){return{id:t.id,name:t.name,type:t.type,content:t.content,ttl:t.ttl,priority:t.priority,proxied:t.proxied}}async createRecord(t,e){try{let r=await this.resolveZone(t),n=this.toCloudflareRecord(e,r.name);return{success:!0,id:(await this.request("POST",`/zones/${r.id}/dns_records`,n)).result.id,message:"Record created successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async upsertRecord(t,e){try{let r=await this.resolveZone(t),n=this.getFullRecordName(e.name,r.name),o=(await this.request("GET",`/zones/${r.id}/dns_records?type=${e.type}&name=${encodeURIComponent(n)}`)).result?.[0],i=e.proxied??o?.proxied,a=this.toCloudflareRecord(e,r.name,i);if(o)return{success:!0,id:(await this.request("PUT",`/zones/${r.id}/dns_records/${o.id}`,a)).result.id,message:"Record updated successfully"};return{success:!0,id:(await this.request("POST",`/zones/${r.id}/dns_records`,a)).result.id,message:"Record created successfully"}}catch(r){return this.createRecord(t,e)}}async deleteRecord(t,e){try{let r=await this.resolveZone(t),n=r.id,s=this.getFullRecordName(e.name,r.name),o=await this.request("GET",`/zones/${n}/dns_records?type=${e.type}&name=${encodeURIComponent(s)}`);if(!o.result||o.result.length===0)return{success:!1,message:"Record not found"};let i=o.result.find((a)=>a.content===e.content);if(!i)return{success:!1,message:"Record with matching content not found"};return await this.request("DELETE",`/zones/${n}/dns_records/${i.id}`),{success:!0,message:"Record deleted successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async listRecords(t,e){try{let n=`/zones/${await this.getZoneId(t)}/dns_records?per_page=100`;if(e)n+=`&type=${e}`;let s=[],o=1,i=!0;while(i){let a=await this.request("GET",`${n}&page=${o}`);if(s.push(...a.result||[]),a.result_info)i=o<a.result_info.total_pages,o++;else i=!1}return{success:!0,records:s.map((a)=>this.fromCloudflareRecord(a))}}catch(r){return{success:!1,records:[],message:r instanceof Error?r.message:"Unknown error"}}}async canManageDomain(t){try{return await this.getZoneId(t),!0}catch{return!1}}async listDomains(){try{let t=[],e=1,r=!0;while(r){let n=await this.request("GET",`/zones?per_page=50&page=${e}`);if(t.push(...n.result||[]),n.result_info)r=e<n.result_info.total_pages,e++;else r=!1}return t.map((n)=>n.name)}catch{return[]}}async createZone(t,e={}){let r=t.replace(/\.$/,"").toLowerCase(),n=e.accountId??this.accountId;if(!n)throw Error(`Cannot create zone ${r}: no Cloudflare account id. Set CLOUDFLARE_ACCOUNT_ID, or pass accountId.`);try{let o=(await this.request("POST","/zones",{name:r,account:{id:n},jump_start:e.jumpStart??!1})).result;return this.zoneCache.set(o.name,o.id),{id:o.id,name:o.name,status:o.status,nameServers:o.name_servers??[],created:!0}}catch(s){let o=s instanceof Error?s.message:String(s);if(!/already exists|1061/i.test(o))throw s;let i=await this.getZoneDetails(r);if(!i)throw s;return{...i,created:!1}}}async getZoneDetails(t){try{let e=await this.getZoneId(t),r=await this.request("GET",`/zones/${e}`);return{id:r.result.id,name:r.result.name,status:r.result.status,nameServers:r.result.name_servers,paused:r.result.paused}}catch{return null}}async purgeCache(t,e){try{let r=await this.getZoneId(t),n={};if(e?.purgeEverything)n.purge_everything=!0;else{if(e?.files)n.files=e.files;if(e?.tags)n.tags=e.tags;if(e?.hosts)n.hosts=e.hosts}if(Object.keys(n).length===0)n.purge_everything=!0;return await this.request("POST",`/zones/${r}/purge_cache`,n),!0}catch{return!1}}async getRecordProxyStatus(t,e){try{let r=await this.resolveZone(t),n=r.id,s=this.getFullRecordName(e.name,r.name),o=await this.request("GET",`/zones/${n}/dns_records?type=${e.type}&name=${encodeURIComponent(s)}`);if(o.result&&o.result.length>0)return o.result.find((a)=>a.content===e.content)?.proxied??null;return null}catch{return null}}async setRecordProxyStatus(t,e,r){try{let n=await this.resolveZone(t),s=n.id,o=this.getFullRecordName(e.name,n.name),i=await this.request("GET",`/zones/${s}/dns_records?type=${e.type}&name=${encodeURIComponent(o)}`);if(!i.result||i.result.length===0)return!1;let a=i.result.find((c)=>c.content===e.content);if(!a)return!1;return await this.request("PATCH",`/zones/${s}/dns_records/${a.id}`,{proxied:r}),!0}catch{return!1}}async zoneIdFor(t){return this.getZoneId(t)}get account(){return this.accountId}async getZoneSettings(t){let e=await this.getZoneId(t),r=await this.request("GET",`/zones/${e}/settings`),n={};for(let s of r.result||[])n[s.id]=s.value;return n}async applyZoneSettings(t,e){let r=await this.getZoneId(t),n=await this.getZoneSettings(t).catch(()=>({})),s=[],o=[];for(let[i,a]of Object.entries(e)){if(a===void 0)continue;let c=n[i];if(c!==void 0&&T(c,a))continue;try{await this.request("PATCH",`/zones/${r}/settings/${i}`,{value:a}),s.push({id:i,from:c,to:a})}catch(d){o.push({id:i,error:d instanceof Error?d.message:String(d)})}}return{changed:s,failed:o}}async getPhaseRules(t,e){let r=await this.getZoneId(t);try{return(await this.request("GET",`/zones/${r}/rulesets/phases/${e}/entrypoint`)).result?.rules||[]}catch{return[]}}async putManagedPhaseRules(t,e,r){try{let n=await this.getZoneId(t),o=(await this.getPhaseRules(t,e)).filter((c)=>!(c.description||"").startsWith(S)),i=r.map((c)=>({...c,description:c.description?.startsWith(S)?c.description:`${S} ${c.description||e}`})),a=[...o,...i].map(({id:c,...d})=>d);return await this.request("PUT",`/zones/${n}/rulesets/phases/${e}/entrypoint`,{rules:a}),{success:!0}}catch(n){return{success:!1,message:n instanceof Error?n.message:String(n)}}}}function T(t,e){if(t===e)return!0;if(typeof t!==typeof e||t===null||e===null)return!1;if(typeof t!=="object")return!1;if(Array.isArray(t)||Array.isArray(e)){if(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)return!1;return t.every((s,o)=>T(s,e[o]))}let r=t,n=e;return Object.keys(n).every((s)=>T(r[s],n[s]))}function O(t){let e=(t.content||t.value||"").trim();if(t.weight!==void 0&&t.port!==void 0&&t.priority!==void 0&&e)return{priority:t.priority,weight:t.weight,port:t.port,target:x(e)};let r=e.split(/\s+/);if(r.length<4)return null;let[n,s,o]=r.slice(0,3).map(Number);if(![n,s,o].every(Number.isFinite))return null;return{priority:n,weight:s,port:o,target:x(r.slice(3).join(" "))}}function x(t){return t.replace(/\.$/,"")}var k=new Set(["A","AAAA","CNAME","ALIAS"]);function A(t){let e=t.trim().replace(/^"|"$/g,"").toLowerCase();if(e.startsWith("v=spf1"))return"v=spf1";if(e.startsWith("v=dmarc1"))return"v=dmarc1";return}function f(t){return t.trim().replace(/^"(.*)"$/s,"$1")}function R(t){return t.replace(/\.$/,"").toLowerCase()}function V(t,e){let r=R(e),n=(t??"@").trim();if(!n||n==="@")return r;let s=R(n);if(s===r||s.endsWith(`.${r}`))return s;return`${s}.${r}`}function z(t,e){return t.map((r)=>({...r,name:V(r.name,e),proxied:r.proxied??!1}))}function L(t,e){if(t.type!==e.type)return!1;if(R(t.name)!==R(e.name))return!1;if(k.has(e.type))return!0;if(e.type==="TXT"){let r=A(e.content);if(r)return A(f(t.content))===r;return f(t.content)===f(e.content)}return f(t.content)===f(e.content)}function q(t,e){if(f(t.content)!==f(e.content))return!1;if(e.priority!==void 0&&t.priority!==e.priority)return!1;if(e.proxied!==void 0&&t.proxied!==void 0&&t.proxied!==e.proxied)return!1;return!0}async function U(t){let{provider:e,zone:r,records:n}=t,s={outcomes:[],warnings:[]};if(n.length===0)return s;let o=await e.listRecords(r);if(!o.success)return s.warnings.push(`could not list ${r}: ${o.message||"unknown provider error"} — records not reconciled`),s;let i=o.records;for(let a of n){let c=i.filter((u)=>L(u,a));if(c.length>0&&c.every((u)=>q(u,a))){s.outcomes.push({record:a,action:"unchanged"});continue}let d={name:a.name,type:a.type,content:a.content,ttl:a.ttl??3600,...a.priority!==void 0?{priority:a.priority}:{},...a.proxied!==void 0?{proxied:a.proxied}:{}},m=a.type==="TXT"&&A(a.content)!==void 0;if(m)for(let u of c){let b=await e.deleteRecord(r,{name:u.name,type:u.type,content:u.content});if(!b.success)s.warnings.push(`could not remove superseded ${u.type} at ${u.name}: ${b.message||"unknown error"}`)}let g=m||c.length===0?await e.createRecord(r,d):await e.upsertRecord(r,d);if(g.success)s.outcomes.push({record:a,action:c.length>0?"updated":"created"});else s.outcomes.push({record:a,action:"failed",message:g.message})}for(let a of["MX"]){let c=new Set(n.filter((d)=>d.type===a).map((d)=>R(d.name)));for(let d of c){let m=new Set(n.filter((u)=>u.type===a&&R(u.name)===d).map((u)=>f(u.content).toLowerCase())),g=i.filter((u)=>u.type===a&&R(u.name)===d&&!m.has(f(u.content).toLowerCase()));for(let u of g)s.warnings.push(`${d} has an undeclared ${a} record (${u.content}) alongside the declared one — mail will be split between them. Remove it at the provider if it is stale.`)}}return s}class C{name="route53";client;hostedZoneCache=new Map;providedHostedZoneId;constructor(t="us-east-1",e){this.client=new y(t),this.providedHostedZoneId=e}getRootDomain(t){let e=t.replace(/\.$/,"").split(".");if(e.length>=2)return e.slice(-2).join(".");return t}async getHostedZoneId(t){if(this.providedHostedZoneId)return this.providedHostedZoneId;let e=this.getRootDomain(t),r=this.hostedZoneCache.get(e);if(r)return r;let n=await this.client.findHostedZoneForDomain(t);if(n){let s=n.Id.replace("/hostedzone/","");return this.hostedZoneCache.set(e,s),s}return null}normalizeName(t,e){let r=t.replace(/\.$/,""),n=e.replace(/\.$/,"");if(!n||n==="@")return`${r}.`;if(n===r||n.endsWith(`.${r}`))return`${n}.`;return`${n}.${r}.`}async createRecord(t,e){try{let r=await this.getHostedZoneId(t);if(!r)return{success:!1,message:`No hosted zone found for domain: ${t}`};let n=this.normalizeName(t,e.name),s=e.content;if(e.type==="TXT"&&!s.startsWith('"'))s=`"${s}"`;if(e.type==="MX"&&e.priority!==void 0)s=`${e.priority} ${s}`;return{success:!0,id:(await this.client.changeResourceRecordSets({HostedZoneId:r,ChangeBatch:{Comment:"Created by ts-cloud DNS provider",Changes:[{Action:"CREATE",ResourceRecordSet:{Name:n,Type:e.type,TTL:e.ttl||300,ResourceRecords:[{Value:s}]}}]}})).ChangeInfo?.Id,message:"Record created successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async upsertRecord(t,e){try{let r=await this.getHostedZoneId(t);if(!r)return{success:!1,message:`No hosted zone found for domain: ${t}`};let n=this.normalizeName(t,e.name),s=e.content;if(e.type==="TXT"&&!s.startsWith('"'))s=`"${s}"`;if(e.type==="MX"&&e.priority!==void 0)s=`${e.priority} ${s}`;return{success:!0,id:(await this.client.changeResourceRecordSets({HostedZoneId:r,ChangeBatch:{Comment:"Upserted by ts-cloud DNS provider",Changes:[{Action:"UPSERT",ResourceRecordSet:{Name:n,Type:e.type,TTL:e.ttl||300,ResourceRecords:[{Value:s}]}}]}})).ChangeInfo?.Id,message:"Record upserted successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async deleteRecord(t,e){try{let r=await this.getHostedZoneId(t);if(!r)return{success:!1,message:`No hosted zone found for domain: ${t}`};let n=this.normalizeName(t,e.name),s=e.content;if(e.type==="TXT"&&!s.startsWith('"'))s=`"${s}"`;if(e.type==="MX"&&e.priority!==void 0)s=`${e.priority} ${s}`;return await this.client.changeResourceRecordSets({HostedZoneId:r,ChangeBatch:{Comment:"Deleted by ts-cloud DNS provider",Changes:[{Action:"DELETE",ResourceRecordSet:{Name:n,Type:e.type,TTL:e.ttl||300,ResourceRecords:[{Value:s}]}}]}}),{success:!0,message:"Record deleted successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async listRecords(t,e){try{let r=await this.getHostedZoneId(t);if(!r)return{success:!1,records:[],message:`No hosted zone found for domain: ${t}`};let n=await this.client.listResourceRecordSets({HostedZoneId:r,StartRecordType:e}),s=[];for(let o of n.ResourceRecordSets){if(e&&o.Type!==e)continue;if(o.AliasTarget)continue;for(let i of o.ResourceRecords||[]){let a=i.Value,c;if(o.Type==="MX"){let d=a.split(" ");if(d.length>=2)c=Number.parseInt(d[0],10),a=d.slice(1).join(" ")}if(o.Type==="TXT"&&a.startsWith('"')&&a.endsWith('"'))a=a.slice(1,-1);s.push({name:o.Name.replace(/\.$/,""),type:o.Type,content:a,ttl:o.TTL,priority:c})}}return{success:!0,records:s}}catch(r){return{success:!1,records:[],message:r instanceof Error?r.message:"Unknown error"}}}async canManageDomain(t){return await this.getHostedZoneId(t)!==null}async listDomains(){try{return(await this.client.listHostedZones()).HostedZones.map((e)=>e.Name.replace(/\.$/,""))}catch{return[]}}getRoute53Client(){return this.client}async createAliasRecord(t){try{let e=await this.getHostedZoneId(t.domain);if(!e)return{success:!1,message:`No hosted zone found for domain: ${t.domain}`};return{success:!0,id:(await this.client.createAliasRecord({HostedZoneId:e,Name:this.normalizeName(t.domain,t.name),TargetHostedZoneId:t.targetHostedZoneId,TargetDNSName:t.targetDnsName,EvaluateTargetHealth:t.evaluateTargetHealth,Type:t.type})).ChangeInfo?.Id,message:"Alias record created successfully"}}catch(e){return{success:!1,message:e instanceof Error?e.message:"Unknown error"}}}async createCloudFrontAlias(t){return this.createAliasRecord({domain:t.domain,name:t.name,targetHostedZoneId:y.CloudFrontHostedZoneId,targetDnsName:t.cloudFrontDomainName,evaluateTargetHealth:!1})}async createAlbAlias(t){let e=y.ALBHostedZoneIds[t.region];if(!e)return{success:!1,message:`Unknown region for ALB: ${t.region}`};return this.createAliasRecord({domain:t.domain,name:t.name,targetHostedZoneId:e,targetDnsName:t.albDnsName,evaluateTargetHealth:!0})}}async function j(t,e){let r=[],n,s;for(;;){let o=await t.listResourceRecordSets({HostedZoneId:e,StartRecordName:n,StartRecordType:s,MaxItems:"100"});if(r.push(...o.ResourceRecordSets),!o.IsTruncated)break;if(n=o.NextRecordName,s=o.NextRecordType,!n)break}return r}function l(t){return t.replace(/\.$/,"").toLowerCase()}function F(t){let e=t.match(/"(?:[^"\\]|\\.)*"/g);if(!e)return t;return e.map((r)=>r.slice(1,-1).replace(/\\(.)/g,"$1")).join("")}function G(t,e){let r=l(e),n=[],s=[],o=[],i=new Set;for(let a of t){let c=l(a.Name),d=a.Type;if(d==="SOA"||d==="NS"&&c===r){s.push({name:c,type:d,reason:"owned by the destination provider"});continue}if(a.SetIdentifier){s.push({name:c,type:d,reason:`routing policy record (SetIdentifier=${a.SetIdentifier}) has no equivalent — recreate by hand`}),o.push(`${d} ${c} is part of a Route53 routing policy and was NOT migrated`);continue}if(a.AliasTarget){if(i.has(c))continue;i.add(c);let m=l(a.AliasTarget.DNSName);if(n.push({name:c,type:"CNAME",content:m,ttl:300,translatedFrom:`${d} ALIAS → ${m}`}),a.AliasTarget.EvaluateTargetHealth)o.push(`${c} was an ALIAS with health evaluation enabled; the CNAME that replaces it has no health check`);continue}for(let m of a.ResourceRecords||[]){let g=W(c,d,m.Value,a.TTL);if("reason"in g){s.push({name:c,type:d,reason:g.reason}),o.push(`${d} ${c}: ${g.reason}`);continue}n.push(g)}}return{zone:r,records:n,skipped:s,warnings:o}}function W(t,e,r,n){let s={name:t,ttl:n};switch(e){case"A":case"AAAA":case"CNAME":case"PTR":return{...s,type:e==="PTR"?"CNAME":e,content:l(r)};case"TXT":return{...s,type:"TXT",content:F(r)};case"MX":{let[o,...i]=r.trim().split(/\s+/);if(!i.length)return{reason:`malformed MX value "${r}"`};return{...s,type:"MX",content:l(i.join(" ")),priority:Number(o)}}case"SRV":{let o=r.trim().split(/\s+/);if(o.length<4)return{reason:`malformed SRV value "${r}"`};let[i,a,c]=o.slice(0,3).map(Number);return{...s,type:"SRV",content:l(o.slice(3).join(" ")),priority:i,weight:a,port:c}}case"NS":return{...s,type:"NS",content:l(r)};case"CAA":return{...s,type:"CAA",content:r.trim()};default:return{reason:`unsupported record type ${e}`}}}async function H(t,e){let r=[],n=[];for(let s of e.records){let o=await t.upsertRecord(e.zone,{...s,proxied:!1});if(o.success)r.push(s);else n.push({record:s,message:o.message||"unknown provider error"})}return{applied:r,failed:n}}async function K(t,e){let r=await t.listRecords(e.zone),n=[],s=[],o=new Map;for(let i of r.records||[]){let a=`${l(i.name)}|${i.type}`,c=o.get(a)??[];c.push(l(String(i.content))),o.set(a,c)}for(let i of e.records){let a=o.get(`${l(i.name)}|${i.type}`),c=l(i.content);if(a?.some((d)=>d===c||d.includes(c)||c.includes(d)))n.push(i);else s.push({record:i,found:a?.join(", ")})}return{matched:n,missing:s,ok:s.length===0}}class P{client;region;constructor(t="us-east-1"){this.client=new M,this.region=t}async requestCertificate(t){let e={DomainName:t.DomainName,ValidationMethod:t.ValidationMethod||"DNS"};if(t.SubjectAlternativeNames)e.SubjectAlternativeNames=t.SubjectAlternativeNames;return{CertificateArn:(await this.client.request({service:"acm",region:this.region,method:"POST",path:"/",headers:{"content-type":"application/x-amz-json-1.1","x-amz-target":"CertificateManager.RequestCertificate"},body:JSON.stringify(e)})).CertificateArn||""}}async describeCertificate(t){let r=(await this.client.request({service:"acm",region:this.region,method:"POST",path:"/",headers:{"content-type":"application/x-amz-json-1.1","x-amz-target":"CertificateManager.DescribeCertificate"},body:JSON.stringify({CertificateArn:t.CertificateArn})})).Certificate||{};return{CertificateArn:r.CertificateArn||"",DomainName:r.DomainName||"",SubjectAlternativeNames:r.SubjectAlternativeNames,Status:r.Status||"PENDING_VALIDATION",Type:r.Type,DomainValidationOptions:r.DomainValidationOptions?.map((n)=>({DomainName:n.DomainName,ValidationDomain:n.ValidationDomain,ValidationStatus:n.ValidationStatus,ResourceRecord:n.ResourceRecord?{Name:n.ResourceRecord.Name,Type:n.ResourceRecord.Type,Value:n.ResourceRecord.Value}:void 0,ValidationMethod:n.ValidationMethod})),CreatedAt:r.CreatedAt,IssuedAt:r.IssuedAt,NotBefore:r.NotBefore,NotAfter:r.NotAfter}}async listCertificates(t){let e={};if(t?.CertificateStatuses)e.CertificateStatuses=t.CertificateStatuses;if(t?.MaxItems)e.MaxItems=t.MaxItems;if(t?.NextToken)e.NextToken=t.NextToken;let r=await this.client.request({service:"acm",region:this.region,method:"POST",path:"/",headers:{"content-type":"application/x-amz-json-1.1","x-amz-target":"CertificateManager.ListCertificates"},body:JSON.stringify(e)});return{CertificateSummaryList:(r.CertificateSummaryList||[]).map((n)=>({CertificateArn:n.CertificateArn,DomainName:n.DomainName})),NextToken:r.NextToken}}async deleteCertificate(t){await this.client.request({service:"acm",region:this.region,method:"POST",path:"/",headers:{"content-type":"application/x-amz-json-1.1","x-amz-target":"CertificateManager.DeleteCertificate"},body:JSON.stringify({CertificateArn:t.CertificateArn})})}async listTagsForCertificate(t){return{Tags:(await this.client.request({service:"acm",region:this.region,method:"POST",path:"/",headers:{"content-type":"application/x-amz-json-1.1","x-amz-target":"CertificateManager.ListTagsForCertificate"},body:JSON.stringify({CertificateArn:t.CertificateArn})})).Tags||[]}}async addTagsToCertificate(t){await this.client.request({service:"acm",region:this.region,method:"POST",path:"/",headers:{"content-type":"application/x-amz-json-1.1","x-amz-target":"CertificateManager.AddTagsToCertificate"},body:JSON.stringify({CertificateArn:t.CertificateArn,Tags:t.Tags})})}async resendValidationEmail(t){await this.client.request({service:"acm",region:this.region,method:"POST",path:"/",headers:{"content-type":"application/x-amz-json-1.1","x-amz-target":"CertificateManager.ResendValidationEmail"},body:JSON.stringify({CertificateArn:t.CertificateArn,Domain:t.Domain,ValidationDomain:t.ValidationDomain})})}async findCertificateByDomain(t){let r=(await this.listCertificates({CertificateStatuses:["ISSUED"]})).CertificateSummaryList.find((n)=>n.DomainName===t||n.DomainName===`*.${t.split(".").slice(1).join(".")}`);if(!r)return null;return this.describeCertificate({CertificateArn:r.CertificateArn})}async waitForCertificateValidation(t,e=60,r=30000){for(let n=0;n<e;n++){let s=await this.describeCertificate({CertificateArn:t});if(s.Status==="ISSUED")return s;if(s.Status==="FAILED"||s.Status==="VALIDATION_TIMED_OUT")return null;await new Promise((o)=>setTimeout(o,r))}return null}async getDnsValidationRecords(t){let e=await this.describeCertificate({CertificateArn:t});if(!e.DomainValidationOptions)return[];return e.DomainValidationOptions.filter((r)=>r.ResourceRecord&&r.ValidationMethod==="DNS").map((r)=>({domainName:r.DomainName,recordName:r.ResourceRecord.Name,recordType:r.ResourceRecord.Type,recordValue:r.ResourceRecord.Value}))}async requestCertificateWithSans(t){let e=new Set;if(e.add(t.DomainName),t.IncludeWww!==!1)e.add(`www.${t.DomainName}`);if(t.IncludeWildcard)e.add(`*.${t.DomainName}`);if(t.AdditionalSans)for(let r of t.AdditionalSans)e.add(r);return this.requestCertificate({DomainName:t.DomainName,SubjectAlternativeNames:Array.from(e),ValidationMethod:"DNS"})}async isCertificateValidForDomain(t,e){let r=await this.describeCertificate({CertificateArn:t});if(r.Status!=="ISSUED")return!1;if(r.DomainName===e)return!0;if(r.DomainName?.startsWith("*.")){let n=r.DomainName.slice(2),s=e.split("."),o=n.split(".");if(s.slice(-o.length).join(".")===n)return!0}if(r.SubjectAlternativeNames)for(let n of r.SubjectAlternativeNames){if(n===e)return!0;if(n.startsWith("*.")){let s=n.slice(2),o=e.split("."),i=s.split(".");if(o.slice(-i.length).join(".")===s)return!0}}return!1}}class X{acm;route53;dnsProvider;constructor(t="us-east-1",e){if(this.acm=new P(t),this.route53=new y,e&&e.provider!=="route53")this.dnsProvider=p(e)}async requestAndValidate(t){let{domainName:e,hostedZoneId:r,subjectAlternativeNames:n=[],waitForValidation:s=!1,maxWaitMinutes:o=30}=t;if(!this.dnsProvider&&!r)throw Error("Either hostedZoneId or external DNS provider configuration is required");let{CertificateArn:i}=await this.acm.requestCertificate({DomainName:e,SubjectAlternativeNames:n.length>0?[e,...n]:void 0,ValidationMethod:"DNS"});await this.waitForValidationOptions(i);let a=await this.acm.getDnsValidationRecords(i);if(this.dnsProvider)for(let c of a){let d=await this.dnsProvider.upsertRecord(e,{name:c.recordName,type:c.recordType,content:c.recordValue,ttl:300});if(!d.success)console.warn(`Failed to create validation record for ${c.domainName}: ${d.message}`)}else if(r)for(let c of a)await this.route53.changeResourceRecordSets({HostedZoneId:r,ChangeBatch:{Comment:`ACM DNS validation for ${c.domainName}`,Changes:[{Action:"UPSERT",ResourceRecordSet:{Name:c.recordName,Type:c.recordType,TTL:300,ResourceRecords:[{Value:c.recordValue}]}}]}});if(s){if(!await this.acm.waitForCertificateValidation(i,o*2,30000))throw Error(`Certificate validation timed out after ${o} minutes`)}return{certificateArn:i,validationRecords:a}}async waitForValidationOptions(t,e=30){for(let r=0;r<e;r++){let n=await this.acm.describeCertificate({CertificateArn:t});if(n.DomainValidationOptions&&n.DomainValidationOptions.length>0&&n.DomainValidationOptions[0].ResourceRecord)return;await new Promise((s)=>setTimeout(s,2000))}throw Error("Timeout waiting for DNS validation options")}async createValidationRecords(t){let{certificateArn:e,hostedZoneId:r,domain:n}=t;if(!this.dnsProvider&&!r)throw Error("Either hostedZoneId or external DNS provider configuration is required");let s=await this.acm.getDnsValidationRecords(e),o=[];if(this.dnsProvider){let i=n||s[0]?.domainName;for(let a of s){let c=await this.dnsProvider.upsertRecord(i,{name:a.recordName,type:a.recordType,content:a.recordValue,ttl:300});o.push({...a,changeId:c.success?c.id:void 0})}}else if(r)for(let i of s){let a=await this.route53.changeResourceRecordSets({HostedZoneId:r,ChangeBatch:{Comment:`ACM DNS validation for ${i.domainName}`,Changes:[{Action:"UPSERT",ResourceRecordSet:{Name:i.recordName,Type:i.recordType,TTL:300,ResourceRecords:[{Value:i.recordValue}]}}]}});o.push({...i,changeId:a.ChangeInfo?.Id})}return o}async deleteValidationRecords(t){let{certificateArn:e,hostedZoneId:r,domain:n}=t,s=await this.acm.getDnsValidationRecords(e);if(this.dnsProvider){let o=n||s[0]?.domainName;for(let i of s)try{await this.dnsProvider.deleteRecord(o,{name:i.recordName,type:i.recordType,content:i.recordValue})}catch{}}else if(r)for(let o of s)try{await this.route53.changeResourceRecordSets({HostedZoneId:r,ChangeBatch:{Comment:`Cleanup ACM DNS validation for ${o.domainName}`,Changes:[{Action:"DELETE",ResourceRecordSet:{Name:o.recordName,Type:o.recordType,TTL:300,ResourceRecords:[{Value:o.recordValue}]}}]}})}catch{}}async findOrCreateCertificate(t){let{domainName:e,hostedZoneId:r,subjectAlternativeNames:n,waitForValidation:s=!0}=t;if(!this.dnsProvider&&!r)throw Error("Either hostedZoneId or external DNS provider configuration is required");let o=await this.acm.findCertificateByDomain(e);if(o&&o.Status==="ISSUED")return{certificateArn:o.CertificateArn,isNew:!1};let{certificateArn:i}=await this.requestAndValidate({domainName:e,hostedZoneId:r,subjectAlternativeNames:n,waitForValidation:s});return{certificateArn:i,isNew:!0}}hasExternalDnsProvider(){return this.dnsProvider!==void 0}getDnsProviderName(){return this.dnsProvider?.name||"route53"}}class D{acm;dnsProvider;constructor(t,e="us-east-1"){if(this.acm=new P(e),"provider"in t)this.dnsProvider=p(t);else this.dnsProvider=t}getProvider(){return this.dnsProvider}async requestAndValidate(t){let{domainName:e,subjectAlternativeNames:r=[],waitForValidation:n=!1,maxWaitMinutes:s=30}=t,{CertificateArn:o}=await this.acm.requestCertificate({DomainName:e,SubjectAlternativeNames:r.length>0?[e,...r]:void 0,ValidationMethod:"DNS"});await this.waitForValidationOptions(o);let i=await this.acm.getDnsValidationRecords(o);for(let c of i){let d=await this.dnsProvider.upsertRecord(e,{name:c.recordName,type:c.recordType,content:c.recordValue,ttl:300});if(!d.success)console.warn(`Failed to create validation record for ${c.domainName}: ${d.message}`)}let a="pending";if(n)a=(await this.acm.waitForCertificateValidation(o,s*2,30000))?.Status==="ISSUED"?"issued":"failed";return{certificateArn:o,validationRecords:i.map((c)=>({domainName:c.domainName,recordName:c.recordName,recordType:c.recordType,recordValue:c.recordValue})),isNew:!0,status:a}}async createValidationRecords(t){let{certificateArn:e,domain:r}=t,n=[],s=await this.acm.getDnsValidationRecords(e);for(let o of s){let i=await this.dnsProvider.upsertRecord(r,{name:o.recordName,type:o.recordType,content:o.recordValue,ttl:300});if(!i.success)n.push(`Failed to create record for ${o.domainName}: ${i.message}`)}return{success:n.length===0,records:s.map((o)=>({domainName:o.domainName,recordName:o.recordName,recordType:o.recordType,recordValue:o.recordValue})),errors:n}}async deleteValidationRecords(t){let{certificateArn:e,domain:r}=t,n=[],s=await this.acm.getDnsValidationRecords(e);for(let o of s){let i=await this.dnsProvider.deleteRecord(r,{name:o.recordName,type:o.recordType,content:o.recordValue});if(!i.success)n.push(`Failed to delete record for ${o.domainName}: ${i.message}`)}return{success:n.length===0,errors:n}}async findOrCreateCertificate(t){let{domainName:e,subjectAlternativeNames:r=[],waitForValidation:n=!0,maxWaitMinutes:s}=t,o=await this.acm.findCertificateByDomain(e);if(o&&o.Status==="ISSUED"){let i=o.SubjectAlternativeNames||[o.DomainName],a=i.some((d)=>d===`*.${e}`);if(r.every((d)=>i.includes(d)||a))return{certificateArn:o.CertificateArn,validationRecords:[],isNew:!1,status:"issued"};console.log("Existing certificate doesn't cover all required SANs, requesting new certificate...")}return this.requestAndValidate({domainName:e,subjectAlternativeNames:r,waitForValidation:n,maxWaitMinutes:s})}async requestCertificateWithCommonSans(t){let{domainName:e,includeWww:r=!0,includeWildcard:n=!1,additionalSans:s=[],waitForValidation:o=!1}=t,i=[];if(r)i.push(`www.${e}`);if(n)i.push(`*.${e}`);return i.push(...s),this.requestAndValidate({domainName:e,subjectAlternativeNames:i,waitForValidation:o})}async waitForValidationOptions(t,e=30){for(let r=0;r<e;r++){let n=await this.acm.describeCertificate({CertificateArn:t});if(n.DomainValidationOptions&&n.DomainValidationOptions.length>0&&n.DomainValidationOptions[0].ResourceRecord)return;await new Promise((s)=>setTimeout(s,2000))}throw Error("Timeout waiting for DNS validation options")}async getCertificateStatus(t){let e=await this.acm.describeCertificate({CertificateArn:t});return{status:e.Status,domainValidations:(e.DomainValidationOptions||[]).map((r)=>({domain:r.DomainName,status:r.ValidationStatus||"UNKNOWN"}))}}}function B(t,e,r){return new D({provider:"porkbun",apiKey:t,secretKey:e},r)}function Y(t,e,r,n){return new D({provider:"godaddy",apiKey:t,apiSecret:e,environment:n},r)}function J(t,e,r){return new D({provider:"route53",region:t,hostedZoneId:e},r||t)}function p(t){switch(t.provider){case"route53":return new C(t.region,t.hostedZoneId);case"porkbun":return new h(t.apiKey,t.secretKey);case"godaddy":return new v(t.apiKey,t.apiSecret,t.environment);case"cloudflare":return new w(t.apiToken,{zoneId:t.zoneId,accountId:t.accountId});default:throw Error(`Unknown DNS provider: ${t.provider}`)}}async function De(t,e){for(let r of e){let n=p(r);if(await n.canManageDomain(t))return n}return null}class Z{providers=new Map;configs=[];addConfig(t){return this.configs.push(t),this}addRoute53(t,e){return this.configs.push({provider:"route53",region:t,hostedZoneId:e}),this}addPorkbun(t,e){return this.configs.push({provider:"porkbun",apiKey:t,secretKey:e}),this}addGoDaddy(t,e,r){return this.configs.push({provider:"godaddy",apiKey:t,apiSecret:e,environment:r}),this}addCloudflare(t,e={}){return this.configs.push({provider:"cloudflare",apiToken:t,zoneId:e.zoneId,accountId:e.accountId}),this}loadFromEnv(){if(process.env.AWS_ACCESS_KEY_ID||process.env.AWS_REGION)this.addRoute53(process.env.AWS_REGION);let t=process.env.PORKBUN_API_KEY,e=process.env.PORKBUN_SECRET_KEY;if(t&&e)this.addPorkbun(t,e);let r=process.env.GODADDY_API_KEY,n=process.env.GODADDY_API_SECRET;if(r&&n){let o=process.env.GODADDY_ENVIRONMENT;this.addGoDaddy(r,n,o)}let s=process.env.CLOUDFLARE_API_TOKEN;if(s)this.addCloudflare(s,{zoneId:process.env.CLOUDFLARE_ZONE_ID,accountId:process.env.CLOUDFLARE_ACCOUNT_ID});return this}getProvider(t){let e=this.providers.get(t);if(e)return e;let r=this.configs.find((s)=>s.provider===t);if(!r)return null;let n=p(r);return this.providers.set(t,n),n}async getProviderForDomain(t){for(let e of this.configs){let r=p(e);if(await r.canManageDomain(t))return r}return null}getAllProviders(){return this.configs.map((t)=>p(t))}}var ve=new Z;
1
+ import{Tf as y}from"./chunk-qjk1v1gs.js";import{Yh as M}from"./chunk-gk58959n.js";var I=new Set(["A","AAAA","CNAME"]);function E(t,e=""){return t===408||t===409||t===425||t===429||t>=500||/rate limit|temporar|timed? ?out|try again/i.test(e)}async function N(t,e){let r=e?.headers.get("retry-after"),n=r===null||r===void 0?void 0:Number(r)*1000,s=Number.isFinite(n)?Math.max(0,n):Math.min(1000*2**(t-1),30000);await new Promise((o)=>setTimeout(o,s))}class h{name="porkbun";apiKey;secretKey;requestTimeoutMs;constructor(t,e,r=15000){this.apiKey=t,this.secretKey=e,this.requestTimeoutMs=r}async request(t,e={}){let r;for(let n=1;n<=8;n+=1){let s,o=new AbortController,i=setTimeout(()=>{o.abort(Error(`Porkbun API request timed out after ${this.requestTimeoutMs}ms`))},this.requestTimeoutMs);try{s=await fetch(`https://api.porkbun.com/api/json/v3${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apikey:this.apiKey,secretapikey:this.secretKey,...e}),signal:o.signal})}catch(c){if(r=c,n===8)throw c;await N(n);continue}finally{clearTimeout(i)}if(!s.ok){if(r=Error(`Porkbun API error: ${s.status} ${s.statusText}`),!E(s.status)||n===8)throw r;await N(n,s);continue}let a=await s.json();if(a.status==="ERROR"){if(r=Error(`Porkbun API error: ${a.message||"Unknown error"}`),!E(0,a.message)||n===8)throw r;await N(n,s);continue}return a}throw r}getSubdomain(t,e){let r=t.replace(/\.$/,""),n=e.replace(/\.$/,"");if(r===n)return"";if(r.endsWith(`.${n}`))return r.slice(0,-(n.length+1));return r}getRootDomain(t){let e=t.replace(/\.$/,"").split(".");if(e.length>=2)return e.slice(-2).join(".");return t}static ADDRESS_TYPES=new Set(["A","AAAA"]);async clearConflictingAliases(t,e){if(!h.ADDRESS_TYPES.has(e.type))return[];let r=this.getRootDomain(t),n=this.getSubdomain(e.name,r),s=await this.listRecords(t);if(!s.success)return[`could not list records to clear ALIAS/CNAME conflicts: ${s.message??"unknown provider error"}`];let o=[];for(let i of s.records){if(i.type!=="ALIAS"&&i.type!=="CNAME")continue;if(this.getSubdomain(i.name,r)!==n)continue;let a=await this.deleteRecord(t,i);if(!a.success)o.push(`could not remove conflicting ${i.type} on ${i.name}: ${a.message??"unknown provider error"}`)}return o}async addressRecordExists(t,e){let r=this.getRootDomain(t),n=this.getSubdomain(e.name,r),s=await this.listRecords(t);if(!s.success)return!0;return s.records.some((o)=>o.type===e.type&&this.getSubdomain(o.name,r)===n&&o.content===e.content)}async createRecord(t,e){try{let r=this.getRootDomain(t),n=this.getSubdomain(e.name,r),s={type:e.type,content:e.content,ttl:String(e.ttl||600)};if(n)s.name=n;if((e.type==="MX"||e.type==="SRV")&&e.priority!==void 0)s.prio=String(e.priority);if(e.type==="SRV"&&e.weight!==void 0&&e.port!==void 0)s.content=`${e.weight} ${e.port} ${e.content}`;let o=await this.clearConflictingAliases(t,e),i=await this.request(`/dns/create/${r}`,s);if(h.ADDRESS_TYPES.has(e.type)&&!await this.addressRecordExists(t,e))return{success:!1,message:`Porkbun reported success but no ${e.type} record for ${e.name} exists${o.length>0?` (${o.join("; ")})`:""}. A conflicting ALIAS/CNAME on the same name silently voids the write.`};return{success:!0,id:i.id?.toString(),message:"Record created successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async upsertRecord(t,e){try{let r=this.getRootDomain(t),n=this.getSubdomain(e.name,r),s=await this.listRecords(t,e.type);if(s.success){let o=s.records.find((i)=>this.getSubdomain(i.name,r)===n&&i.type===e.type);if(o?.id){let i={type:e.type,content:e.content,ttl:String(e.ttl||600)};if(n)i.name=n;if((e.type==="MX"||e.type==="SRV")&&e.priority!==void 0)i.prio=String(e.priority);if(e.type==="SRV"&&e.weight!==void 0&&e.port!==void 0)i.content=`${e.weight} ${e.port} ${e.content}`;return await this.request(`/dns/edit/${r}/${o.id}`,i),{success:!0,id:o.id,message:"Record updated successfully"}}}return this.createRecord(t,e)}catch(r){return this.createRecord(t,e)}}async deleteRecord(t,e){try{let r=this.getRootDomain(t);if("id"in e&&e.id)return await this.request(`/dns/delete/${r}/${e.id}`),{success:!0,message:"Record deleted successfully"};let n=this.getSubdomain(e.name,r),s=await this.listRecords(t);if(!s.success)return{success:!1,message:"Failed to list records"};let o=s.records.find((i)=>this.getSubdomain(i.name,r)===n&&i.type===e.type&&i.content===e.content);if(!o?.id)return{success:!1,message:"Record not found"};return await this.request(`/dns/delete/${r}/${o.id}`),{success:!0,message:"Record deleted successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async listRecords(t,e){try{let r=this.getRootDomain(t),n=`/dns/retrieve/${r}`;if(e)n=`/dns/retrieveByNameType/${r}/${e}`;return{success:!0,records:((await this.request(n)).records||[]).map((i)=>({id:i.id,name:i.name||r,type:i.type,content:i.content,ttl:Number.parseInt(i.ttl,10),priority:i.prio?Number.parseInt(i.prio,10):void 0}))}}catch(r){return{success:!1,records:[],message:r instanceof Error?r.message:"Unknown error"}}}async canManageDomain(t){try{let e=this.getRootDomain(t);return await this.request(`/dns/retrieve/${e}`),!0}catch{return!1}}async listDomains(){try{return((await this.request("/domain/listAll")).domains||[]).map((e)=>e.domain)}catch{return[]}}async getNameServers(t){try{let e=this.getRootDomain(t);return(await this.request(`/dns/getNS/${e}`)).ns||[]}catch{return[]}}async updateNameServers(t,e){try{let r=this.getRootDomain(t);return await this.request(`/dns/updateNS/${r}`,{ns:e}),!0}catch{return!1}}}class v{name="godaddy";apiKey;apiSecret;baseUrl;constructor(t,e,r="production"){this.apiKey=t,this.apiSecret=e,this.baseUrl=r==="ote"?"https://api.ote-godaddy.com":"https://api.godaddy.com"}async request(t,e,r){let n=`${this.baseUrl}${e}`,s={Authorization:`sso-key ${this.apiKey}:${this.apiSecret}`,"Content-Type":"application/json",Accept:"application/json"},o={method:t,headers:s};if(r)o.body=JSON.stringify(r);let i=await fetch(n,o);if(i.status===204)return{};if(i.ok){let c=await i.text();if(c)return JSON.parse(c);return{}}let a=`GoDaddy API error: ${i.status} ${i.statusText}`;try{let c=await i.json();if(c.message)a=`GoDaddy API error: ${c.message}`;if(c.fields)a+=` - Fields: ${JSON.stringify(c.fields)}`}catch{}throw Error(a)}getSubdomain(t,e){let r=t.replace(/\.$/,""),n=e.replace(/\.$/,"");if(r===n)return"@";if(r.endsWith(`.${n}`))return r.slice(0,-(n.length+1));return r}getRootDomain(t){let e=t.replace(/\.$/,"").split(".");if(e.length>=2)return e.slice(-2).join(".");return t}toGoDaddyRecord(t,e){let r=this.getRootDomain(e),n=this.getSubdomain(t.name,r),s={type:t.type,name:n,data:t.content,ttl:t.ttl||600};if(t.type==="MX"&&t.priority!==void 0)s.priority=t.priority;return s}fromGoDaddyRecord(t,e){let r=this.getRootDomain(e),n=t.name;if(n==="@")n=r;else if(!n.endsWith(r))n=`${n}.${r}`;return{name:n,type:t.type,content:t.data,ttl:t.ttl,priority:t.priority}}async createRecord(t,e){try{let r=this.getRootDomain(t),n=this.toGoDaddyRecord(e,t);return await this.request("PATCH",`/v1/domains/${r}/records`,[n]),{success:!0,message:"Record created successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async upsertRecord(t,e){try{let r=this.getRootDomain(t),n=this.toGoDaddyRecord(e,t);return await this.request("PUT",`/v1/domains/${r}/records/${e.type}/${n.name}`,[n]),{success:!0,message:"Record upserted successfully"}}catch(r){return this.createRecord(t,e)}}async deleteRecord(t,e){try{let r=this.getRootDomain(t),n=this.getSubdomain(e.name,r),s=await this.request("GET",`/v1/domains/${r}/records/${e.type}/${n}`),o=s.filter((i)=>i.data!==e.content);if(o.length===s.length)return{success:!1,message:"Record not found"};if(o.length===0)try{await this.request("DELETE",`/v1/domains/${r}/records/${e.type}/${n}`)}catch{}else await this.request("PUT",`/v1/domains/${r}/records/${e.type}/${n}`,o);return{success:!0,message:"Record deleted successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async listRecords(t,e){try{let r=this.getRootDomain(t),n=`/v1/domains/${r}/records`;if(e)n=`/v1/domains/${r}/records/${e}`;return{success:!0,records:(await this.request("GET",n)).map((o)=>this.fromGoDaddyRecord(o,t))}}catch(r){return{success:!1,records:[],message:r instanceof Error?r.message:"Unknown error"}}}async canManageDomain(t){try{let e=this.getRootDomain(t);return await this.request("GET",`/v1/domains/${e}`),!0}catch{return!1}}async listDomains(){try{return(await this.request("GET","/v1/domains")).map((e)=>e.domain)}catch{return[]}}async getDomainDetails(t){try{let e=this.getRootDomain(t),r=await this.request("GET",`/v1/domains/${e}`);return{domain:r.domain,status:r.status,nameServers:r.nameServers,expires:r.expires}}catch{return null}}async getNameServers(t){return(await this.getDomainDetails(t))?.nameServers??[]}async updateNameServers(t,e){try{let r=this.getRootDomain(t);return await this.request("PATCH",`/v1/domains/${r}`,{nameServers:e}),!0}catch{return!1}}async checkDomainAvailability(t){try{let e=await this.request("GET",`/v1/domains/available?domain=${encodeURIComponent(t)}`);return{available:e.available,price:e.price,currency:e.currency}}catch{return{available:!1}}}}var _="https://api.cloudflare.com/client/v4",S="[ts-cloud]";class w{name="cloudflare";apiToken;zoneCache=new Map;configuredZoneId;accountId;configuredZoneName;constructor(t,e={}){this.apiToken=t,this.configuredZoneId=e.zoneId,this.accountId=e.accountId}async request(t,e,r){let n=`${_}${e}`,s={Authorization:`Bearer ${this.apiToken}`,"Content-Type":"application/json"},o={method:t,headers:s};if(r)o.body=JSON.stringify(r);let a=await(await fetch(n,o)).json();if(!a.success){let c=a.errors.map((d)=>d.message).join(", ");throw Error(`Cloudflare API error: ${c}`)}return a}getRootDomain(t){let e=t.replace(/\.$/,"").split(".");if(e.length>=2)return e.slice(-2).join(".");return t}async resolveZone(t){let e=t.replace(/\.$/,"").toLowerCase();if(this.configuredZoneId){let i=await this.resolveConfiguredZoneName();if(i&&(e===i||e.endsWith(`.${i}`)))return{id:this.configuredZoneId,name:i}}let r=this.getRootDomain(e),n=this.zoneCache.get(r);if(n)return{id:n,name:r};let s=await this.request("GET",`/zones?name=${encodeURIComponent(r)}`);if(!s.result||s.result.length===0)throw Error(`Zone not found for domain: ${r}. `+"If the API token is scoped to a single zone, set its zone id (CLOUDFLARE_ZONE_ID) — "+"zone lookup by name needs account-wide Zone:Read.");let o=s.result[0].id;return this.zoneCache.set(r,o),{id:o,name:s.result[0].name||r}}async resolveConfiguredZoneName(){if(!this.configuredZoneId)return;if(this.configuredZoneName)return this.configuredZoneName;try{let e=(await this.request("GET",`/zones/${this.configuredZoneId}`)).result?.name?.toLowerCase();if(!e)return;return this.configuredZoneName=e,this.zoneCache.set(e,this.configuredZoneId),e}catch{return}}async getZoneId(t){return(await this.resolveZone(t)).id}getFullRecordName(t,e){let r=t.replace(/\.$/,"");if(!r||r===e||r==="@")return e;if(r.endsWith(`.${e}`))return r;return`${r}.${e}`}toCloudflareRecord(t,e,r){let n={type:t.type,name:this.getFullRecordName(t.name,e),content:t.content||t.value||"",ttl:t.ttl||1},s=r??t.proxied;if(s!==void 0&&I.has(t.type)){if(n.proxied=s,s)n.ttl=1}if(t.type==="MX"&&t.priority!==void 0)n.priority=t.priority;if(t.type==="SRV"){let o=O(t);if(o)n.data=o,delete n.content,delete n.priority;else if(t.priority!==void 0)n.priority=t.priority}return n}fromCloudflareRecord(t){return{id:t.id,name:t.name,type:t.type,content:t.content,ttl:t.ttl,priority:t.priority,proxied:t.proxied}}async createRecord(t,e){try{let r=await this.resolveZone(t),n=this.toCloudflareRecord(e,r.name);return{success:!0,id:(await this.request("POST",`/zones/${r.id}/dns_records`,n)).result.id,message:"Record created successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async upsertRecord(t,e){try{let r=await this.resolveZone(t),n=this.getFullRecordName(e.name,r.name),o=(await this.request("GET",`/zones/${r.id}/dns_records?type=${e.type}&name=${encodeURIComponent(n)}`)).result?.[0],i=e.proxied??o?.proxied,a=this.toCloudflareRecord(e,r.name,i);if(o)return{success:!0,id:(await this.request("PUT",`/zones/${r.id}/dns_records/${o.id}`,a)).result.id,message:"Record updated successfully"};return{success:!0,id:(await this.request("POST",`/zones/${r.id}/dns_records`,a)).result.id,message:"Record created successfully"}}catch(r){return this.createRecord(t,e)}}async deleteRecord(t,e){try{let r=await this.resolveZone(t),n=r.id,s=this.getFullRecordName(e.name,r.name),o=await this.request("GET",`/zones/${n}/dns_records?type=${e.type}&name=${encodeURIComponent(s)}`);if(!o.result||o.result.length===0)return{success:!1,message:"Record not found"};let i=o.result.find((a)=>a.content===e.content);if(!i)return{success:!1,message:"Record with matching content not found"};return await this.request("DELETE",`/zones/${n}/dns_records/${i.id}`),{success:!0,message:"Record deleted successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async listRecords(t,e){try{let n=`/zones/${await this.getZoneId(t)}/dns_records?per_page=100`;if(e)n+=`&type=${e}`;let s=[],o=1,i=!0;while(i){let a=await this.request("GET",`${n}&page=${o}`);if(s.push(...a.result||[]),a.result_info)i=o<a.result_info.total_pages,o++;else i=!1}return{success:!0,records:s.map((a)=>this.fromCloudflareRecord(a))}}catch(r){return{success:!1,records:[],message:r instanceof Error?r.message:"Unknown error"}}}async canManageDomain(t){try{return await this.getZoneId(t),!0}catch{return!1}}async listDomains(){try{let t=[],e=1,r=!0;while(r){let n=await this.request("GET",`/zones?per_page=50&page=${e}`);if(t.push(...n.result||[]),n.result_info)r=e<n.result_info.total_pages,e++;else r=!1}return t.map((n)=>n.name)}catch{return[]}}async createZone(t,e={}){let r=t.replace(/\.$/,"").toLowerCase(),n=e.accountId??this.accountId;if(!n)throw Error(`Cannot create zone ${r}: no Cloudflare account id. Set CLOUDFLARE_ACCOUNT_ID, or pass accountId.`);try{let o=(await this.request("POST","/zones",{name:r,account:{id:n},jump_start:e.jumpStart??!1})).result;return this.zoneCache.set(o.name,o.id),{id:o.id,name:o.name,status:o.status,nameServers:o.name_servers??[],created:!0}}catch(s){let o=s instanceof Error?s.message:String(s);if(!/already exists|1061/i.test(o))throw s;let i=await this.getZoneDetails(r);if(!i)throw s;return{...i,created:!1}}}async getZoneDetails(t){try{let e=await this.getZoneId(t),r=await this.request("GET",`/zones/${e}`);return{id:r.result.id,name:r.result.name,status:r.result.status,nameServers:r.result.name_servers,paused:r.result.paused}}catch{return null}}async purgeCache(t,e){try{let r=await this.getZoneId(t),n={};if(e?.purgeEverything)n.purge_everything=!0;else{if(e?.files)n.files=e.files;if(e?.tags)n.tags=e.tags;if(e?.hosts)n.hosts=e.hosts}if(Object.keys(n).length===0)n.purge_everything=!0;return await this.request("POST",`/zones/${r}/purge_cache`,n),!0}catch{return!1}}async getRecordProxyStatus(t,e){try{let r=await this.resolveZone(t),n=r.id,s=this.getFullRecordName(e.name,r.name),o=await this.request("GET",`/zones/${n}/dns_records?type=${e.type}&name=${encodeURIComponent(s)}`);if(o.result&&o.result.length>0)return o.result.find((a)=>a.content===e.content)?.proxied??null;return null}catch{return null}}async setRecordProxyStatus(t,e,r){try{let n=await this.resolveZone(t),s=n.id,o=this.getFullRecordName(e.name,n.name),i=await this.request("GET",`/zones/${s}/dns_records?type=${e.type}&name=${encodeURIComponent(o)}`);if(!i.result||i.result.length===0)return!1;let a=i.result.find((c)=>c.content===e.content);if(!a)return!1;return await this.request("PATCH",`/zones/${s}/dns_records/${a.id}`,{proxied:r}),!0}catch{return!1}}async zoneIdFor(t){return this.getZoneId(t)}get account(){return this.accountId}async getZoneSettings(t){let e=await this.getZoneId(t),r=await this.request("GET",`/zones/${e}/settings`),n={};for(let s of r.result||[])n[s.id]=s.value;return n}async applyZoneSettings(t,e){let r=await this.getZoneId(t),n=await this.getZoneSettings(t).catch(()=>({})),s=[],o=[];for(let[i,a]of Object.entries(e)){if(a===void 0)continue;let c=n[i];if(c!==void 0&&T(c,a))continue;try{await this.request("PATCH",`/zones/${r}/settings/${i}`,{value:a}),s.push({id:i,from:c,to:a})}catch(d){o.push({id:i,error:d instanceof Error?d.message:String(d)})}}return{changed:s,failed:o}}async getPhaseRules(t,e){let r=await this.getZoneId(t);try{return(await this.request("GET",`/zones/${r}/rulesets/phases/${e}/entrypoint`)).result?.rules||[]}catch{return[]}}async putManagedPhaseRules(t,e,r){try{let n=await this.getZoneId(t),o=(await this.getPhaseRules(t,e)).filter((c)=>!(c.description||"").startsWith(S)),i=r.map((c)=>({...c,description:c.description?.startsWith(S)?c.description:`${S} ${c.description||e}`})),a=[...o,...i].map(({id:c,...d})=>d);return await this.request("PUT",`/zones/${n}/rulesets/phases/${e}/entrypoint`,{rules:a}),{success:!0}}catch(n){return{success:!1,message:n instanceof Error?n.message:String(n)}}}}function T(t,e){if(t===e)return!0;if(typeof t!==typeof e||t===null||e===null)return!1;if(typeof t!=="object")return!1;if(Array.isArray(t)||Array.isArray(e)){if(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)return!1;return t.every((s,o)=>T(s,e[o]))}let r=t,n=e;return Object.keys(n).every((s)=>T(r[s],n[s]))}function O(t){let e=(t.content||t.value||"").trim();if(t.weight!==void 0&&t.port!==void 0&&t.priority!==void 0&&e)return{priority:t.priority,weight:t.weight,port:t.port,target:x(e)};let r=e.split(/\s+/);if(r.length<4)return null;let[n,s,o]=r.slice(0,3).map(Number);if(![n,s,o].every(Number.isFinite))return null;return{priority:n,weight:s,port:o,target:x(r.slice(3).join(" "))}}function x(t){return t.replace(/\.$/,"")}var k=new Set(["A","AAAA","CNAME","ALIAS"]);function A(t){let e=t.trim().replace(/^"|"$/g,"").toLowerCase();if(e.startsWith("v=spf1"))return"v=spf1";if(e.startsWith("v=dmarc1"))return"v=dmarc1";return}function f(t){return t.trim().replace(/^"(.*)"$/s,"$1")}function R(t){return t.replace(/\.$/,"").toLowerCase()}function V(t,e){let r=R(e),n=(t??"@").trim();if(!n||n==="@")return r;let s=R(n);if(s===r||s.endsWith(`.${r}`))return s;return`${s}.${r}`}function z(t,e){return t.map((r)=>({...r,name:V(r.name,e),proxied:r.proxied??!1}))}function L(t,e){if(t.type!==e.type)return!1;if(R(t.name)!==R(e.name))return!1;if(k.has(e.type))return!0;if(e.type==="TXT"){let r=A(e.content);if(r)return A(f(t.content))===r;return f(t.content)===f(e.content)}return f(t.content)===f(e.content)}function q(t,e){if(f(t.content)!==f(e.content))return!1;if(e.priority!==void 0&&t.priority!==e.priority)return!1;if(e.proxied!==void 0&&t.proxied!==void 0&&t.proxied!==e.proxied)return!1;return!0}async function U(t){let{provider:e,zone:r,records:n}=t,s={outcomes:[],warnings:[]};if(n.length===0)return s;let o=await e.listRecords(r);if(!o.success)return s.warnings.push(`could not list ${r}: ${o.message||"unknown provider error"} — records not reconciled`),s;let i=o.records;for(let a of n){let c=i.filter((u)=>L(u,a));if(c.length>0&&c.every((u)=>q(u,a))){s.outcomes.push({record:a,action:"unchanged"});continue}let d={name:a.name,type:a.type,content:a.content,ttl:a.ttl??3600,...a.priority!==void 0?{priority:a.priority}:{},...a.proxied!==void 0?{proxied:a.proxied}:{}},m=a.type==="TXT"&&A(a.content)!==void 0;if(m)for(let u of c){let b=await e.deleteRecord(r,{name:u.name,type:u.type,content:u.content});if(!b.success)s.warnings.push(`could not remove superseded ${u.type} at ${u.name}: ${b.message||"unknown error"}`)}let g=m||c.length===0?await e.createRecord(r,d):await e.upsertRecord(r,d);if(g.success)s.outcomes.push({record:a,action:c.length>0?"updated":"created"});else s.outcomes.push({record:a,action:"failed",message:g.message})}for(let a of["MX"]){let c=new Set(n.filter((d)=>d.type===a).map((d)=>R(d.name)));for(let d of c){let m=new Set(n.filter((u)=>u.type===a&&R(u.name)===d).map((u)=>f(u.content).toLowerCase())),g=i.filter((u)=>u.type===a&&R(u.name)===d&&!m.has(f(u.content).toLowerCase()));for(let u of g)s.warnings.push(`${d} has an undeclared ${a} record (${u.content}) alongside the declared one — mail will be split between them. Remove it at the provider if it is stale.`)}}return s}class C{name="route53";client;hostedZoneCache=new Map;providedHostedZoneId;constructor(t="us-east-1",e){this.client=new y(t),this.providedHostedZoneId=e}getRootDomain(t){let e=t.replace(/\.$/,"").split(".");if(e.length>=2)return e.slice(-2).join(".");return t}async getHostedZoneId(t){if(this.providedHostedZoneId)return this.providedHostedZoneId;let e=this.getRootDomain(t),r=this.hostedZoneCache.get(e);if(r)return r;let n=await this.client.findHostedZoneForDomain(t);if(n){let s=n.Id.replace("/hostedzone/","");return this.hostedZoneCache.set(e,s),s}return null}normalizeName(t,e){let r=t.replace(/\.$/,""),n=e.replace(/\.$/,"");if(!n||n==="@")return`${r}.`;if(n===r||n.endsWith(`.${r}`))return`${n}.`;return`${n}.${r}.`}async createRecord(t,e){try{let r=await this.getHostedZoneId(t);if(!r)return{success:!1,message:`No hosted zone found for domain: ${t}`};let n=this.normalizeName(t,e.name),s=e.content;if(e.type==="TXT"&&!s.startsWith('"'))s=`"${s}"`;if(e.type==="MX"&&e.priority!==void 0)s=`${e.priority} ${s}`;return{success:!0,id:(await this.client.changeResourceRecordSets({HostedZoneId:r,ChangeBatch:{Comment:"Created by ts-cloud DNS provider",Changes:[{Action:"CREATE",ResourceRecordSet:{Name:n,Type:e.type,TTL:e.ttl||300,ResourceRecords:[{Value:s}]}}]}})).ChangeInfo?.Id,message:"Record created successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async upsertRecord(t,e){try{let r=await this.getHostedZoneId(t);if(!r)return{success:!1,message:`No hosted zone found for domain: ${t}`};let n=this.normalizeName(t,e.name),s=e.content;if(e.type==="TXT"&&!s.startsWith('"'))s=`"${s}"`;if(e.type==="MX"&&e.priority!==void 0)s=`${e.priority} ${s}`;return{success:!0,id:(await this.client.changeResourceRecordSets({HostedZoneId:r,ChangeBatch:{Comment:"Upserted by ts-cloud DNS provider",Changes:[{Action:"UPSERT",ResourceRecordSet:{Name:n,Type:e.type,TTL:e.ttl||300,ResourceRecords:[{Value:s}]}}]}})).ChangeInfo?.Id,message:"Record upserted successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async deleteRecord(t,e){try{let r=await this.getHostedZoneId(t);if(!r)return{success:!1,message:`No hosted zone found for domain: ${t}`};let n=this.normalizeName(t,e.name),s=e.content;if(e.type==="TXT"&&!s.startsWith('"'))s=`"${s}"`;if(e.type==="MX"&&e.priority!==void 0)s=`${e.priority} ${s}`;return await this.client.changeResourceRecordSets({HostedZoneId:r,ChangeBatch:{Comment:"Deleted by ts-cloud DNS provider",Changes:[{Action:"DELETE",ResourceRecordSet:{Name:n,Type:e.type,TTL:e.ttl||300,ResourceRecords:[{Value:s}]}}]}}),{success:!0,message:"Record deleted successfully"}}catch(r){return{success:!1,message:r instanceof Error?r.message:"Unknown error"}}}async listRecords(t,e){try{let r=await this.getHostedZoneId(t);if(!r)return{success:!1,records:[],message:`No hosted zone found for domain: ${t}`};let n=await this.client.listResourceRecordSets({HostedZoneId:r,StartRecordType:e}),s=[];for(let o of n.ResourceRecordSets){if(e&&o.Type!==e)continue;if(o.AliasTarget)continue;for(let i of o.ResourceRecords||[]){let a=i.Value,c;if(o.Type==="MX"){let d=a.split(" ");if(d.length>=2)c=Number.parseInt(d[0],10),a=d.slice(1).join(" ")}if(o.Type==="TXT"&&a.startsWith('"')&&a.endsWith('"'))a=a.slice(1,-1);s.push({name:o.Name.replace(/\.$/,""),type:o.Type,content:a,ttl:o.TTL,priority:c})}}return{success:!0,records:s}}catch(r){return{success:!1,records:[],message:r instanceof Error?r.message:"Unknown error"}}}async canManageDomain(t){return await this.getHostedZoneId(t)!==null}async listDomains(){try{return(await this.client.listHostedZones()).HostedZones.map((e)=>e.Name.replace(/\.$/,""))}catch{return[]}}getRoute53Client(){return this.client}async createAliasRecord(t){try{let e=await this.getHostedZoneId(t.domain);if(!e)return{success:!1,message:`No hosted zone found for domain: ${t.domain}`};return{success:!0,id:(await this.client.createAliasRecord({HostedZoneId:e,Name:this.normalizeName(t.domain,t.name),TargetHostedZoneId:t.targetHostedZoneId,TargetDNSName:t.targetDnsName,EvaluateTargetHealth:t.evaluateTargetHealth,Type:t.type})).ChangeInfo?.Id,message:"Alias record created successfully"}}catch(e){return{success:!1,message:e instanceof Error?e.message:"Unknown error"}}}async createCloudFrontAlias(t){return this.createAliasRecord({domain:t.domain,name:t.name,targetHostedZoneId:y.CloudFrontHostedZoneId,targetDnsName:t.cloudFrontDomainName,evaluateTargetHealth:!1})}async createAlbAlias(t){let e=y.ALBHostedZoneIds[t.region];if(!e)return{success:!1,message:`Unknown region for ALB: ${t.region}`};return this.createAliasRecord({domain:t.domain,name:t.name,targetHostedZoneId:e,targetDnsName:t.albDnsName,evaluateTargetHealth:!0})}}async function j(t,e){let r=[],n,s;for(;;){let o=await t.listResourceRecordSets({HostedZoneId:e,StartRecordName:n,StartRecordType:s,MaxItems:"100"});if(r.push(...o.ResourceRecordSets),!o.IsTruncated)break;if(n=o.NextRecordName,s=o.NextRecordType,!n)break}return r}function l(t){return t.replace(/\.$/,"").toLowerCase()}function F(t){let e=t.match(/"(?:[^"\\]|\\.)*"/g);if(!e)return t;return e.map((r)=>r.slice(1,-1).replace(/\\(.)/g,"$1")).join("")}function G(t,e){let r=l(e),n=[],s=[],o=[],i=new Set;for(let a of t){let c=l(a.Name),d=a.Type;if(d==="SOA"||d==="NS"&&c===r){s.push({name:c,type:d,reason:"owned by the destination provider"});continue}if(a.SetIdentifier){s.push({name:c,type:d,reason:`routing policy record (SetIdentifier=${a.SetIdentifier}) has no equivalent — recreate by hand`}),o.push(`${d} ${c} is part of a Route53 routing policy and was NOT migrated`);continue}if(a.AliasTarget){if(i.has(c))continue;i.add(c);let m=l(a.AliasTarget.DNSName);if(n.push({name:c,type:"CNAME",content:m,ttl:300,translatedFrom:`${d} ALIAS → ${m}`}),a.AliasTarget.EvaluateTargetHealth)o.push(`${c} was an ALIAS with health evaluation enabled; the CNAME that replaces it has no health check`);continue}for(let m of a.ResourceRecords||[]){let g=W(c,d,m.Value,a.TTL);if("reason"in g){s.push({name:c,type:d,reason:g.reason}),o.push(`${d} ${c}: ${g.reason}`);continue}n.push(g)}}return{zone:r,records:n,skipped:s,warnings:o}}function W(t,e,r,n){let s={name:t,ttl:n};switch(e){case"A":case"AAAA":case"CNAME":case"PTR":return{...s,type:e==="PTR"?"CNAME":e,content:l(r)};case"TXT":return{...s,type:"TXT",content:F(r)};case"MX":{let[o,...i]=r.trim().split(/\s+/);if(!i.length)return{reason:`malformed MX value "${r}"`};return{...s,type:"MX",content:l(i.join(" ")),priority:Number(o)}}case"SRV":{let o=r.trim().split(/\s+/);if(o.length<4)return{reason:`malformed SRV value "${r}"`};let[i,a,c]=o.slice(0,3).map(Number);return{...s,type:"SRV",content:l(o.slice(3).join(" ")),priority:i,weight:a,port:c}}case"NS":return{...s,type:"NS",content:l(r)};case"CAA":return{...s,type:"CAA",content:r.trim()};default:return{reason:`unsupported record type ${e}`}}}async function H(t,e){let r=[],n=[];for(let s of e.records){let o=await t.upsertRecord(e.zone,{...s,proxied:!1});if(o.success)r.push(s);else n.push({record:s,message:o.message||"unknown provider error"})}return{applied:r,failed:n}}async function K(t,e){let r=await t.listRecords(e.zone),n=[],s=[],o=new Map;for(let i of r.records||[]){let a=`${l(i.name)}|${i.type}`,c=o.get(a)??[];c.push(l(String(i.content))),o.set(a,c)}for(let i of e.records){let a=o.get(`${l(i.name)}|${i.type}`),c=l(i.content);if(a?.some((d)=>d===c||d.includes(c)||c.includes(d)))n.push(i);else s.push({record:i,found:a?.join(", ")})}return{matched:n,missing:s,ok:s.length===0}}class P{client;region;constructor(t="us-east-1"){this.client=new M,this.region=t}async requestCertificate(t){let e={DomainName:t.DomainName,ValidationMethod:t.ValidationMethod||"DNS"};if(t.SubjectAlternativeNames)e.SubjectAlternativeNames=t.SubjectAlternativeNames;return{CertificateArn:(await this.client.request({service:"acm",region:this.region,method:"POST",path:"/",headers:{"content-type":"application/x-amz-json-1.1","x-amz-target":"CertificateManager.RequestCertificate"},body:JSON.stringify(e)})).CertificateArn||""}}async describeCertificate(t){let r=(await this.client.request({service:"acm",region:this.region,method:"POST",path:"/",headers:{"content-type":"application/x-amz-json-1.1","x-amz-target":"CertificateManager.DescribeCertificate"},body:JSON.stringify({CertificateArn:t.CertificateArn})})).Certificate||{};return{CertificateArn:r.CertificateArn||"",DomainName:r.DomainName||"",SubjectAlternativeNames:r.SubjectAlternativeNames,Status:r.Status||"PENDING_VALIDATION",Type:r.Type,DomainValidationOptions:r.DomainValidationOptions?.map((n)=>({DomainName:n.DomainName,ValidationDomain:n.ValidationDomain,ValidationStatus:n.ValidationStatus,ResourceRecord:n.ResourceRecord?{Name:n.ResourceRecord.Name,Type:n.ResourceRecord.Type,Value:n.ResourceRecord.Value}:void 0,ValidationMethod:n.ValidationMethod})),CreatedAt:r.CreatedAt,IssuedAt:r.IssuedAt,NotBefore:r.NotBefore,NotAfter:r.NotAfter}}async listCertificates(t){let e={};if(t?.CertificateStatuses)e.CertificateStatuses=t.CertificateStatuses;if(t?.MaxItems)e.MaxItems=t.MaxItems;if(t?.NextToken)e.NextToken=t.NextToken;let r=await this.client.request({service:"acm",region:this.region,method:"POST",path:"/",headers:{"content-type":"application/x-amz-json-1.1","x-amz-target":"CertificateManager.ListCertificates"},body:JSON.stringify(e)});return{CertificateSummaryList:(r.CertificateSummaryList||[]).map((n)=>({CertificateArn:n.CertificateArn,DomainName:n.DomainName})),NextToken:r.NextToken}}async deleteCertificate(t){await this.client.request({service:"acm",region:this.region,method:"POST",path:"/",headers:{"content-type":"application/x-amz-json-1.1","x-amz-target":"CertificateManager.DeleteCertificate"},body:JSON.stringify({CertificateArn:t.CertificateArn})})}async listTagsForCertificate(t){return{Tags:(await this.client.request({service:"acm",region:this.region,method:"POST",path:"/",headers:{"content-type":"application/x-amz-json-1.1","x-amz-target":"CertificateManager.ListTagsForCertificate"},body:JSON.stringify({CertificateArn:t.CertificateArn})})).Tags||[]}}async addTagsToCertificate(t){await this.client.request({service:"acm",region:this.region,method:"POST",path:"/",headers:{"content-type":"application/x-amz-json-1.1","x-amz-target":"CertificateManager.AddTagsToCertificate"},body:JSON.stringify({CertificateArn:t.CertificateArn,Tags:t.Tags})})}async resendValidationEmail(t){await this.client.request({service:"acm",region:this.region,method:"POST",path:"/",headers:{"content-type":"application/x-amz-json-1.1","x-amz-target":"CertificateManager.ResendValidationEmail"},body:JSON.stringify({CertificateArn:t.CertificateArn,Domain:t.Domain,ValidationDomain:t.ValidationDomain})})}async findCertificateByDomain(t){let r=(await this.listCertificates({CertificateStatuses:["ISSUED"]})).CertificateSummaryList.find((n)=>n.DomainName===t||n.DomainName===`*.${t.split(".").slice(1).join(".")}`);if(!r)return null;return this.describeCertificate({CertificateArn:r.CertificateArn})}async waitForCertificateValidation(t,e=60,r=30000){for(let n=0;n<e;n++){let s=await this.describeCertificate({CertificateArn:t});if(s.Status==="ISSUED")return s;if(s.Status==="FAILED"||s.Status==="VALIDATION_TIMED_OUT")return null;await new Promise((o)=>setTimeout(o,r))}return null}async getDnsValidationRecords(t){let e=await this.describeCertificate({CertificateArn:t});if(!e.DomainValidationOptions)return[];return e.DomainValidationOptions.filter((r)=>r.ResourceRecord&&r.ValidationMethod==="DNS").map((r)=>({domainName:r.DomainName,recordName:r.ResourceRecord.Name,recordType:r.ResourceRecord.Type,recordValue:r.ResourceRecord.Value}))}async requestCertificateWithSans(t){let e=new Set;if(e.add(t.DomainName),t.IncludeWww!==!1)e.add(`www.${t.DomainName}`);if(t.IncludeWildcard)e.add(`*.${t.DomainName}`);if(t.AdditionalSans)for(let r of t.AdditionalSans)e.add(r);return this.requestCertificate({DomainName:t.DomainName,SubjectAlternativeNames:Array.from(e),ValidationMethod:"DNS"})}async isCertificateValidForDomain(t,e){let r=await this.describeCertificate({CertificateArn:t});if(r.Status!=="ISSUED")return!1;if(r.DomainName===e)return!0;if(r.DomainName?.startsWith("*.")){let n=r.DomainName.slice(2),s=e.split("."),o=n.split(".");if(s.slice(-o.length).join(".")===n)return!0}if(r.SubjectAlternativeNames)for(let n of r.SubjectAlternativeNames){if(n===e)return!0;if(n.startsWith("*.")){let s=n.slice(2),o=e.split("."),i=s.split(".");if(o.slice(-i.length).join(".")===s)return!0}}return!1}}class X{acm;route53;dnsProvider;constructor(t="us-east-1",e){if(this.acm=new P(t),this.route53=new y,e&&e.provider!=="route53")this.dnsProvider=p(e)}async requestAndValidate(t){let{domainName:e,hostedZoneId:r,subjectAlternativeNames:n=[],waitForValidation:s=!1,maxWaitMinutes:o=30}=t;if(!this.dnsProvider&&!r)throw Error("Either hostedZoneId or external DNS provider configuration is required");let{CertificateArn:i}=await this.acm.requestCertificate({DomainName:e,SubjectAlternativeNames:n.length>0?[e,...n]:void 0,ValidationMethod:"DNS"});await this.waitForValidationOptions(i);let a=await this.acm.getDnsValidationRecords(i);if(this.dnsProvider)for(let c of a){let d=await this.dnsProvider.upsertRecord(e,{name:c.recordName,type:c.recordType,content:c.recordValue,ttl:300});if(!d.success)console.warn(`Failed to create validation record for ${c.domainName}: ${d.message}`)}else if(r)for(let c of a)await this.route53.changeResourceRecordSets({HostedZoneId:r,ChangeBatch:{Comment:`ACM DNS validation for ${c.domainName}`,Changes:[{Action:"UPSERT",ResourceRecordSet:{Name:c.recordName,Type:c.recordType,TTL:300,ResourceRecords:[{Value:c.recordValue}]}}]}});if(s){if(!await this.acm.waitForCertificateValidation(i,o*2,30000))throw Error(`Certificate validation timed out after ${o} minutes`)}return{certificateArn:i,validationRecords:a}}async waitForValidationOptions(t,e=30){for(let r=0;r<e;r++){let n=await this.acm.describeCertificate({CertificateArn:t});if(n.DomainValidationOptions&&n.DomainValidationOptions.length>0&&n.DomainValidationOptions[0].ResourceRecord)return;await new Promise((s)=>setTimeout(s,2000))}throw Error("Timeout waiting for DNS validation options")}async createValidationRecords(t){let{certificateArn:e,hostedZoneId:r,domain:n}=t;if(!this.dnsProvider&&!r)throw Error("Either hostedZoneId or external DNS provider configuration is required");let s=await this.acm.getDnsValidationRecords(e),o=[];if(this.dnsProvider){let i=n||s[0]?.domainName;for(let a of s){let c=await this.dnsProvider.upsertRecord(i,{name:a.recordName,type:a.recordType,content:a.recordValue,ttl:300});o.push({...a,changeId:c.success?c.id:void 0})}}else if(r)for(let i of s){let a=await this.route53.changeResourceRecordSets({HostedZoneId:r,ChangeBatch:{Comment:`ACM DNS validation for ${i.domainName}`,Changes:[{Action:"UPSERT",ResourceRecordSet:{Name:i.recordName,Type:i.recordType,TTL:300,ResourceRecords:[{Value:i.recordValue}]}}]}});o.push({...i,changeId:a.ChangeInfo?.Id})}return o}async deleteValidationRecords(t){let{certificateArn:e,hostedZoneId:r,domain:n}=t,s=await this.acm.getDnsValidationRecords(e);if(this.dnsProvider){let o=n||s[0]?.domainName;for(let i of s)try{await this.dnsProvider.deleteRecord(o,{name:i.recordName,type:i.recordType,content:i.recordValue})}catch{}}else if(r)for(let o of s)try{await this.route53.changeResourceRecordSets({HostedZoneId:r,ChangeBatch:{Comment:`Cleanup ACM DNS validation for ${o.domainName}`,Changes:[{Action:"DELETE",ResourceRecordSet:{Name:o.recordName,Type:o.recordType,TTL:300,ResourceRecords:[{Value:o.recordValue}]}}]}})}catch{}}async findOrCreateCertificate(t){let{domainName:e,hostedZoneId:r,subjectAlternativeNames:n,waitForValidation:s=!0}=t;if(!this.dnsProvider&&!r)throw Error("Either hostedZoneId or external DNS provider configuration is required");let o=await this.acm.findCertificateByDomain(e);if(o&&o.Status==="ISSUED")return{certificateArn:o.CertificateArn,isNew:!1};let{certificateArn:i}=await this.requestAndValidate({domainName:e,hostedZoneId:r,subjectAlternativeNames:n,waitForValidation:s});return{certificateArn:i,isNew:!0}}hasExternalDnsProvider(){return this.dnsProvider!==void 0}getDnsProviderName(){return this.dnsProvider?.name||"route53"}}class D{acm;dnsProvider;constructor(t,e="us-east-1"){if(this.acm=new P(e),"provider"in t)this.dnsProvider=p(t);else this.dnsProvider=t}getProvider(){return this.dnsProvider}async requestAndValidate(t){let{domainName:e,subjectAlternativeNames:r=[],waitForValidation:n=!1,maxWaitMinutes:s=30}=t,{CertificateArn:o}=await this.acm.requestCertificate({DomainName:e,SubjectAlternativeNames:r.length>0?[e,...r]:void 0,ValidationMethod:"DNS"});await this.waitForValidationOptions(o);let i=await this.acm.getDnsValidationRecords(o);for(let c of i){let d=await this.dnsProvider.upsertRecord(e,{name:c.recordName,type:c.recordType,content:c.recordValue,ttl:300});if(!d.success)console.warn(`Failed to create validation record for ${c.domainName}: ${d.message}`)}let a="pending";if(n)a=(await this.acm.waitForCertificateValidation(o,s*2,30000))?.Status==="ISSUED"?"issued":"failed";return{certificateArn:o,validationRecords:i.map((c)=>({domainName:c.domainName,recordName:c.recordName,recordType:c.recordType,recordValue:c.recordValue})),isNew:!0,status:a}}async createValidationRecords(t){let{certificateArn:e,domain:r}=t,n=[],s=await this.acm.getDnsValidationRecords(e);for(let o of s){let i=await this.dnsProvider.upsertRecord(r,{name:o.recordName,type:o.recordType,content:o.recordValue,ttl:300});if(!i.success)n.push(`Failed to create record for ${o.domainName}: ${i.message}`)}return{success:n.length===0,records:s.map((o)=>({domainName:o.domainName,recordName:o.recordName,recordType:o.recordType,recordValue:o.recordValue})),errors:n}}async deleteValidationRecords(t){let{certificateArn:e,domain:r}=t,n=[],s=await this.acm.getDnsValidationRecords(e);for(let o of s){let i=await this.dnsProvider.deleteRecord(r,{name:o.recordName,type:o.recordType,content:o.recordValue});if(!i.success)n.push(`Failed to delete record for ${o.domainName}: ${i.message}`)}return{success:n.length===0,errors:n}}async findOrCreateCertificate(t){let{domainName:e,subjectAlternativeNames:r=[],waitForValidation:n=!0,maxWaitMinutes:s}=t,o=await this.acm.findCertificateByDomain(e);if(o&&o.Status==="ISSUED"){let i=o.SubjectAlternativeNames||[o.DomainName],a=i.some((d)=>d===`*.${e}`);if(r.every((d)=>i.includes(d)||a))return{certificateArn:o.CertificateArn,validationRecords:[],isNew:!1,status:"issued"};console.log("Existing certificate doesn't cover all required SANs, requesting new certificate...")}return this.requestAndValidate({domainName:e,subjectAlternativeNames:r,waitForValidation:n,maxWaitMinutes:s})}async requestCertificateWithCommonSans(t){let{domainName:e,includeWww:r=!0,includeWildcard:n=!1,additionalSans:s=[],waitForValidation:o=!1}=t,i=[];if(r)i.push(`www.${e}`);if(n)i.push(`*.${e}`);return i.push(...s),this.requestAndValidate({domainName:e,subjectAlternativeNames:i,waitForValidation:o})}async waitForValidationOptions(t,e=30){for(let r=0;r<e;r++){let n=await this.acm.describeCertificate({CertificateArn:t});if(n.DomainValidationOptions&&n.DomainValidationOptions.length>0&&n.DomainValidationOptions[0].ResourceRecord)return;await new Promise((s)=>setTimeout(s,2000))}throw Error("Timeout waiting for DNS validation options")}async getCertificateStatus(t){let e=await this.acm.describeCertificate({CertificateArn:t});return{status:e.Status,domainValidations:(e.DomainValidationOptions||[]).map((r)=>({domain:r.DomainName,status:r.ValidationStatus||"UNKNOWN"}))}}}function B(t,e,r){return new D({provider:"porkbun",apiKey:t,secretKey:e},r)}function Y(t,e,r,n){return new D({provider:"godaddy",apiKey:t,apiSecret:e,environment:n},r)}function J(t,e,r){return new D({provider:"route53",region:t,hostedZoneId:e},r||t)}function p(t){switch(t.provider){case"route53":return new C(t.region,t.hostedZoneId);case"porkbun":return new h(t.apiKey,t.secretKey);case"godaddy":return new v(t.apiKey,t.apiSecret,t.environment);case"cloudflare":return new w(t.apiToken,{zoneId:t.zoneId,accountId:t.accountId});default:throw Error(`Unknown DNS provider: ${t.provider}`)}}async function De(t,e){for(let r of e){let n=p(r);if(await n.canManageDomain(t))return n}return null}class Z{providers=new Map;configs=[];addConfig(t){return this.configs.push(t),this}addRoute53(t,e){return this.configs.push({provider:"route53",region:t,hostedZoneId:e}),this}addPorkbun(t,e){return this.configs.push({provider:"porkbun",apiKey:t,secretKey:e}),this}addGoDaddy(t,e,r){return this.configs.push({provider:"godaddy",apiKey:t,apiSecret:e,environment:r}),this}addCloudflare(t,e={}){return this.configs.push({provider:"cloudflare",apiToken:t,zoneId:e.zoneId,accountId:e.accountId}),this}loadFromEnv(){if(process.env.AWS_ACCESS_KEY_ID||process.env.AWS_REGION)this.addRoute53(process.env.AWS_REGION);let t=process.env.PORKBUN_API_KEY,e=process.env.PORKBUN_SECRET_KEY;if(t&&e)this.addPorkbun(t,e);let r=process.env.GODADDY_API_KEY,n=process.env.GODADDY_API_SECRET;if(r&&n){let o=process.env.GODADDY_ENVIRONMENT;this.addGoDaddy(r,n,o)}let s=process.env.CLOUDFLARE_API_TOKEN;if(s)this.addCloudflare(s,{zoneId:process.env.CLOUDFLARE_ZONE_ID,accountId:process.env.CLOUDFLARE_ACCOUNT_ID});return this}getProvider(t){let e=this.providers.get(t);if(e)return e;let r=this.configs.find((s)=>s.provider===t);if(!r)return null;let n=p(r);return this.providers.set(t,n),n}async getProviderForDomain(t){for(let e of this.configs){let r=p(e);if(await r.canManageDomain(t))return r}return null}getAllProviders(){return this.configs.map((t)=>p(t))}}var ve=new Z;
2
2
  export{I as vf,h as wf,v as xf,S as yf,w as zf,A as Af,V as Bf,z as Cf,U as Df,C as Ef,j as Ff,G as Gf,H as Hf,K as If,D as Jf,B as Kf,Y as Lf,J as Mf,p as Nf,De as Of,Z as Pf,ve as Qf,P as Rf,X as Sf};
@@ -34,4 +34,4 @@ fi
34
34
  mv "${s}.new" "${s}"
35
35
  echo "ts-cloud: WAF config installed (mode: ${n.mode})"
36
36
  `}function _(e,r){return e.map((t)=>({projectId:r.projectId,environmentId:r.environmentId,resourceId:r.resourceId,kind:"event",source:"zig-waf",name:t.action==="blocked"?"waf.blocked":"waf.matched",timestamp:t.timestamp,value:1,host:t.host,pathTemplate:t.path,method:t.method,attributes:{ruleId:t.ruleId??null,anomalyScore:t.anomalyScore,action:t.action,messages:t.messages.slice(0,5)}}))}
37
- export{l as We,g as Xe,R as Ye,v as Ze,I as _e,_ as $e};
37
+ export{l as kl,g as ll,R as ml,v as nl,I as ol,_ as pl};