@geekmidas/cli 10.0.0-alpha.15 → 10.0.0-alpha.151

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 (438) hide show
  1. package/README.md +313 -380
  2. package/bin/adjacent-tsconfig.mjs +46 -8
  3. package/bin/gkm.mjs +11 -3
  4. package/bin/owning-tsconfig-jsx-register.mjs +18 -0
  5. package/bin/owning-tsconfig-jsx.mjs +108 -0
  6. package/dist/EndpointGenerator-CusLH-9S.mjs +1037 -0
  7. package/dist/EndpointGenerator-CusLH-9S.mjs.map +1 -0
  8. package/dist/EndpointGenerator-DyLMYClE.cjs +1096 -0
  9. package/dist/EndpointGenerator-DyLMYClE.cjs.map +1 -0
  10. package/dist/GoDaddyProvider-BZYq0-nV.cjs +412 -0
  11. package/dist/GoDaddyProvider-BZYq0-nV.cjs.map +1 -0
  12. package/dist/GoDaddyProvider-D-8GW8cP.mjs +412 -0
  13. package/dist/GoDaddyProvider-D-8GW8cP.mjs.map +1 -0
  14. package/dist/{HostingerProvider-BZFGYYVA.cjs → HostingerProvider-BxRR2ibx.cjs} +23 -9
  15. package/dist/HostingerProvider-BxRR2ibx.cjs.map +1 -0
  16. package/dist/{HostingerProvider-BY26bWwB.mjs → HostingerProvider-C-C4aiKF.mjs} +23 -9
  17. package/dist/HostingerProvider-C-C4aiKF.mjs.map +1 -0
  18. package/dist/LegacyStateStore-BFkNiBxC.mjs +124 -0
  19. package/dist/LegacyStateStore-BFkNiBxC.mjs.map +1 -0
  20. package/dist/LegacyStateStore-DYaamZqR.cjs +124 -0
  21. package/dist/LegacyStateStore-DYaamZqR.cjs.map +1 -0
  22. package/dist/LocalStateStore-7pP4naiB.mjs +167 -0
  23. package/dist/LocalStateStore-7pP4naiB.mjs.map +1 -0
  24. package/dist/LocalStateStore-C0JSjyCg.cjs +178 -0
  25. package/dist/LocalStateStore-C0JSjyCg.cjs.map +1 -0
  26. package/dist/OpenApiTsGenerator-BTMuu1WS.mjs +534 -0
  27. package/dist/OpenApiTsGenerator-BTMuu1WS.mjs.map +1 -0
  28. package/dist/OpenApiTsGenerator-CI-tceXV.cjs +539 -0
  29. package/dist/OpenApiTsGenerator-CI-tceXV.cjs.map +1 -0
  30. package/dist/{Route53Provider-Cvj40A8I.mjs → Route53Provider-Di_SD9CF.mjs} +3 -3
  31. package/dist/Route53Provider-Di_SD9CF.mjs.map +1 -0
  32. package/dist/{Route53Provider-DVILBsvV.cjs → Route53Provider-emLuQHVw.cjs} +3 -3
  33. package/dist/Route53Provider-emLuQHVw.cjs.map +1 -0
  34. package/dist/S3StateStore-BnmbFco-.cjs +222 -0
  35. package/dist/S3StateStore-BnmbFco-.cjs.map +1 -0
  36. package/dist/S3StateStore-Dzyuiy3V.mjs +223 -0
  37. package/dist/S3StateStore-Dzyuiy3V.mjs.map +1 -0
  38. package/dist/SSMStateStore-BLbjoEFc.cjs +204 -0
  39. package/dist/SSMStateStore-BLbjoEFc.cjs.map +1 -0
  40. package/dist/SSMStateStore-BcNH7efc.mjs +205 -0
  41. package/dist/SSMStateStore-BcNH7efc.mjs.map +1 -0
  42. package/dist/SubscriberGenerator-BNJyPmXJ.cjs +848 -0
  43. package/dist/SubscriberGenerator-BNJyPmXJ.cjs.map +1 -0
  44. package/dist/SubscriberGenerator-CzPrixYu.mjs +783 -0
  45. package/dist/SubscriberGenerator-CzPrixYu.mjs.map +1 -0
  46. package/dist/add-SHsas9Yu.mjs +711 -0
  47. package/dist/add-SHsas9Yu.mjs.map +1 -0
  48. package/dist/add-moAE6nV4.cjs +713 -0
  49. package/dist/add-moAE6nV4.cjs.map +1 -0
  50. package/dist/appPorts-BoXMwolc.mjs +249 -0
  51. package/dist/appPorts-BoXMwolc.mjs.map +1 -0
  52. package/dist/appPorts-IW-OZmRi.cjs +296 -0
  53. package/dist/appPorts-IW-OZmRi.cjs.map +1 -0
  54. package/dist/apps-BOgA6AcI.mjs +5534 -0
  55. package/dist/apps-BOgA6AcI.mjs.map +1 -0
  56. package/dist/apps-DkxHjd59.cjs +6148 -0
  57. package/dist/apps-DkxHjd59.cjs.map +1 -0
  58. package/dist/aws-8QQ8n-t6.mjs +89 -0
  59. package/dist/aws-8QQ8n-t6.mjs.map +1 -0
  60. package/dist/aws-DY9NqQIT.cjs +100 -0
  61. package/dist/aws-DY9NqQIT.cjs.map +1 -0
  62. package/dist/awsStore-Bx5nCFnS.mjs +121 -0
  63. package/dist/awsStore-Bx5nCFnS.mjs.map +1 -0
  64. package/dist/awsStore-u3ehhMoY.cjs +138 -0
  65. package/dist/awsStore-u3ehhMoY.cjs.map +1 -0
  66. package/dist/{backup-provisioner-DIVCbfee.mjs → backup-provisioner-C8DnCmxK.mjs} +2 -2
  67. package/dist/backup-provisioner-C8DnCmxK.mjs.map +1 -0
  68. package/dist/{backup-provisioner-BmhIO_Yr.cjs → backup-provisioner-oDEsPj02.cjs} +2 -2
  69. package/dist/backup-provisioner-oDEsPj02.cjs.map +1 -0
  70. package/dist/backups/runner.cjs +519 -0
  71. package/dist/backups/runner.cjs.map +1 -0
  72. package/dist/backups/runner.d.cts +102 -0
  73. package/dist/backups/runner.d.cts.map +1 -0
  74. package/dist/backups/runner.d.mts +102 -0
  75. package/dist/backups/runner.d.mts.map +1 -0
  76. package/dist/backups/runner.mjs +506 -0
  77. package/dist/backups/runner.mjs.map +1 -0
  78. package/dist/{bundler-BeNDZdHQ.cjs → bundler-D0spRLb-.cjs} +59 -14
  79. package/dist/bundler-D0spRLb-.cjs.map +1 -0
  80. package/dist/{bundler-BodTL4kf.mjs → bundler-Dy-Dfchf.mjs} +59 -14
  81. package/dist/bundler-Dy-Dfchf.mjs.map +1 -0
  82. package/dist/cli-BmCyUTZf.cjs +71 -0
  83. package/dist/cli-BmCyUTZf.cjs.map +1 -0
  84. package/dist/cli-BpT_gg4n.mjs +71 -0
  85. package/dist/cli-BpT_gg4n.mjs.map +1 -0
  86. package/dist/compose-0HkjQywT.cjs +3046 -0
  87. package/dist/compose-0HkjQywT.cjs.map +1 -0
  88. package/dist/compose-B3OOowfE.mjs +1560 -0
  89. package/dist/compose-B3OOowfE.mjs.map +1 -0
  90. package/dist/compose-BIXEPrGA.mjs +2957 -0
  91. package/dist/compose-BIXEPrGA.mjs.map +1 -0
  92. package/dist/compose-BP8OeV7P.cjs +1919 -0
  93. package/dist/compose-BP8OeV7P.cjs.map +1 -0
  94. package/dist/config-BLrAd7Of.mjs +659 -0
  95. package/dist/config-BLrAd7Of.mjs.map +1 -0
  96. package/dist/config-CRk2vdSp.d.mts +268 -0
  97. package/dist/config-CRk2vdSp.d.mts.map +1 -0
  98. package/dist/config-juUyBlb1.cjs +772 -0
  99. package/dist/config-juUyBlb1.cjs.map +1 -0
  100. package/dist/config-oBgsbLip.d.cts +268 -0
  101. package/dist/config-oBgsbLip.d.cts.map +1 -0
  102. package/dist/config.cjs +11 -3
  103. package/dist/config.d.cts +4 -117
  104. package/dist/config.d.mts +4 -117
  105. package/dist/config.mjs +3 -3
  106. package/dist/credentialSchemas-BAklWDna.cjs +271 -0
  107. package/dist/credentialSchemas-BAklWDna.cjs.map +1 -0
  108. package/dist/credentialSchemas-mz9QZTYh.mjs +236 -0
  109. package/dist/credentialSchemas-mz9QZTYh.mjs.map +1 -0
  110. package/dist/credentials-B6ZwGsy-.cjs +2272 -0
  111. package/dist/credentials-B6ZwGsy-.cjs.map +1 -0
  112. package/dist/credentials-DRfP9aG7.mjs +1817 -0
  113. package/dist/credentials-DRfP9aG7.mjs.map +1 -0
  114. package/dist/databases-DawSdqBI.cjs +703 -0
  115. package/dist/databases-DawSdqBI.cjs.map +1 -0
  116. package/dist/databases-mzSUFBTw.mjs +588 -0
  117. package/dist/databases-mzSUFBTw.mjs.map +1 -0
  118. package/dist/define-6poNqm5O.mjs +106 -0
  119. package/dist/define-6poNqm5O.mjs.map +1 -0
  120. package/dist/define-crmMcXFS.cjs +153 -0
  121. package/dist/define-crmMcXFS.cjs.map +1 -0
  122. package/dist/deploy/public.cjs +211 -0
  123. package/dist/deploy/public.cjs.map +1 -0
  124. package/dist/deploy/public.d.cts +647 -0
  125. package/dist/deploy/public.d.cts.map +1 -0
  126. package/dist/deploy/public.d.mts +647 -0
  127. package/dist/deploy/public.d.mts.map +1 -0
  128. package/dist/deploy/public.mjs +144 -0
  129. package/dist/deploy/public.mjs.map +1 -0
  130. package/dist/deploy/sniffer-envparser-worker.cjs +54 -0
  131. package/dist/deploy/sniffer-envparser-worker.cjs.map +1 -0
  132. package/dist/deploy/sniffer-envparser-worker.d.cts +1 -0
  133. package/dist/deploy/sniffer-envparser-worker.d.mts +1 -0
  134. package/dist/deploy/sniffer-envparser-worker.mjs +55 -0
  135. package/dist/deploy/sniffer-envparser-worker.mjs.map +1 -0
  136. package/dist/deploy/sniffer-hooks.cjs +1 -1
  137. package/dist/deploy/sniffer-hooks.mjs +1 -1
  138. package/dist/deploy/sniffer-loader.cjs +2 -2
  139. package/dist/deploy/sniffer-loader.mjs +1 -1
  140. package/dist/deploy/sniffer-routes-worker.cjs +2 -2
  141. package/dist/deploy/sniffer-routes-worker.mjs +1 -1
  142. package/dist/deploy-BgOujGGL.mjs +3836 -0
  143. package/dist/deploy-BgOujGGL.mjs.map +1 -0
  144. package/dist/deploy-ciuNiVqo.cjs +3892 -0
  145. package/dist/deploy-ciuNiVqo.cjs.map +1 -0
  146. package/dist/discover-CRywE7yc.cjs +1085 -0
  147. package/dist/discover-CRywE7yc.cjs.map +1 -0
  148. package/dist/discover-DbDrCQ8h.mjs +940 -0
  149. package/dist/discover-DbDrCQ8h.mjs.map +1 -0
  150. package/dist/docker-74kvq2jQ.cjs +1514 -0
  151. package/dist/docker-74kvq2jQ.cjs.map +1 -0
  152. package/dist/docker-CXYz3W2U.mjs +1407 -0
  153. package/dist/docker-CXYz3W2U.mjs.map +1 -0
  154. package/dist/dokploy-CrxDMut1.cjs +38 -0
  155. package/dist/dokploy-CrxDMut1.cjs.map +1 -0
  156. package/dist/dokploy-tNy6ZU64.mjs +38 -0
  157. package/dist/dokploy-tNy6ZU64.mjs.map +1 -0
  158. package/dist/drivers-aM87NQJi.cjs +224 -0
  159. package/dist/drivers-aM87NQJi.cjs.map +1 -0
  160. package/dist/drivers-uxLBq3e3.mjs +195 -0
  161. package/dist/drivers-uxLBq3e3.mjs.map +1 -0
  162. package/dist/eas-B3yv_XVz.mjs +334 -0
  163. package/dist/eas-B3yv_XVz.mjs.map +1 -0
  164. package/dist/eas-CiORdzk0.cjs +337 -0
  165. package/dist/eas-CiORdzk0.cjs.map +1 -0
  166. package/dist/emit-Bj6XSivk.mjs +136 -0
  167. package/dist/emit-Bj6XSivk.mjs.map +1 -0
  168. package/dist/emit-CDC__ubE.cjs +147 -0
  169. package/dist/emit-CDC__ubE.cjs.map +1 -0
  170. package/dist/encryption-Birkm2_E.mjs +89 -0
  171. package/dist/encryption-Birkm2_E.mjs.map +1 -0
  172. package/dist/encryption-drgYmkGP.cjs +90 -0
  173. package/dist/encryption-drgYmkGP.cjs.map +1 -0
  174. package/dist/engine-CW78Wt8x.mjs +3217 -0
  175. package/dist/engine-CW78Wt8x.mjs.map +1 -0
  176. package/dist/engine-CfLaQ0bJ.cjs +3330 -0
  177. package/dist/engine-CfLaQ0bJ.cjs.map +1 -0
  178. package/dist/errors-D8Gwp5kU.mjs +23 -0
  179. package/dist/errors-D8Gwp5kU.mjs.map +1 -0
  180. package/dist/errors-DMC4Umsb.cjs +34 -0
  181. package/dist/errors-DMC4Umsb.cjs.map +1 -0
  182. package/dist/github-BfLlBWB5.cjs +901 -0
  183. package/dist/github-BfLlBWB5.cjs.map +1 -0
  184. package/dist/github-DphkHybE.mjs +900 -0
  185. package/dist/github-DphkHybE.mjs.map +1 -0
  186. package/dist/googlePlay-BWDhYvH_.cjs +931 -0
  187. package/dist/googlePlay-BWDhYvH_.cjs.map +1 -0
  188. package/dist/googlePlay-CjzqTF8t.mjs +931 -0
  189. package/dist/googlePlay-CjzqTF8t.mjs.map +1 -0
  190. package/dist/{index-D-iAVHx-.d.cts → index-B35vTdAW.d.cts} +39 -15
  191. package/dist/index-B35vTdAW.d.cts.map +1 -0
  192. package/dist/{index-Cd-qeOam.d.mts → index-Dv1Zj86i.d.mts} +39 -15
  193. package/dist/index-Dv1Zj86i.d.mts.map +1 -0
  194. package/dist/index.cjs +13594 -12347
  195. package/dist/index.cjs.map +1 -1
  196. package/dist/index.mjs +13541 -12292
  197. package/dist/index.mjs.map +1 -1
  198. package/dist/local-Bt9jPziD.cjs +241 -0
  199. package/dist/local-Bt9jPziD.cjs.map +1 -0
  200. package/dist/local-DBtepRK5.mjs +224 -0
  201. package/dist/local-DBtepRK5.mjs.map +1 -0
  202. package/dist/migrate-2YESt4v9.mjs +267 -0
  203. package/dist/migrate-2YESt4v9.mjs.map +1 -0
  204. package/dist/migrate-B-_cASJt.cjs +272 -0
  205. package/dist/migrate-B-_cASJt.cjs.map +1 -0
  206. package/dist/migrate-BUhe0BuA.cjs +181 -0
  207. package/dist/migrate-BUhe0BuA.cjs.map +1 -0
  208. package/dist/migrate-Dp_Y2XGi.mjs +181 -0
  209. package/dist/migrate-Dp_Y2XGi.mjs.map +1 -0
  210. package/dist/notes-DHN4qThL.mjs +399 -0
  211. package/dist/notes-DHN4qThL.mjs.map +1 -0
  212. package/dist/notes-DUq6Bx1I.cjs +500 -0
  213. package/dist/notes-DUq6Bx1I.cjs.map +1 -0
  214. package/dist/openapi.cjs +213 -7
  215. package/dist/openapi.cjs.map +1 -0
  216. package/dist/openapi.d.cts +32 -8
  217. package/dist/openapi.d.cts.map +1 -1
  218. package/dist/openapi.d.mts +32 -8
  219. package/dist/openapi.d.mts.map +1 -1
  220. package/dist/openapi.mjs +208 -2
  221. package/dist/openapi.mjs.map +1 -0
  222. package/dist/projectBucket-CxsutB3D.cjs +263 -0
  223. package/dist/projectBucket-CxsutB3D.cjs.map +1 -0
  224. package/dist/projectBucket-DzLZlleB.mjs +222 -0
  225. package/dist/projectBucket-DzLZlleB.mjs.map +1 -0
  226. package/dist/provider-BqpjG9QM.cjs +57 -0
  227. package/dist/provider-BqpjG9QM.cjs.map +1 -0
  228. package/dist/provider-CEOKk8NS.mjs +46 -0
  229. package/dist/provider-CEOKk8NS.mjs.map +1 -0
  230. package/dist/publish-BVal0GFd.mjs +123 -0
  231. package/dist/publish-BVal0GFd.mjs.map +1 -0
  232. package/dist/publish-DmTJhVe8.cjs +124 -0
  233. package/dist/publish-DmTJhVe8.cjs.map +1 -0
  234. package/dist/ready-BNh3zsSn.cjs +404 -0
  235. package/dist/ready-BNh3zsSn.cjs.map +1 -0
  236. package/dist/ready-g25dcGzK.mjs +375 -0
  237. package/dist/ready-g25dcGzK.mjs.map +1 -0
  238. package/dist/reconcile/public.cjs +3 -5
  239. package/dist/reconcile/public.d.cts +31 -89
  240. package/dist/reconcile/public.d.cts.map +1 -1
  241. package/dist/reconcile/public.d.mts +31 -89
  242. package/dist/reconcile/public.d.mts.map +1 -1
  243. package/dist/reconcile/public.mjs +3 -3
  244. package/dist/{reconcile-DhQ00DpU.mjs → reconcile--I7V4Klj.mjs} +2 -2
  245. package/dist/{reconcile-DhQ00DpU.mjs.map → reconcile--I7V4Klj.mjs.map} +1 -1
  246. package/dist/{reconcile-Dd2iyILf.cjs → reconcile-CuCQBa5-.cjs} +3 -3
  247. package/dist/{reconcile-Dd2iyILf.cjs.map → reconcile-CuCQBa5-.cjs.map} +1 -1
  248. package/dist/resolve-BwTJI8K7.cjs +316 -0
  249. package/dist/resolve-BwTJI8K7.cjs.map +1 -0
  250. package/dist/resolve-UBq26cZc.mjs +263 -0
  251. package/dist/resolve-UBq26cZc.mjs.map +1 -0
  252. package/dist/rollback-BFKex9TO.cjs +165 -0
  253. package/dist/rollback-BFKex9TO.cjs.map +1 -0
  254. package/dist/rollback-DiOcLTRc.mjs +136 -0
  255. package/dist/rollback-DiOcLTRc.mjs.map +1 -0
  256. package/dist/runtime-CFvcLEJW.d.cts +82 -0
  257. package/dist/runtime-CFvcLEJW.d.cts.map +1 -0
  258. package/dist/runtime-dwsH6ddo.d.mts +82 -0
  259. package/dist/runtime-dwsH6ddo.d.mts.map +1 -0
  260. package/dist/s3-BgG_xW-D.cjs +215 -0
  261. package/dist/s3-BgG_xW-D.cjs.map +1 -0
  262. package/dist/s3-CkrerKdA.mjs +215 -0
  263. package/dist/s3-CkrerKdA.mjs.map +1 -0
  264. package/dist/sandbox/config-worker.cjs +43 -0
  265. package/dist/sandbox/config-worker.cjs.map +1 -0
  266. package/dist/sandbox/config-worker.d.cts +1 -0
  267. package/dist/sandbox/config-worker.d.mts +1 -0
  268. package/dist/sandbox/config-worker.mjs +44 -0
  269. package/dist/sandbox/config-worker.mjs.map +1 -0
  270. package/dist/sandbox/credentials-worker.cjs +53 -0
  271. package/dist/sandbox/credentials-worker.cjs.map +1 -0
  272. package/dist/sandbox/credentials-worker.d.cts +1 -0
  273. package/dist/sandbox/credentials-worker.d.mts +1 -0
  274. package/dist/sandbox/credentials-worker.mjs +54 -0
  275. package/dist/sandbox/credentials-worker.mjs.map +1 -0
  276. package/dist/sandbox/discover-worker.cjs +47 -0
  277. package/dist/sandbox/discover-worker.cjs.map +1 -0
  278. package/dist/sandbox/discover-worker.d.cts +1 -0
  279. package/dist/sandbox/discover-worker.d.mts +1 -0
  280. package/dist/sandbox/discover-worker.mjs +48 -0
  281. package/dist/sandbox/discover-worker.mjs.map +1 -0
  282. package/dist/sandbox/migrate-worker.cjs +75 -0
  283. package/dist/sandbox/migrate-worker.cjs.map +1 -0
  284. package/dist/sandbox/migrate-worker.d.cts +1 -0
  285. package/dist/sandbox/migrate-worker.d.mts +1 -0
  286. package/dist/sandbox/migrate-worker.mjs +76 -0
  287. package/dist/sandbox/migrate-worker.mjs.map +1 -0
  288. package/dist/{workspace-mFpI_ky_.cjs → schemas-BCwKKA42.mjs} +399 -1162
  289. package/dist/schemas-BCwKKA42.mjs.map +1 -0
  290. package/dist/{workspace-CgwmXEtc.mjs → schemas-BQ_v0lEX.cjs} +487 -971
  291. package/dist/schemas-BQ_v0lEX.cjs.map +1 -0
  292. package/dist/secretsManager-CQORubp9.mjs +97 -0
  293. package/dist/secretsManager-CQORubp9.mjs.map +1 -0
  294. package/dist/secretsManager-RAGcEDX1.cjs +108 -0
  295. package/dist/secretsManager-RAGcEDX1.cjs.map +1 -0
  296. package/dist/seeds-B3xvUAQf.cjs +363 -0
  297. package/dist/seeds-B3xvUAQf.cjs.map +1 -0
  298. package/dist/seeds-BCC8vAXR.mjs +298 -0
  299. package/dist/seeds-BCC8vAXR.mjs.map +1 -0
  300. package/dist/serverSetup-CUBu8_Mk.cjs +652 -0
  301. package/dist/serverSetup-CUBu8_Mk.cjs.map +1 -0
  302. package/dist/serverSetup-eh9MUdSN.mjs +652 -0
  303. package/dist/serverSetup-eh9MUdSN.mjs.map +1 -0
  304. package/dist/sniffer-CNTnUmhc.mjs +1824 -0
  305. package/dist/sniffer-CNTnUmhc.mjs.map +1 -0
  306. package/dist/sniffer-CaoQH_kk.cjs +1997 -0
  307. package/dist/sniffer-CaoQH_kk.cjs.map +1 -0
  308. package/dist/snsSubscriptions-DiqwM9Ms.cjs +1173 -0
  309. package/dist/snsSubscriptions-DiqwM9Ms.cjs.map +1 -0
  310. package/dist/snsSubscriptions-zOIIswN0.mjs +1048 -0
  311. package/dist/snsSubscriptions-zOIIswN0.mjs.map +1 -0
  312. package/dist/sst-D6Dvhr6H.mjs +462 -0
  313. package/dist/sst-D6Dvhr6H.mjs.map +1 -0
  314. package/dist/sst-DECRMgjv.cjs +485 -0
  315. package/dist/sst-DECRMgjv.cjs.map +1 -0
  316. package/dist/stack-BZG5HoVN.mjs +2206 -0
  317. package/dist/stack-BZG5HoVN.mjs.map +1 -0
  318. package/dist/stack-CLk9WojF.cjs +2381 -0
  319. package/dist/stack-CLk9WojF.cjs.map +1 -0
  320. package/dist/stage-Cl0DPJ7w.cjs +313 -0
  321. package/dist/stage-Cl0DPJ7w.cjs.map +1 -0
  322. package/dist/stage-DiLPb89O.mjs +302 -0
  323. package/dist/stage-DiLPb89O.mjs.map +1 -0
  324. package/dist/stages-Bs1THSy7.cjs +190 -0
  325. package/dist/stages-Bs1THSy7.cjs.map +1 -0
  326. package/dist/stages-_xCG4Ymu.mjs +190 -0
  327. package/dist/stages-_xCG4Ymu.mjs.map +1 -0
  328. package/dist/target/public.cjs +15 -0
  329. package/dist/target/public.d.cts +28 -0
  330. package/dist/target/public.d.cts.map +1 -0
  331. package/dist/target/public.d.mts +28 -0
  332. package/dist/target/public.d.mts.map +1 -0
  333. package/dist/target/public.mjs +4 -0
  334. package/dist/terminal-XQE106CG.cjs +85 -0
  335. package/dist/terminal-XQE106CG.cjs.map +1 -0
  336. package/dist/terminal-jGj9TtMQ.mjs +85 -0
  337. package/dist/terminal-jGj9TtMQ.mjs.map +1 -0
  338. package/dist/types-Bl_CwZC9.cjs +90 -0
  339. package/dist/types-Bl_CwZC9.cjs.map +1 -0
  340. package/dist/{types-BGo5TaNE.d.mts → types-Dk--xVOT.d.cts} +2234 -439
  341. package/dist/types-Dk--xVOT.d.cts.map +1 -0
  342. package/dist/{types-C5ZNpUad.d.cts → types-DwQYpd_0.d.mts} +2232 -439
  343. package/dist/types-DwQYpd_0.d.mts.map +1 -0
  344. package/dist/types-Y1NfWlyG.mjs +61 -0
  345. package/dist/types-Y1NfWlyG.mjs.map +1 -0
  346. package/dist/utils-D2Nk1Nv2.cjs +205 -0
  347. package/dist/utils-D2Nk1Nv2.cjs.map +1 -0
  348. package/dist/utils-D_fxUqvU.mjs +156 -0
  349. package/dist/utils-D_fxUqvU.mjs.map +1 -0
  350. package/dist/vitest.cjs +65 -0
  351. package/dist/vitest.cjs.map +1 -0
  352. package/dist/vitest.d.cts +29 -0
  353. package/dist/vitest.d.cts.map +1 -0
  354. package/dist/vitest.d.mts +29 -0
  355. package/dist/vitest.d.mts.map +1 -0
  356. package/dist/vitest.mjs +65 -0
  357. package/dist/vitest.mjs.map +1 -0
  358. package/dist/workerRuntime-BXfhbe13.cjs +108 -0
  359. package/dist/workerRuntime-BXfhbe13.cjs.map +1 -0
  360. package/dist/workerRuntime-CsOyBRx2.mjs +79 -0
  361. package/dist/workerRuntime-CsOyBRx2.mjs.map +1 -0
  362. package/dist/workspace/index.cjs +6 -2
  363. package/dist/workspace/index.d.cts +3 -3
  364. package/dist/workspace/index.d.mts +3 -3
  365. package/dist/workspace/index.mjs +2 -2
  366. package/dist/workspace-1szcahj9.cjs +2916 -0
  367. package/dist/workspace-1szcahj9.cjs.map +1 -0
  368. package/dist/workspace-DFGsrjGD.mjs +2480 -0
  369. package/dist/workspace-DFGsrjGD.mjs.map +1 -0
  370. package/package.json +66 -14
  371. package/dist/HostingerProvider-BY26bWwB.mjs.map +0 -1
  372. package/dist/HostingerProvider-BZFGYYVA.cjs.map +0 -1
  373. package/dist/LocalStateProvider-7HR6SS2t.cjs +0 -48
  374. package/dist/LocalStateProvider-7HR6SS2t.cjs.map +0 -1
  375. package/dist/LocalStateProvider-D7QyJoLM.mjs +0 -48
  376. package/dist/LocalStateProvider-D7QyJoLM.mjs.map +0 -1
  377. package/dist/Route53Provider-Cvj40A8I.mjs.map +0 -1
  378. package/dist/Route53Provider-DVILBsvV.cjs.map +0 -1
  379. package/dist/SSMStateProvider-B0Hu1MKZ.mjs +0 -75
  380. package/dist/SSMStateProvider-B0Hu1MKZ.mjs.map +0 -1
  381. package/dist/SSMStateProvider-VrQ-yeqd.cjs +0 -74
  382. package/dist/SSMStateProvider-VrQ-yeqd.cjs.map +0 -1
  383. package/dist/backup-provisioner-BmhIO_Yr.cjs.map +0 -1
  384. package/dist/backup-provisioner-DIVCbfee.mjs.map +0 -1
  385. package/dist/bundler-BeNDZdHQ.cjs.map +0 -1
  386. package/dist/bundler-BodTL4kf.mjs.map +0 -1
  387. package/dist/config-Q1rvKHvw.cjs +0 -467
  388. package/dist/config-Q1rvKHvw.cjs.map +0 -1
  389. package/dist/config-pqGD3hF9.mjs +0 -414
  390. package/dist/config-pqGD3hF9.mjs.map +0 -1
  391. package/dist/config.d.cts.map +0 -1
  392. package/dist/config.d.mts.map +0 -1
  393. package/dist/credentials-BekkKtY_.mjs +0 -2780
  394. package/dist/credentials-BekkKtY_.mjs.map +0 -1
  395. package/dist/credentials-Q6F0uqJq.cjs +0 -2917
  396. package/dist/credentials-Q6F0uqJq.cjs.map +0 -1
  397. package/dist/discover-BERGFg8v.cjs +0 -288
  398. package/dist/discover-BERGFg8v.cjs.map +0 -1
  399. package/dist/discover-CK-n3w6b.mjs +0 -244
  400. package/dist/discover-CK-n3w6b.mjs.map +0 -1
  401. package/dist/emit-BdoPFjZf.cjs +0 -253
  402. package/dist/emit-BdoPFjZf.cjs.map +0 -1
  403. package/dist/emit-Bzq7JsMP.mjs +0 -224
  404. package/dist/emit-Bzq7JsMP.mjs.map +0 -1
  405. package/dist/fullstack-secrets-BET8gqwK.mjs +0 -81
  406. package/dist/fullstack-secrets-BET8gqwK.mjs.map +0 -1
  407. package/dist/fullstack-secrets-DXsWO-5m.cjs +0 -92
  408. package/dist/fullstack-secrets-DXsWO-5m.cjs.map +0 -1
  409. package/dist/generator-LfZU7NlU.mjs +0 -247
  410. package/dist/generator-LfZU7NlU.mjs.map +0 -1
  411. package/dist/generator-Wdfp0jCS.cjs +0 -282
  412. package/dist/generator-Wdfp0jCS.cjs.map +0 -1
  413. package/dist/github-BfflNPVe.cjs +0 -203
  414. package/dist/github-BfflNPVe.cjs.map +0 -1
  415. package/dist/github-CRwnxKmD.mjs +0 -203
  416. package/dist/github-CRwnxKmD.mjs.map +0 -1
  417. package/dist/index-Cd-qeOam.d.mts.map +0 -1
  418. package/dist/index-D-iAVHx-.d.cts.map +0 -1
  419. package/dist/keystore-B4PRlbgE.mjs +0 -81
  420. package/dist/keystore-B4PRlbgE.mjs.map +0 -1
  421. package/dist/keystore-DgGRj2Yy.cjs +0 -98
  422. package/dist/keystore-DgGRj2Yy.cjs.map +0 -1
  423. package/dist/openapi-Dcbme-Us.cjs +0 -2038
  424. package/dist/openapi-Dcbme-Us.cjs.map +0 -1
  425. package/dist/openapi-vy4JzhUv.mjs +0 -1991
  426. package/dist/openapi-vy4JzhUv.mjs.map +0 -1
  427. package/dist/storage-C-30BD1e.cjs +0 -272
  428. package/dist/storage-C-30BD1e.cjs.map +0 -1
  429. package/dist/storage-P_b3w7uj.mjs +0 -231
  430. package/dist/storage-P_b3w7uj.mjs.map +0 -1
  431. package/dist/sync-B3xxXtJT.mjs +0 -88
  432. package/dist/sync-B3xxXtJT.mjs.map +0 -1
  433. package/dist/sync-D7uTIIEi.cjs +0 -111
  434. package/dist/sync-D7uTIIEi.cjs.map +0 -1
  435. package/dist/types-BGo5TaNE.d.mts.map +0 -1
  436. package/dist/types-C5ZNpUad.d.cts.map +0 -1
  437. package/dist/workspace-CgwmXEtc.mjs.map +0 -1
  438. package/dist/workspace-mFpI_ky_.cjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snsSubscriptions-zOIIswN0.mjs","names":["dnsLookup"],"sources":["../src/providers/aws.ts","../src/compose/dns.ts","../src/deploy/snsSubscriptions.ts"],"sourcesContent":["/**\n * The AWS account a provider provisions in — the stage's, found the way the\n * SSM and Secrets Manager stores find it.\n *\n * 1. `--profile`, resolved on its own: exported keys left over from another\n * account never win over a profile someone named.\n * 2. `AWS_PROFILE`, else `AWS_ACCESS_KEY_ID`/`AWS_SECRET_ACCESS_KEY` — the\n * deploy's own `aws` credential kind (`storedCredentials`).\n * 3. The SDK's default chain: `~/.aws` default profile, SSO, a role. In CI,\n * whatever `aws-actions/configure-aws-credentials` exported.\n *\n * None of them: the provider has no provisioning credentials, and the stage\n * is treated as `external`.\n */\n\nimport {\n\ttype AwsCredential,\n\tstoredCredentials,\n} from '../deploy/credentials.js';\nimport type { CredentialLookup } from './types.js';\n\n/** An AWS credential, or the default chain the SDK resolves itself. */\nexport type AwsProvisioning =\n\t| AwsCredential\n\t| {\n\t\t\tchain: true;\n\t\t\tregion?: string;\n\t };\n\nexport async function awsProvisioningCredentials(\n\tlookup: CredentialLookup,\n): Promise<AwsProvisioning | undefined> {\n\tconst region = lookup.env.AWS_REGION ?? lookup.env.AWS_DEFAULT_REGION;\n\tconst where = region ? { region } : {};\n\tif (lookup.profile) return { profile: lookup.profile, ...where };\n\n\tconst stored = await storedCredentials({\n\t\tenv: lookup.env,\n\t\t...(lookup.home ? { home: lookup.home } : {}),\n\t}).get({ kind: 'aws', stage: lookup.stage });\n\tif (stored) return stored;\n\n\ttry {\n\t\tconst { fromNodeProviderChain } = await import(\n\t\t\t'@aws-sdk/credential-providers'\n\t\t);\n\t\tawait fromNodeProviderChain({ timeout: 1000, maxRetries: 0 })();\n\t\treturn { chain: true, ...where };\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * An S3-compatible endpoint the environment points the SDK at — the AWS\n * emulator in tests. The SDK reads it itself; it is read here too, because\n * an emulator takes path-style requests, and a key written for one has to\n * say where it is.\n */\nexport function awsEndpoint(\n\tenv: NodeJS.ProcessEnv,\n\tservice: 'S3' | 'IAM' | 'CLOUDFRONT' | 'ACM' | 'SNS' | 'SQS' | 'STS' | 'SES',\n): string | undefined {\n\treturn env[`AWS_ENDPOINT_URL_${service}`] ?? env.AWS_ENDPOINT_URL;\n}\n\n/** An SDK client's config for a provisioning credential. */\nexport async function awsClientConfig(\n\tcredential: AwsProvisioning,\n\tregion: string,\n): Promise<{\n\tregion: string;\n\tcredentials?:\n\t\t| ReturnType<typeof import('@aws-sdk/credential-providers').fromIni>\n\t\t| { accessKeyId: string; secretAccessKey: string; sessionToken?: string };\n}> {\n\tif ('profile' in credential) {\n\t\tconst { fromIni } = await import('@aws-sdk/credential-providers');\n\t\treturn { region, credentials: fromIni({ profile: credential.profile }) };\n\t}\n\tif ('accessKeyId' in credential) {\n\t\treturn {\n\t\t\tregion,\n\t\t\tcredentials: {\n\t\t\t\taccessKeyId: credential.accessKeyId,\n\t\t\t\tsecretAccessKey: credential.secretAccessKey,\n\t\t\t\t...(credential.sessionToken\n\t\t\t\t\t? { sessionToken: credential.sessionToken }\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t};\n\t}\n\treturn { region };\n}\n","/**\n * A compose stage's DNS: the records its public hosts need, and the check that\n * they resolve to its server before a certificate is asked for.\n *\n * - **The server** (`serverAddress`): the stage's own secrets hold its public\n * addresses — `GKM_SERVER_IPV4`, and `GKM_SERVER_IPV6` where it has one.\n * Reserved for gkm: never handed to an app.\n * - **The plan** (`planStackDns`, pure): every public host the stack serves —\n * its apex, each app, each file server, the public log UI — pointed at the\n * server. An A record per host (and an AAAA with an IPv6 address), or, where\n * the domain's `dns` entry says `records: { mode: 'cname', target }`, one A\n * record for the target and a CNAME to it for every other host but the\n * apex, which DNS forbids a CNAME at.\n * - **Applying it** (`applyStackDns`): through the domain's provider in `dns`,\n * a record set at a time. A record with the right value is left alone; one\n * with another value is replaced and the change printed. A `manual` domain\n * is printed and nothing else. A dry run reads, prints and writes nothing.\n * - **The check** (`checkStackDns`): each host resolved with the system\n * resolver. One that is not the server stops the deploy with\n * {@link HostNotPointingAtServer}, before Caddy or Traefik ask Let's Encrypt\n * for a certificate it cannot get — and use up the rate limit trying.\n * - **What gkm wrote before** (`diffRecordedDns`, pure): the plan against the\n * records the stage's state says gkm wrote — added, kept, and stale: a\n * host the stage no longer serves, after a domain or an app changed.\n * - **The prune** (`pruneStackDns`): each stale record deleted through its\n * domain's provider, if it still holds the value gkm wrote. One someone\n * pointed elsewhere is left alone; one no provider can delete is printed.\n * - **The step** (`stageDns`): all of it, as every deploy runs it — the plan applied through each provider,\n * what was written read back from the provider, the stale records pruned,\n * and only the hosts no provider wrote resolved publicly. A brand-new name\n * is never looked up before its record exists, so no resolver caches it as\n * missing.\n */\n\nimport { lookup as dnsLookup } from 'node:dns/promises';\nimport { isIPv4, isIPv6 } from 'node:net';\nimport type {\n\tCredentialProvider,\n\tGoDaddyCredential,\n\tHostingerCredential,\n} from '../deploy/credentials';\nimport type { DnsResourceRecord } from '../deploy/dnsResources';\nimport {\n\tcreateDnsProvider,\n\ttype DnsProvider,\n\ttype DnsRecord,\n\tDnsRecordsUnreadable,\n\ttype DnsConfig as SchemaDnsConfig,\n} from '../target/dokploy/dns/DnsProvider';\nimport type { GoDaddyProviderOptions } from '../target/dokploy/dns/GoDaddyProvider';\nimport {\n\textractSubdomain,\n\tfindRootDomain,\n\tnormalizeDnsConfig,\n} from '../target/dokploy/dns/index';\nimport type {\n\tDnsProvider as DnsProviderConfig,\n\tWorkspaceDnsConfig,\n} from '../workspace/types';\nimport {\n\tcnameTarget,\n\ttype DnsRecordsMode,\n\tisReservedStageKey,\n\tSERVER_IPV4_KEY,\n\tSERVER_IPV6_KEY,\n} from './dnsConfig';\n\nexport { isReservedStageKey, SERVER_IPV4_KEY, SERVER_IPV6_KEY };\n\nimport { GkmError } from '../errors';\nimport type { ComposeStack } from './stack';\n\n/** A deployed stage's server: what its hosts' records point at. */\nexport interface ServerAddress {\n\tipv4: string;\n\tipv6?: string;\n}\n\n/** The line that says how to set the server's address. */\nexport function serverAddressHint(stage: string): string {\n\treturn `gkm secrets:set ${SERVER_IPV4_KEY} '<ip>' --stage ${stage}`;\n}\n\n/** A server address in the stage's secrets that is not an address. */\nexport class ServerAddressInvalid extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly key: string,\n\t\treadonly value: string,\n\t) {\n\t\tconst ipv4 = key === SERVER_IPV4_KEY;\n\t\tsuper(\n\t\t\t`${key} in the '${stage}' stage's secrets is ${JSON.stringify(value)}, ` +\n\t\t\t\t`which is not an ${ipv4 ? 'IPv4 address (like 203.0.113.10)' : 'IPv6 address (like 2001:db8::10)'}. ` +\n\t\t\t\t`Set the server's public address: gkm secrets:set ${key} '<ip>' --stage ${stage}.`,\n\t\t);\n\t\tthis.name = 'ServerAddressInvalid';\n\t}\n}\n\n/**\n * A compose stage that serves real domains with no server address: its hosts\n * cannot be pointed or checked, and a certificate would be asked for blind.\n */\nexport class ServerAddressMissing extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly domain: string,\n\t) {\n\t\tsuper(\n\t\t\t`The '${stage}' stage serves ${domain} and its secrets hold no ` +\n\t\t\t\t`${SERVER_IPV4_KEY} — the public address of the server its stack runs ` +\n\t\t\t\t\"on, which its hosts' DNS records point at and every deploy checks \" +\n\t\t\t\t`before asking for certificates. Set it: ${serverAddressHint(stage)} ` +\n\t\t\t\t`(and ${SERVER_IPV6_KEY} for an IPv6 address).`,\n\t\t);\n\t\tthis.name = 'ServerAddressMissing';\n\t}\n}\n\n/**\n * The server's address from the stage's secrets, checked — `undefined` when\n * `GKM_SERVER_IPV4` is not set.\n *\n * @throws {ServerAddressInvalid} for a value that is not an address\n */\nexport function serverAddress(\n\tstage: string,\n\tcustom: Readonly<Record<string, string>> | undefined,\n): ServerAddress | undefined {\n\tconst ipv4 = custom?.[SERVER_IPV4_KEY]?.trim();\n\tconst ipv6 = custom?.[SERVER_IPV6_KEY]?.trim();\n\tif (ipv6 && !isIPv6(ipv6)) {\n\t\tthrow new ServerAddressInvalid(stage, SERVER_IPV6_KEY, ipv6);\n\t}\n\tif (!ipv4) return undefined;\n\tif (!isIPv4(ipv4))\n\t\tthrow new ServerAddressInvalid(stage, SERVER_IPV4_KEY, ipv4);\n\treturn { ipv4, ...(ipv6 ? { ipv6 } : {}) };\n}\n\n/**\n * A name that resolves to this machine by definition — `localhost` and every\n * `*.localhost` — and is in nobody's DNS.\n */\nexport function isLocalHost(host: string): boolean {\n\tconst name = host.toLowerCase().replace(/\\.$/, '');\n\treturn name === 'localhost' || name.endsWith('.localhost');\n}\n\n/**\n * The server's address, required where the stage serves real domains — not\n * `*.localhost` ones, which point at this machine already.\n *\n * @throws {ServerAddressMissing} when the stage has a domain and no address\n * @throws {ServerAddressInvalid} for a value that is not an address\n */\nexport function requiredServerAddress(\n\tstage: string,\n\tdomain: string | undefined,\n\tcustom: Readonly<Record<string, string>> | undefined,\n): ServerAddress | undefined {\n\tconst server = serverAddress(stage, custom);\n\tif (!server && domain && !isLocalHost(domain)) {\n\t\tthrow new ServerAddressMissing(stage, domain);\n\t}\n\treturn server;\n}\n\n/**\n * The record types gkm writes: A, AAAA and CNAME for the stack's hosts, and\n * the CNAME and MX records a provider asks for (`writeProviderDns`).\n */\nexport type StackRecordType = 'A' | 'AAAA' | 'CNAME' | 'MX';\n\n/** The types that point a name somewhere — a name holds a CNAME or the others. */\nconst ADDRESS_TYPES: readonly StackRecordType[] = ['A', 'AAAA', 'CNAME'];\n\n/** One record a stack's host needs. */\nexport interface PlannedDnsRecord {\n\t/** The full name: `api.example.com`. */\n\thost: string;\n\t/** The root domain in `dns` it is under. */\n\tdomain: string;\n\t/** Relative to the domain, as providers take it: `api`, `@`. */\n\tname: string;\n\ttype: StackRecordType;\n\t/**\n\t * As a zone file writes it — an MX record's is `<priority> <host>`\n\t * (`mxValue`).\n\t */\n\tvalue: string;\n\tttl: number;\n}\n\n/** One `dns` domain's share of the plan. */\nexport interface DomainDnsPlan {\n\tdomain: string;\n\t/** `godaddy`, `route53`, `manual`, … — `custom` for an object. */\n\tprovider: string;\n\tconfig: DnsProviderConfig;\n\trecords: PlannedDnsRecord[];\n}\n\nexport interface StackDnsPlan {\n\tstage: string;\n\tserver: ServerAddress;\n\tdomains: DomainDnsPlan[];\n\t/** Hosts under no `dns` domain: theirs to point by hand. */\n\tuncovered: string[];\n}\n\n/** Every public host the stack serves, once each, sorted. */\nexport function stackHosts(stack: Pick<ComposeStack, 'routes'>): string[] {\n\treturn [...new Set(stack.routes.map((route) => route.host))].sort();\n}\n\n/** The TTL a domain's records are written with. */\nexport function recordTtl(config: DnsProviderConfig): number {\n\tconst ttl = 'ttl' in config ? config.ttl : undefined;\n\tif (ttl) return ttl;\n\treturn config.provider === 'godaddy' ? 600 : 300;\n}\n\nfunction providerName(config: DnsProviderConfig): string {\n\treturn typeof config.provider === 'string' ? config.provider : 'custom';\n}\n\nexport interface PlanStackDnsInput {\n\tstage: string;\n\thosts: readonly string[];\n\tserver: ServerAddress;\n\tdns: WorkspaceDnsConfig | undefined;\n\t/**\n\t * The stage's wildcard site's host, `*.<domain>` — the one wildcard\n\t * record gkm writes, because its tenants are created by the running app\n\t * and no deploy could write a record for each.\n\t */\n\twildcard?: string;\n}\n\n/**\n * A wildcard host that is not the stage's wildcard site's: gkm writes one\n * record per public host, so a stage on another server — or a name someone\n * else points elsewhere — is never caught by a record it did not ask for.\n * Only `*.<domain>` for a site declared `subdomain: '*'` is written, and it\n * covers no name that has a record of its own.\n */\nexport class DnsWildcardRefused extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly host: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${stage}' would point ${host} at its server, and gkm never writes a ` +\n\t\t\t\t'wildcard record: each public host gets its own. Give the app a ' +\n\t\t\t\t'subdomain of its own instead.',\n\t\t);\n\t\tthis.name = 'DnsWildcardRefused';\n\t}\n}\n\n/** The records a stage's hosts need — pure. */\nexport function planStackDns(input: PlanStackDnsInput): StackDnsPlan {\n\tconst { stage, server } = input;\n\tconst dns = input.dns ? normalizeDnsConfig(input.dns) : {};\n\tconst records = new Map<string, PlannedDnsRecord>();\n\tconst uncovered: string[] = [];\n\n\tconst add = (\n\t\thost: string,\n\t\tdomain: string,\n\t\ttype: StackRecordType,\n\t\tvalue: string,\n\t) => {\n\t\tconst name = extractSubdomain(host, domain);\n\t\trecords.set(`${domain} ${name} ${type}`, {\n\t\t\thost,\n\t\t\tdomain,\n\t\t\tname,\n\t\t\ttype,\n\t\t\tvalue,\n\t\t\tttl: recordTtl(dns[domain]!),\n\t\t});\n\t};\n\tconst pointAt = (host: string, domain: string) => {\n\t\tadd(host, domain, 'A', server.ipv4);\n\t\tif (server.ipv6) add(host, domain, 'AAAA', server.ipv6);\n\t};\n\n\tfor (const raw of input.hosts) {\n\t\tconst host = raw.toLowerCase();\n\t\tif (host.includes('*') && host !== input.wildcard?.toLowerCase()) {\n\t\t\tthrow new DnsWildcardRefused(stage, host);\n\t\t}\n\t\tconst domain = findRootDomain(host, dns);\n\t\tif (!domain) {\n\t\t\tuncovered.push(host);\n\t\t\tcontinue;\n\t\t}\n\t\t// A target under the domain itself — the schema refuses one that is\n\t\t// not — gets the A record every other host's CNAME points at.\n\t\tconst target = cnameTarget(\n\t\t\t(dns[domain] as { records?: DnsRecordsMode }).records,\n\t\t\tstage,\n\t\t);\n\t\tif (target) pointAt(target, domain);\n\t\t// The apex can hold no CNAME — it has the zone's SOA and NS — so it\n\t\t// is always an A record.\n\t\tif (target && host !== domain && host !== target) {\n\t\t\tadd(host, domain, 'CNAME', target);\n\t\t} else {\n\t\t\tpointAt(host, domain);\n\t\t}\n\t}\n\n\tconst domains = new Map<string, DomainDnsPlan>();\n\tfor (const record of [...records.values()].sort(\n\t\t(a, b) =>\n\t\t\ta.domain.localeCompare(b.domain) ||\n\t\t\ta.name.localeCompare(b.name) ||\n\t\t\ta.type.localeCompare(b.type),\n\t)) {\n\t\tconst config = dns[record.domain]!;\n\t\tconst plan = domains.get(record.domain) ?? {\n\t\t\tdomain: record.domain,\n\t\t\tprovider: providerName(config),\n\t\t\tconfig,\n\t\t\trecords: [],\n\t\t};\n\t\tplan.records.push(record);\n\t\tdomains.set(record.domain, plan);\n\t}\n\n\treturn {\n\t\tstage,\n\t\tserver,\n\t\tdomains: [...domains.values()],\n\t\tuncovered: uncovered.sort(),\n\t};\n}\n\n/** One change applying a plan makes — or, in a dry run, would. */\nexport interface DnsChange {\n\tdomain: string;\n\tname: string;\n\ttype: StackRecordType;\n\t/**\n\t * `write`: the provider's key cannot read records, so the record is\n\t * written without knowing what is there — idempotent, and not diffed.\n\t */\n\taction: 'create' | 'update' | 'delete' | 'unchanged' | 'write' | 'manual';\n\t/** The value it is set to — absent for a delete. */\n\tvalue?: string;\n\t/** What it was, for an update or a delete. */\n\tprevious?: string;\n\tttl?: number;\n}\n\nexport interface ApplyStackDnsOptions {\n\tdryRun?: boolean;\n\tlog?: (line: string) => void;\n\t/** Where the GoDaddy provider reads its key: the environment and the CLI's home. */\n\tcredentials?: GoDaddyProviderOptions;\n\t/** The Hostinger token, when the caller already has it. */\n\thostinger?: HostingerCredential;\n\t/** The provider for a domain — `createDnsProvider` by default. */\n\tproviderFor?: (config: DnsProviderConfig) => Promise<DnsProvider | null>;\n\t/**\n\t * Read every record written back from its provider, and throw\n\t * {@link DnsRecordsNotConfirmed} for one that does not hold its value.\n\t */\n\tconfirm?: boolean;\n}\n\n/** What applying a plan did, and what of it the providers confirmed. */\nexport interface StackDnsApplied {\n\t/** Every change, the unchanged included; a dry run makes none of them. */\n\tchanges: DnsChange[];\n\t/**\n\t * Hosts whose every record the provider holds with its value — read\n\t * before the run (unchanged) or after it wrote them (`confirm`).\n\t */\n\tconfirmed: string[];\n\t/**\n\t * Hosts no provider vouches for: a `manual` domain's, those under no\n\t * domain in `dns`, and those of a key that can write and not read.\n\t */\n\tunconfirmed: string[];\n}\n\n/** One record a provider did not hold with its value after it was written. */\nexport interface UnconfirmedRecord {\n\thost: string;\n\ttype: StackRecordType;\n\texpected: string;\n\t/** What the provider read back — empty when the record is not there. */\n\tfound: string[];\n}\n\n/** Records a provider accepted and then did not read back with their value. */\nexport class DnsRecordsNotConfirmed extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly domain: string,\n\t\treadonly provider: string,\n\t\treadonly records: readonly UnconfirmedRecord[],\n\t) {\n\t\tconst lines = records.map(\n\t\t\t(r) =>\n\t\t\t\t` - ${r.host} ${r.type}: ${r.found.length > 0 ? r.found.join(', ') : 'nothing'}, expected ${r.expected}`,\n\t\t);\n\t\tsuper(\n\t\t\t`${provider} accepted '${stage}''s records for ${domain}, and reading them ` +\n\t\t\t\t`back does not show them:\\n${lines.join('\\n')}\\n` +\n\t\t\t\t\"Deploy again; if it persists, check the records in the provider's \" +\n\t\t\t\t'console — another tool may be writing the same names.',\n\t\t);\n\t\tthis.name = 'DnsRecordsNotConfirmed';\n\t}\n}\n\n/** `api.example.com A 203.0.113.10 (TTL 600)` */\nfunction describe(record: PlannedDnsRecord): string {\n\treturn `${record.host.padEnd(32)} ${record.type.padEnd(5)} ${record.value} (TTL ${record.ttl})`;\n}\n\nfunction printManual(\n\tplan: DomainDnsPlan,\n\tlog: (line: string) => void,\n\twhy: string,\n): DnsChange[] {\n\tlog(` ${plan.domain}: ${why} — create these records at its DNS host:`);\n\tfor (const record of plan.records) log(` ${describe(record)}`);\n\treturn plan.records.map((r) => ({\n\t\tdomain: r.domain,\n\t\tname: r.name,\n\t\ttype: r.type,\n\t\taction: 'manual',\n\t\tvalue: r.value,\n\t\tttl: r.ttl,\n\t}));\n}\n\n/**\n * The existing records of every planned name: A, AAAA and CNAME where one of\n * them is planned — what the name points at, and what a change of mode\n * deletes — and MX where an MX is. No other type is read.\n */\nasync function existingRecords(\n\tprovider: DnsProvider,\n\tplan: DomainDnsPlan,\n): Promise<DnsRecord[]> {\n\tconst wanted = new Map<string, { name: string; type: StackRecordType }>();\n\tfor (const record of plan.records) {\n\t\tconst types = ADDRESS_TYPES.includes(record.type)\n\t\t\t? ADDRESS_TYPES\n\t\t\t: [record.type];\n\t\tfor (const type of types) {\n\t\t\twanted.set(`${record.name} ${type}`, { name: record.name, type });\n\t\t}\n\t}\n\treturn readRecords(provider, plan.domain, [...wanted.values()]);\n}\n\n/** Exactly these names and types, as the provider holds them. */\nasync function readRecords(\n\tprovider: DnsProvider,\n\tdomain: string,\n\twanted: readonly { name: string; type: StackRecordType }[],\n): Promise<DnsRecord[]> {\n\tif (provider.readRecords) return provider.readRecords(domain, wanted);\n\tconst all = await provider.getRecords(domain);\n\treturn all.filter((r) =>\n\t\twanted.some((w) => w.name === r.name && w.type === r.type),\n\t);\n}\n\n/** The provider for a domain's config: `providerFor`, or the real one. */\nfunction providerResolver(\n\toptions: Pick<\n\t\tApplyStackDnsOptions,\n\t\t'providerFor' | 'credentials' | 'hostinger'\n\t>,\n): (config: DnsProviderConfig) => Promise<DnsProvider | null> {\n\treturn (\n\t\toptions.providerFor ??\n\t\t((config: DnsProviderConfig) =>\n\t\t\tcreateDnsProvider({\n\t\t\t\tconfig: config as SchemaDnsConfig,\n\t\t\t\t...(options.credentials ? { godaddy: options.credentials } : {}),\n\t\t\t\t...(options.hostinger ? { hostinger: options.hostinger } : {}),\n\t\t\t}))\n\t);\n}\n\n/** Two values compared as DNS does: case, a trailing dot and spacing aside. */\nconst same = (a: string, b: string) => {\n\tconst normalize = (value: string) =>\n\t\tvalue.trim().replace(/\\.$/, '').replace(/\\s+/g, ' ').toLowerCase();\n\treturn normalize(a) === normalize(b);\n};\n\n/**\n * What each domain's records need, compared with what is there: creates,\n * updates, and the deletes a change of mode needs — a name moving from an A\n * record to a CNAME, or back, cannot hold both. Nothing else is deleted: an\n * MX planned at a name deletes nothing, and a CNAME or A planned at a name\n * never deletes its MX.\n */\nexport function diffDomainDns(\n\tplan: DomainDnsPlan,\n\texisting: readonly DnsRecord[],\n): DnsChange[] {\n\tconst changes: DnsChange[] = [];\n\tconst find = (name: string, type: string) =>\n\t\texisting.find((r) => r.name === name && r.type === type);\n\n\tconst planned = new Map<string, Set<StackRecordType>>();\n\tfor (const record of plan.records) {\n\t\tconst types = planned.get(record.name) ?? new Set();\n\t\ttypes.add(record.type);\n\t\tplanned.set(record.name, types);\n\t}\n\n\t// The deletes first: a CNAME where an A record goes, A and AAAA where a\n\t// CNAME goes.\n\tfor (const [name, types] of planned) {\n\t\tconst conflicting: StackRecordType[] = types.has('CNAME')\n\t\t\t? ['A', 'AAAA']\n\t\t\t: types.has('A') || types.has('AAAA')\n\t\t\t\t? ['CNAME']\n\t\t\t\t: [];\n\t\tfor (const type of conflicting) {\n\t\t\tconst found = find(name, type);\n\t\t\tif (!found || found.values.length === 0) continue;\n\t\t\tchanges.push({\n\t\t\t\tdomain: plan.domain,\n\t\t\t\tname,\n\t\t\t\ttype,\n\t\t\t\taction: 'delete',\n\t\t\t\tprevious: found.values.join(', '),\n\t\t\t});\n\t\t}\n\t}\n\n\tfor (const record of plan.records) {\n\t\tconst found = find(record.name, record.type);\n\t\tconst base = {\n\t\t\tdomain: plan.domain,\n\t\t\tname: record.name,\n\t\t\ttype: record.type,\n\t\t\tvalue: record.value,\n\t\t\tttl: record.ttl,\n\t\t};\n\t\tif (!found || found.values.length === 0) {\n\t\t\tchanges.push({ ...base, action: 'create' });\n\t\t} else if (\n\t\t\tfound.values.length === 1 &&\n\t\t\tsame(found.values[0]!, record.value)\n\t\t) {\n\t\t\tchanges.push({ ...base, action: 'unchanged' });\n\t\t} else {\n\t\t\tchanges.push({\n\t\t\t\t...base,\n\t\t\t\taction: 'update',\n\t\t\t\tprevious: found.values.join(', '),\n\t\t\t});\n\t\t}\n\t}\n\treturn changes;\n}\n\n/** A host's full name from a domain and a relative name. */\nfunction fullName(domain: string, name: string): string {\n\treturn name === '@' ? domain : `${name}.${domain}`;\n}\n\nfunction printChange(\n\tchange: DnsChange,\n\tdryRun: boolean,\n\tlog: (line: string) => void,\n) {\n\tconst host = fullName(change.domain, change.name).padEnd(32);\n\tconst type = change.type.padEnd(5);\n\tconst would = dryRun ? 'would ' : '';\n\tswitch (change.action) {\n\t\tcase 'unchanged':\n\t\t\tlog(\n\t\t\t\t` ✓ ${host} ${type} ${change.value} (TTL ${change.ttl}) — up to date`,\n\t\t\t);\n\t\t\tbreak;\n\t\tcase 'create':\n\t\t\tlog(\n\t\t\t\t` + ${host} ${type} ${change.value} (TTL ${change.ttl}) — ${would}create`,\n\t\t\t);\n\t\t\tbreak;\n\t\tcase 'update':\n\t\t\tlog(\n\t\t\t\t` ~ ${host} ${type} ${change.previous} → ${change.value} (TTL ${change.ttl}) — ${would}update`,\n\t\t\t);\n\t\t\tbreak;\n\t\tcase 'write':\n\t\t\tlog(\n\t\t\t\tdryRun\n\t\t\t\t\t? ` ? ${host} ${type} ${change.value} (TTL ${change.ttl}) — would write; current value unknown (key cannot read DNS)`\n\t\t\t\t\t: ` ! ${host} ${type} ${change.value} (TTL ${change.ttl}) — written (not diffed)`,\n\t\t\t);\n\t\t\tbreak;\n\t\tcase 'delete':\n\t\t\tlog(\n\t\t\t\t` - ${host} ${type} ${change.previous} — ${would}delete (a name cannot hold a CNAME and an A record)`,\n\t\t\t);\n\t\t\tbreak;\n\t}\n}\n\n/**\n * Each domain's records, through its provider. Returns every change, the\n * unchanged included; a dry run makes none of them.\n */\nexport async function applyStackDns(\n\tplan: StackDnsPlan,\n\toptions: ApplyStackDnsOptions = {},\n): Promise<DnsChange[]> {\n\treturn (await settleStackDns(plan, options)).changes;\n}\n\n/**\n * Each domain's records, through its provider — and, with `confirm`, what was\n * written read back from it. A record already holding its value is neither\n * written nor read again.\n *\n * @throws {DnsRecordsNotConfirmed} when a written record does not read back\n */\nexport async function settleStackDns(\n\tplan: StackDnsPlan,\n\toptions: ApplyStackDnsOptions = {},\n): Promise<StackDnsApplied> {\n\tconst dryRun = options.dryRun === true;\n\tconst log = options.log ?? ((line: string) => console.log(line));\n\tconst providerFor = providerResolver(options);\n\n\tconst changes: DnsChange[] = [];\n\tconst confirmed = new Set<string>();\n\tconst unconfirmed = new Set<string>();\n\tconst hostsOf = (domain: DomainDnsPlan) =>\n\t\tnew Set(domain.records.map((r) => r.host));\n\tfor (const host of plan.uncovered) {\n\t\tlog(\n\t\t\t` ⚠ ${host} is under no domain in dns — point it at ${plan.server.ipv4} yourself`,\n\t\t);\n\t}\n\n\tfor (const domain of plan.domains) {\n\t\tif (domain.provider === 'manual') {\n\t\t\tchanges.push(...printManual(domain, log, 'manual'));\n\t\t\tfor (const host of hostsOf(domain)) unconfirmed.add(host);\n\t\t\tcontinue;\n\t\t}\n\t\tconst provider = await providerFor(domain.config);\n\t\tif (!provider) {\n\t\t\tchanges.push(...printManual(domain, log, 'manual'));\n\t\t\tfor (const host of hostsOf(domain)) unconfirmed.add(host);\n\t\t\tcontinue;\n\t\t}\n\n\t\tlog(` ${domain.domain} (${provider.name})${dryRun ? ' — dry run' : ''}`);\n\t\tlet existing: DnsRecord[];\n\t\tlet diff: DnsChange[];\n\t\tlet unreadable = false;\n\t\ttry {\n\t\t\texisting = await existingRecords(provider, domain);\n\t\t\tdiff = diffDomainDns(domain, existing);\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof DnsRecordsUnreadable)) throw error;\n\t\t\tlog(\n\t\t\t\t` ℹ The ${provider.name} key cannot read ${domain.domain}'s DNS records, so changes cannot be diffed: every record is written (idempotent).`,\n\t\t\t);\n\t\t\tunreadable = true;\n\t\t\texisting = [];\n\t\t\tdiff = domain.records.map((r) => ({\n\t\t\t\tdomain: r.domain,\n\t\t\t\tname: r.name,\n\t\t\t\ttype: r.type,\n\t\t\t\taction: 'write' as const,\n\t\t\t\tvalue: r.value,\n\t\t\t\tttl: r.ttl,\n\t\t\t}));\n\t\t}\n\t\tfor (const change of diff) printChange(change, dryRun, log);\n\n\t\t// An AAAA nobody planned, at a name that points here: IPv6 clients —\n\t\t// Let's Encrypt among them — would go somewhere else.\n\t\tif (!plan.server.ipv6) {\n\t\t\tfor (const name of new Set(domain.records.map((r) => r.name))) {\n\t\t\t\tconst aaaa = existing.find((r) => r.name === name && r.type === 'AAAA');\n\t\t\t\tconst planned = domain.records.find(\n\t\t\t\t\t(r) => r.name === name && r.type === 'A',\n\t\t\t\t);\n\t\t\t\tif (aaaa && planned && aaaa.values.length > 0) {\n\t\t\t\t\tlog(\n\t\t\t\t\t\t` ⚠ ${fullName(domain.domain, name)} also has AAAA ${aaaa.values.join(', ')}: ` +\n\t\t\t\t\t\t\t`set ${SERVER_IPV6_KEY} in the '${plan.stage}' stage's secrets to the server's IPv6 address, ` +\n\t\t\t\t\t\t\t'or remove that record, or IPv6 clients go elsewhere',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tchanges.push(...diff);\n\n\t\t// A host every one of whose records was already right is confirmed by\n\t\t// the read that found it so; one with a write is confirmed by reading\n\t\t// it back — or, with a key that cannot read, by nobody.\n\t\tconst written = new Set(\n\t\t\tdiff\n\t\t\t\t.filter((c) => c.action !== 'unchanged')\n\t\t\t\t.map((c) => fullName(c.domain, c.name)),\n\t\t);\n\t\tfor (const host of hostsOf(domain)) {\n\t\t\t// A dry run writes nothing, so nothing it would write is resolved:\n\t\t\t// a name looked up before its record exists is cached as missing.\n\t\t\tif (unreadable) {\n\t\t\t\tif (!dryRun) unconfirmed.add(host);\n\t\t\t} else if (!written.has(host)) confirmed.add(host);\n\t\t}\n\t\tif (dryRun) continue;\n\n\t\tconst deletes = diff.filter((c) => c.action === 'delete');\n\t\tif (deletes.length > 0) {\n\t\t\tawait provider.deleteRecords(\n\t\t\t\tdomain.domain,\n\t\t\t\tdeletes.map((c) => ({ name: c.name, type: c.type })),\n\t\t\t);\n\t\t}\n\t\tconst writes = diff.filter(\n\t\t\t(c) =>\n\t\t\t\tc.action === 'create' || c.action === 'update' || c.action === 'write',\n\t\t);\n\t\tif (writes.length > 0) {\n\t\t\tawait provider.upsertRecords(\n\t\t\t\tdomain.domain,\n\t\t\t\twrites.map((c) => ({\n\t\t\t\t\tname: c.name,\n\t\t\t\t\ttype: c.type,\n\t\t\t\t\tvalue: c.value!,\n\t\t\t\t\tttl: c.ttl!,\n\t\t\t\t})),\n\t\t\t);\n\t\t}\n\n\t\tif (!options.confirm || unreadable || written.size === 0) continue;\n\t\tconst rewritten = {\n\t\t\t...domain,\n\t\t\trecords: domain.records.filter((r) => written.has(r.host)),\n\t\t};\n\t\tconst after = await existingRecords(provider, rewritten);\n\t\tconst missing: UnconfirmedRecord[] = [];\n\t\tfor (const record of rewritten.records) {\n\t\t\tconst found = after.find(\n\t\t\t\t(r) => r.name === record.name && r.type === record.type,\n\t\t\t);\n\t\t\tconst values = found?.values ?? [];\n\t\t\tif (values.length !== 1 || !same(values[0]!, record.value)) {\n\t\t\t\tmissing.push({\n\t\t\t\t\thost: record.host,\n\t\t\t\t\ttype: record.type,\n\t\t\t\t\texpected: record.value,\n\t\t\t\t\tfound: values,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tif (missing.length > 0) {\n\t\t\tthrow new DnsRecordsNotConfirmed(\n\t\t\t\tplan.stage,\n\t\t\t\tdomain.domain,\n\t\t\t\tprovider.name,\n\t\t\t\tmissing,\n\t\t\t);\n\t\t}\n\t\tfor (const host of written) confirmed.add(host);\n\t\tlog(\n\t\t\t` ✓ ${written.size} host${written.size === 1 ? '' : 's'} read back from ${provider.name}`,\n\t\t);\n\t}\n\tfor (const host of plan.uncovered) unconfirmed.add(host);\n\treturn {\n\t\tchanges,\n\t\tconfirmed: [...confirmed].sort(),\n\t\tunconfirmed: [...unconfirmed].filter((h) => !confirmed.has(h)).sort(),\n\t};\n}\n\n// ============================================================================\n// What gkm wrote before: the diff and the prune\n// ============================================================================\n\n/** A record gkm wrote for the stage, as its state keeps it. */\nexport type RecordedDnsRecord = DnsResourceRecord & { fqdn: string };\n\n/** The plan against the records the stage's state says gkm wrote. */\nexport interface RecordedDnsDiff {\n\t/** Planned, and never written by gkm for the stage. */\n\tadded: PlannedDnsRecord[];\n\t/** Planned, and written by gkm before — at this value or another. */\n\tkept: PlannedDnsRecord[];\n\t/** Written by gkm before, and no longer planned. */\n\tstale: RecordedDnsRecord[];\n}\n\n/** `api.example.com A` — a record's identity, whatever its value. */\nconst recordKey = (fqdn: string, type: string) =>\n\t`${fqdn.trim().replace(/\\.$/, '').toLowerCase()} ${type.toUpperCase()}`;\n\n/**\n * The plan against the records gkm wrote for the stage — pure. A record is\n * its full name and its type: one the plan has at another value is kept (the\n * apply updates it), and one whose name or type the plan no longer has is\n * stale — a host the stage stopped serving when its domain or an app changed,\n * or an AAAA once its server has no IPv6 address.\n */\nexport function diffRecordedDns(\n\tplan: StackDnsPlan,\n\trecorded: readonly RecordedDnsRecord[],\n): RecordedDnsDiff {\n\tconst planned = plan.domains.flatMap((domain) => domain.records);\n\tconst wanted = new Set(planned.map((r) => recordKey(r.host, r.type)));\n\tconst written = new Set(recorded.map((r) => recordKey(r.fqdn, r.type)));\n\treturn {\n\t\tadded: planned.filter((r) => !written.has(recordKey(r.host, r.type))),\n\t\tkept: planned.filter((r) => written.has(recordKey(r.host, r.type))),\n\t\tstale: recorded.filter((r) => !wanted.has(recordKey(r.fqdn, r.type))),\n\t};\n}\n\n/** What the prune did with one stale record — or, in a dry run, would. */\nexport interface PrunedDnsRecord {\n\trecord: RecordedDnsRecord;\n\t/**\n\t * - `delete`: it still held the value gkm wrote, and is deleted\n\t * - `gone`: the provider no longer has it\n\t * - `changed`: it was pointed elsewhere since, and is left as it is\n\t * - `manual`: no provider gkm can use deletes it — printed for a person\n\t *\n\t * Each is forgotten from the stage's state: none is gkm's any more.\n\t */\n\taction: 'delete' | 'gone' | 'changed' | 'manual';\n\t/** What the provider holds, for `changed`. */\n\tfound?: string[];\n}\n\nexport interface PruneStackDnsOptions\n\textends Pick<\n\t\tApplyStackDnsOptions,\n\t\t'dryRun' | 'log' | 'credentials' | 'hostinger' | 'providerFor'\n\t> {\n\tstage: string;\n\tdns: WorkspaceDnsConfig | undefined;\n}\n\n/**\n * Each stale record deleted through its domain's provider — only where the\n * provider still holds exactly the value gkm wrote, so a name someone has\n * since pointed elsewhere is never taken from them. Where no provider can\n * read and delete it — a `manual` domain, one gone from `dns`, a key that\n * can only write — it is printed for a person to remove. A dry run reads\n * and prints, and deletes nothing.\n */\nexport async function pruneStackDns(\n\tstale: readonly RecordedDnsRecord[],\n\toptions: PruneStackDnsOptions,\n): Promise<PrunedDnsRecord[]> {\n\tif (stale.length === 0) return [];\n\tconst dryRun = options.dryRun === true;\n\tconst log = options.log ?? ((line: string) => console.log(line));\n\tconst providerFor = providerResolver(options);\n\tconst dns = options.dns ? normalizeDnsConfig(options.dns) : {};\n\n\tconst byDomain = new Map<string, RecordedDnsRecord[]>();\n\tfor (const record of stale) {\n\t\tbyDomain.set(record.domain, [\n\t\t\t...(byDomain.get(record.domain) ?? []),\n\t\t\trecord,\n\t\t]);\n\t}\n\n\tlog(` No longer served by '${options.stage}':`);\n\tconst pruned: PrunedDnsRecord[] = [];\n\tconst byHand = (\n\t\tdomain: string,\n\t\trecords: RecordedDnsRecord[],\n\t\twhy: string,\n\t) => {\n\t\tlog(` ${domain}: ${why} — remove these records at its DNS host:`);\n\t\tfor (const record of records) {\n\t\t\tlog(\n\t\t\t\t` ${record.fqdn.padEnd(32)} ${record.type.padEnd(5)} ${record.value}`,\n\t\t\t);\n\t\t\tpruned.push({ record, action: 'manual' });\n\t\t}\n\t};\n\n\tfor (const [domain, records] of byDomain) {\n\t\tconst config = dns[domain];\n\t\tif (!config) {\n\t\t\tbyHand(domain, records, 'no longer in dns');\n\t\t\tcontinue;\n\t\t}\n\t\tconst provider =\n\t\t\tproviderName(config) === 'manual' ? null : await providerFor(config);\n\t\tif (!provider) {\n\t\t\tbyHand(domain, records, 'manual');\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet existing: DnsRecord[];\n\t\ttry {\n\t\t\texisting = await readRecords(\n\t\t\t\tprovider,\n\t\t\t\tdomain,\n\t\t\t\trecords.map((r) => ({ name: r.name, type: r.type as StackRecordType })),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof DnsRecordsUnreadable)) throw error;\n\t\t\tbyHand(\n\t\t\t\tdomain,\n\t\t\t\trecords,\n\t\t\t\t`the ${provider.name} key cannot read its records, so none is deleted unchecked`,\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst would = dryRun ? 'would ' : '';\n\t\tconst deletes: PrunedDnsRecord[] = [];\n\t\tfor (const record of records) {\n\t\t\tconst host = record.fqdn.padEnd(32);\n\t\t\tconst type = record.type.padEnd(5);\n\t\t\tconst found =\n\t\t\t\texisting.find((r) => r.name === record.name && r.type === record.type)\n\t\t\t\t\t?.values ?? [];\n\t\t\tif (found.length === 0) {\n\t\t\t\tlog(` · ${host} ${type} already gone`);\n\t\t\t\tpruned.push({ record, action: 'gone' });\n\t\t\t} else if (found.length === 1 && same(found[0]!, record.value)) {\n\t\t\t\tlog(` - ${host} ${type} ${record.value} — ${would}delete`);\n\t\t\t\tdeletes.push({ record, action: 'delete' });\n\t\t\t} else {\n\t\t\t\tlog(\n\t\t\t\t\t` ⚠ ${host} ${type} ${found.join(', ')} — pointed elsewhere since gkm wrote ${record.value}; left as it is`,\n\t\t\t\t);\n\t\t\t\tpruned.push({ record, action: 'changed', found });\n\t\t\t}\n\t\t}\n\t\tif (!dryRun && deletes.length > 0) {\n\t\t\tawait provider.deleteRecords(\n\t\t\t\tdomain,\n\t\t\t\tdeletes.map(({ record }) => ({\n\t\t\t\t\tname: record.name,\n\t\t\t\t\ttype: record.type as StackRecordType,\n\t\t\t\t})),\n\t\t\t);\n\t\t}\n\t\tpruned.push(...deletes);\n\t}\n\treturn pruned;\n}\n\n// ============================================================================\n// The check\n// ============================================================================\n\n/** Resolves a host to every address it has — `dns.promises.lookup`, `all`. */\nexport type HostLookup = (host: string) => Promise<string[]>;\n\n/** The system resolver: what the server's own clients would be told. */\nexport const systemLookup: HostLookup = async (host) => {\n\tconst found = await dnsLookup(host, { all: true });\n\treturn found.map((a) => a.address);\n};\n\n/** One host that does not resolve to the server. */\nexport interface MisdirectedHost {\n\thost: string;\n\t/** What it resolves to — empty when it does not resolve. */\n\tresolved: string[];\n\t/** Why it did not resolve, when it did not. */\n\terror?: string;\n}\n\n/** Hosts that do not resolve to the stage's server. */\nexport class HostNotPointingAtServer extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly hosts: readonly MisdirectedHost[],\n\t\treadonly expected: { ipv4: string; ipv6?: string },\n\t\t/** The records to create, where `dns` covers none of them. */\n\t\treadonly fix: string,\n\t) {\n\t\tconst want = expected.ipv6\n\t\t\t? `${expected.ipv4} (and ${expected.ipv6})`\n\t\t\t: expected.ipv4;\n\t\tconst lines = hosts.map(\n\t\t\t(h) =>\n\t\t\t\t` - ${h.host} → ${h.resolved.length > 0 ? h.resolved.join(', ') : `nothing${h.error ? ` (${h.error})` : ''}`}, expected ${want}`,\n\t\t);\n\t\tsuper(\n\t\t\t`${hosts.length === 1 ? 'A host' : `${hosts.length} hosts`} of '${stage}' ` +\n\t\t\t\t`do${hosts.length === 1 ? 'es' : ''} not resolve to its server, so a ` +\n\t\t\t\t`certificate for ${hosts.length === 1 ? 'it' : 'them'} cannot be issued:\\n` +\n\t\t\t\t`${lines.join('\\n')}\\n${fix}\\n` +\n\t\t\t\t'Records can take a few minutes to propagate. With a CDN or proxy in ' +\n\t\t\t\t'front of the server, pass --skip-dns.',\n\t\t);\n\t\tthis.name = 'HostNotPointingAtServer';\n\t}\n}\n\nexport interface CheckStackDnsInput {\n\tstage: string;\n\thosts: readonly string[];\n\tserver: ServerAddress;\n\tdns: WorkspaceDnsConfig | undefined;\n\tlookup?: HostLookup;\n}\n\n/**\n * The name a wildcard record is resolved through: one label no app takes,\n * which only the `*` record answers.\n */\nexport const WILDCARD_PROBE = 'gkm-wildcard-check';\n\n/**\n * Every host resolved: each must resolve to the server's IPv4 address and to\n * nothing but the server's addresses.\n *\n * @throws {HostNotPointingAtServer} naming every host that does not\n */\nexport async function checkStackDns(\n\tinput: CheckStackDnsInput,\n): Promise<string[]> {\n\tconst lookup = input.lookup ?? systemLookup;\n\tconst { server } = input;\n\tconst ours = new Set(\n\t\t[server.ipv4, server.ipv6].filter(Boolean).map((a) => a!.toLowerCase()),\n\t);\n\tconst bad: MisdirectedHost[] = [];\n\tconst ok: string[] = [];\n\tfor (const host of input.hosts) {\n\t\tlet resolved: string[];\n\t\tconst asked = host.startsWith('*.')\n\t\t\t? `${WILDCARD_PROBE}.${host.slice(2)}`\n\t\t\t: host;\n\t\ttry {\n\t\t\tresolved = [...new Set(await lookup(asked))];\n\t\t} catch (error) {\n\t\t\tconst code =\n\t\t\t\terror && typeof error === 'object' && 'code' in error\n\t\t\t\t\t? String((error as { code: unknown }).code)\n\t\t\t\t\t: error instanceof Error\n\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t: String(error);\n\t\t\tbad.push({ host, resolved: [], error: code });\n\t\t\tcontinue;\n\t\t}\n\t\tconst pointsHere =\n\t\t\tresolved.some((a) => a.toLowerCase() === server.ipv4.toLowerCase()) &&\n\t\t\tresolved.every((a) => ours.has(a.toLowerCase()));\n\t\tif (pointsHere) ok.push(host);\n\t\telse bad.push({ host, resolved });\n\t}\n\n\tif (bad.length > 0) {\n\t\tthrow new HostNotPointingAtServer(\n\t\t\tinput.stage,\n\t\t\tbad,\n\t\t\t{ ipv4: server.ipv4, ...(server.ipv6 ? { ipv6: server.ipv6 } : {}) },\n\t\t\tdnsFix(input, bad),\n\t\t);\n\t}\n\treturn ok;\n}\n\n/** How to fix it: the deploy, or the records to create by hand. */\nfunction dnsFix(input: CheckStackDnsInput, bad: readonly MisdirectedHost[]) {\n\tconst hosts = bad.map((h) => h.host);\n\tlet plan: StackDnsPlan;\n\ttry {\n\t\tplan = planStackDns({\n\t\t\tstage: input.stage,\n\t\t\thosts,\n\t\t\tserver: input.server,\n\t\t\tdns: input.dns,\n\t\t});\n\t} catch {\n\t\tplan = {\n\t\t\tstage: input.stage,\n\t\t\tserver: input.server,\n\t\t\tdomains: [],\n\t\t\tuncovered: hosts,\n\t\t};\n\t}\n\tconst automatic = plan.domains.filter((d) => d.provider !== 'manual');\n\tconst byHand = [\n\t\t...plan.domains\n\t\t\t.filter((d) => d.provider === 'manual')\n\t\t\t.flatMap((d) => d.records.map(describe)),\n\t\t...plan.uncovered.flatMap((host) => [\n\t\t\t`${host.padEnd(32)} A ${input.server.ipv4}`,\n\t\t\t...(input.server.ipv6\n\t\t\t\t? [`${host.padEnd(32)} AAAA ${input.server.ipv6}`]\n\t\t\t\t: []),\n\t\t]),\n\t];\n\tconst lines: string[] = [];\n\tif (automatic.length > 0) {\n\t\tlines.push(\n\t\t\t`Fix: gkm deploy --stage ${input.stage} writes the records for ${automatic.map((d) => d.domain).join(', ')} through their provider (--dry-run shows them first).`,\n\t\t);\n\t}\n\tif (byHand.length > 0) {\n\t\tlines.push(\n\t\t\t`${automatic.length > 0 ? 'And create' : 'Fix: create'} these records at the DNS host:`,\n\t\t\t...byHand.map((line) => ` ${line}`),\n\t\t);\n\t}\n\treturn lines.join('\\n');\n}\n\n// ============================================================================\n// The step: plan, apply, confirm, check\n// ============================================================================\n\n/** The environment variable each token-authenticated provider reads. */\nexport const DNS_TOKEN_KEYS = {\n\tgodaddy: 'GODADDY_API_TOKEN',\n\thostinger: 'HOSTINGER_API_TOKEN',\n} as const;\n\n/** A provider whose credential is a token gkm reads. */\nexport type TokenDnsProvider = keyof typeof DNS_TOKEN_KEYS;\n\n/** The tokens a stage's records are written with. */\nexport interface DnsCredentials {\n\tgodaddy?: GoDaddyCredential;\n\thostinger?: HostingerCredential;\n}\n\n/**\n * A domain whose records the deploy writes, and no token to write them with.\n * Raised before anything is built, started or written.\n */\nexport class DnsCredentialMissing extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly domain: string,\n\t\treadonly provider: TokenDnsProvider,\n\t\t/** The variable the token is read from: `GODADDY_API_TOKEN`. */\n\t\treadonly key: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${stage}''s hosts are under ${domain}, whose DNS is ${provider}'s, and ` +\n\t\t\t\t`the deploy writes their records — but ${key} is not set. In CI, add ` +\n\t\t\t\t`${key} as a secret on the '${stage}' GitHub environment and pass it ` +\n\t\t\t\t`to the step that writes the records: env: { ${key}: \\${{ secrets.${key} }} }. ` +\n\t\t\t\t`On this machine, export ${key} or run gkm login --provider ${provider}. ` +\n\t\t\t\t'With a CDN or proxy in front of the server, pass --skip-dns.',\n\t\t);\n\t\tthis.name = 'DnsCredentialMissing';\n\t}\n}\n\n/** One `dns` domain and its provider's config. */\nexport interface DnsDomain {\n\tdomain: string;\n\tconfig: DnsProviderConfig;\n}\n\n/**\n * The `dns` domain a stage's own domain (`domains.<stage>`) is under — where\n * its hosts' records go — or none.\n */\nexport function stageDnsDomains(\n\tstage: string,\n\tdomains: Readonly<Record<string, string>> | undefined,\n\tdns: WorkspaceDnsConfig | undefined,\n): DnsDomain[] {\n\tconst own = domains?.[stage];\n\tif (!own || !dns || isLocalHost(own)) return [];\n\tconst normalized = normalizeDnsConfig(dns);\n\tconst root = findRootDomain(own.toLowerCase(), normalized);\n\treturn root ? [{ domain: root, config: normalized[root]! }] : [];\n}\n\n/**\n * Each token the domains' providers need, from `credentials` — `manual`,\n * Route53 (the AWS SDK's own chain) and a provider object need none.\n *\n * @throws {DnsCredentialMissing} naming the first domain with no token\n */\nexport async function dnsCredentials(\n\tstage: string,\n\tdomains: readonly DnsDomain[],\n\tcredentials: CredentialProvider,\n): Promise<DnsCredentials> {\n\tconst found: DnsCredentials = {};\n\tfor (const { domain, config } of domains) {\n\t\tconst provider = config.provider;\n\t\tif (provider !== 'godaddy' && provider !== 'hostinger') continue;\n\t\tif (found[provider]) continue;\n\t\tconst token = await credentials.get({ kind: provider });\n\t\tif (!token?.token) {\n\t\t\tthrow new DnsCredentialMissing(\n\t\t\t\tstage,\n\t\t\t\tdomain,\n\t\t\t\tprovider,\n\t\t\t\tDNS_TOKEN_KEYS[provider],\n\t\t\t);\n\t\t}\n\t\tfound[provider] = token;\n\t}\n\treturn found;\n}\n\nexport interface StageDnsInput {\n\tstage: string;\n\t/** The stage's public hosts, read off its stack. */\n\thosts: readonly string[];\n\tserver: ServerAddress;\n\tdns: WorkspaceDnsConfig | undefined;\n\t/** Where the providers' tokens come from. */\n\tcredentials: CredentialProvider;\n\tdryRun?: boolean;\n\tlog?: (line: string) => void;\n\t/** Resolves the hosts no provider confirmed — the system resolver by default. */\n\tlookup?: HostLookup;\n\t/** The provider for a domain — `createDnsProvider` by default. */\n\tproviderFor?: (config: DnsProviderConfig) => Promise<DnsProvider | null>;\n\t/** GoDaddy's API, for tests: its base URL and how a 429 is waited out. */\n\tgodaddy?: Pick<GoDaddyProviderOptions, 'baseUrl' | 'sleep' | 'maxAttempts'>;\n\t/** The records the stage's state says gkm wrote: the stale ones are pruned. */\n\trecorded?: readonly RecordedDnsRecord[];\n\t/** The stage's wildcard site's `*.<domain>`, the one wildcard written. */\n\twildcard?: string;\n}\n\nexport interface StageDnsResult {\n\tplan: StackDnsPlan;\n\tchanges: DnsChange[];\n\t/** Hosts whose records their provider holds with the server's address. */\n\tconfirmed: string[];\n\t/** Hosts the system resolver found pointing at the server. */\n\tresolved: string[];\n\t/** The plan against the records gkm wrote for the stage before. */\n\trecorded: RecordedDnsDiff;\n\t/**\n\t * The stale records pruned, through the providers this step used — called\n\t * once the stack serves its new hosts, so a run that stops short leaves\n\t * the old ones answering. In a dry run it reads and prints.\n\t */\n\tprune: () => Promise<PrunedDnsRecord[]>;\n}\n\n/**\n * A stage's DNS, as every deploy runs it: the\n * stage's own hosts planned, written through each domain's provider where\n * they differ, and read back from it — and each record gkm wrote for a host\n * the stage no longer serves found, for `prune` to delete. Only A, AAAA and CNAME records of those\n * names are touched; nothing is a wildcard but a wildcard site's\n * `*.<domain>`, and no other name is read,\n * written or deleted. What no provider confirms — a `manual` domain, a host\n * under no domain in `dns`, a key that cannot read — is resolved publicly.\n * A dry run prints the plan and writes nothing.\n *\n * @throws {DnsCredentialMissing} before anything is read or written\n * @throws {DnsRecordsNotConfirmed} when a written record does not read back\n * @throws {HostNotPointingAtServer} when a resolved host is not the server\n */\nexport async function stageDns(input: StageDnsInput): Promise<StageDnsResult> {\n\tconst { stage, server } = input;\n\tconst log = input.log ?? ((line: string) => console.log(line));\n\tconst plan = planStackDns({\n\t\tstage,\n\t\thosts: input.hosts,\n\t\tserver,\n\t\tdns: input.dns,\n\t\t...(input.wildcard ? { wildcard: input.wildcard } : {}),\n\t});\n\tconst recorded = diffRecordedDns(plan, input.recorded ?? []);\n\t// A stale record's domain needs its provider's token too — the stage's\n\t// old domain, after it moved to another.\n\tconst dns = input.dns ? normalizeDnsConfig(input.dns) : {};\n\tconst staleDomains = [...new Set(recorded.stale.map((r) => r.domain))]\n\t\t.filter(\n\t\t\t(domain) => dns[domain] && !plan.domains.some((d) => d.domain === domain),\n\t\t)\n\t\t.map((domain) => ({ domain, config: dns[domain]! }));\n\tconst tokens = await dnsCredentials(\n\t\tstage,\n\t\t[\n\t\t\t...plan.domains.map(({ domain, config }) => ({ domain, config })),\n\t\t\t...staleDomains,\n\t\t],\n\t\tinput.credentials,\n\t);\n\tconst providers = {\n\t\tlog,\n\t\tcredentials: {\n\t\t\t...(input.godaddy ?? {}),\n\t\t\t...(tokens.godaddy ? { credential: tokens.godaddy } : {}),\n\t\t\tlog,\n\t\t},\n\t\t...(tokens.hostinger ? { hostinger: tokens.hostinger } : {}),\n\t\t...(input.providerFor ? { providerFor: input.providerFor } : {}),\n\t};\n\t// No `dns` at all: nothing to write, and every host is the person's to\n\t// point — checked, without a line per host saying so.\n\tconst applied: StackDnsApplied = !input.dns\n\t\t? { changes: [], confirmed: [], unconfirmed: [...plan.uncovered] }\n\t\t: await settleStackDns(plan, {\n\t\t\t\t...(input.dryRun ? { dryRun: true } : { confirm: true }),\n\t\t\t\t...providers,\n\t\t\t});\n\n\t// A record the apply already deleted — a change of mode — is not pruned.\n\tconst deleted = new Set(\n\t\tapplied.changes\n\t\t\t.filter((c) => c.action === 'delete')\n\t\t\t.map((c) => recordKey(fullName(c.domain, c.name), c.type)),\n\t);\n\tconst stale = recorded.stale.filter(\n\t\t(r) => !deleted.has(recordKey(r.fqdn, r.type)),\n\t);\n\tconst prune = () =>\n\t\tpruneStackDns(stale, {\n\t\t\tstage,\n\t\t\tdns: input.dns,\n\t\t\t...(input.dryRun ? { dryRun: true } : {}),\n\t\t\t...providers,\n\t\t});\n\n\tlet resolved: string[] = [];\n\tif (applied.unconfirmed.length > 0) {\n\t\tresolved = await checkStackDns({\n\t\t\tstage,\n\t\t\thosts: applied.unconfirmed,\n\t\t\tserver,\n\t\t\tdns: input.dns,\n\t\t\t...(input.lookup ? { lookup: input.lookup } : {}),\n\t\t});\n\t}\n\treturn {\n\t\tplan,\n\t\tchanges: applied.changes,\n\t\tconfirmed: applied.confirmed,\n\t\tresolved,\n\t\trecorded,\n\t\tprune,\n\t};\n}\n","/**\n * The SNS subscriptions a deploy makes for the subscribers it pushes to, and\n * keeps: what both owners of them share.\n *\n * Against SNS itself a worker never subscribes — its credentials can only\n * confirm — so the deploy subscribes each pushed subscriber's route, records\n * the ARN in the stage's state, and hands the worker those ARNs as\n * `GKM_SNS_SUBSCRIPTIONS`. Two places make them: the `s3` provider, for a\n * bucket's subscribers (it created the topic), and the compose target, for a\n * topic whose connection string the stage set by hand. Both record them the\n * same way, so one confirmation pass and one read serve both.\n */\n\nimport type {\n\tHttpSubscriptionSpec,\n\tSNSConnection,\n} from '@geekmidas/events/sns';\nimport { GkmError } from '../errors';\nimport {\n\ttype AwsProvisioning,\n\tawsClientConfig,\n\tawsEndpoint,\n\tawsProvisioningCredentials,\n} from '../providers/aws.js';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\nimport type { ResourceInput, ResourceRecord } from './StateStore.js';\n\n/** The type every recorded subscription has in the stage's state. */\nexport const SUBSCRIPTION_TYPE = 'sns-subscription';\n\n/** The state key a subscriber's SNS subscription is recorded under. */\nexport const subscriptionKey = (worker: string, name: string) =>\n\t`${SUBSCRIPTION_TYPE}:${worker}/${name}`;\n\n/** One subscription, as the deploy made it. */\nexport interface RecordedSubscription {\n\tworker: string;\n\t/** The subscriber's export. */\n\tname: string;\n\ttopicArn: string;\n\tendpoint: string;\n\tdeadLetterQueueArn?: string;\n\t/** The `type` filter of a topic subscriber; absent for a bucket's. */\n\tevents?: readonly string[];\n\t/**\n\t * The stage secret whose connection string the subscription was made\n\t * with — a topic set by hand, whose credentials are its own. Absent for a\n\t * bucket's, made with the deploy's provisioning credentials.\n\t */\n\tconnectionKey?: string;\n\t/** SNS still waits for the worker to confirm it. */\n\tpending: boolean;\n}\n\n/** What a recorded subscription is written to the stage's state as. */\nexport function subscriptionResource(\n\tsubscription: RecordedSubscription,\n\tarn: string,\n): ResourceInput {\n\tconst { name, ...data } = subscription;\n\treturn {\n\t\tkey: subscriptionKey(subscription.worker, name),\n\t\ttype: SUBSCRIPTION_TYPE,\n\t\tid: arn,\n\t\tstatus: 'ready',\n\t\tdata: { ...data, ...(data.events ? { events: [...data.events] } : {}) },\n\t};\n}\n\n/** The subscription a record holds, as an endpoint to reconcile. */\nfunction specOf(record: ResourceRecord): HttpSubscriptionSpec {\n\tconst events = record.data?.events;\n\treturn {\n\t\tname: record.key.split('/').pop()!,\n\t\tendpoint: String(record.data?.endpoint),\n\t\t...(record.data?.deadLetterQueueArn\n\t\t\t? { deadLetterQueueArn: String(record.data.deadLetterQueueArn) }\n\t\t\t: {}),\n\t\t...(Array.isArray(events) ? { events: events.map(String) } : {}),\n\t};\n}\n\n/**\n * The subscriptions the deploy recorded, by worker and export — what each\n * worker is handed as `GKM_SNS_SUBSCRIPTIONS`.\n */\nexport function recordedPushSubscriptions(\n\tresources: Readonly<Record<string, ResourceRecord>> | undefined,\n): Record<string, Record<string, string>> {\n\tconst byWorker: Record<string, Record<string, string>> = {};\n\tfor (const record of Object.values(resources ?? {})) {\n\t\tif (record.type !== SUBSCRIPTION_TYPE || !record.id) continue;\n\t\tconst [worker, name] = record.key\n\t\t\t.slice(`${SUBSCRIPTION_TYPE}:`.length)\n\t\t\t.split('/');\n\t\tif (!worker || !name) continue;\n\t\tbyWorker[worker] = { ...byWorker[worker], [name]: record.id };\n\t}\n\treturn byWorker;\n}\n\n/** A topic connection string the deploy cannot sign with. */\nexport class TopicSubscriptionUnsigned extends GkmError {\n\tconstructor(readonly connectionKey: string) {\n\t\tsuper(\n\t\t\t`'${connectionKey}' carries no keys, and the deploy found no AWS ` +\n\t\t\t\t`credentials of its own to subscribe the worker's routes with. Put ` +\n\t\t\t\t`accessKeyId and secretAccessKey in it — keys allowed ` +\n\t\t\t\t`sns:Subscribe, sns:ListSubscriptionsByTopic, ` +\n\t\t\t\t`sns:GetSubscriptionAttributes, sns:SetSubscriptionAttributes and ` +\n\t\t\t\t`sns:Unsubscribe on the topic — or sign in with \\`gkm login\\`.`,\n\t\t);\n\t\tthis.name = 'TopicSubscriptionUnsigned';\n\t}\n}\n\n/**\n * A connection to the topic a stage's connection string names, signed with\n * its own keys — or, carrying none, the deploy's.\n *\n * The emulator the environment points the SDK at stands in for SNS, as it\n * does for every provider: a string with no `endpoint` is SNS itself.\n *\n * @throws {TopicSubscriptionUnsigned} with no keys from either\n */\nexport async function topicConnection(input: {\n\tconnectionKey: string;\n\tconnectionString: string;\n\tstage: string;\n\tenv: NodeJS.ProcessEnv;\n\thome?: string;\n}): Promise<SNSConnection> {\n\tconst { SNSConnection, snsUrl } = await import('@geekmidas/events/sns');\n\tconst { topicArn, region, endpoint } = snsUrl.parse(input.connectionString);\n\tconst params = new URL(input.connectionString).searchParams;\n\tconst accessKeyId = params.get('accessKeyId');\n\tconst secretAccessKey = params.get('secretAccessKey');\n\t// The topic's own region, read off its ARN where the string names none.\n\tconst where = region ?? topicArn.split(':')[3];\n\n\tlet credentials: SNSConnectionCredentials | undefined;\n\tif (accessKeyId && secretAccessKey) {\n\t\tconst sessionToken = params.get('sessionToken');\n\t\tcredentials = {\n\t\t\taccessKeyId,\n\t\t\tsecretAccessKey,\n\t\t\t...(sessionToken ? { sessionToken } : {}),\n\t\t};\n\t} else {\n\t\tconst provisioning = await awsProvisioningCredentials({\n\t\t\tstage: input.stage,\n\t\t\tenv: input.env,\n\t\t\t...(input.home ? { home: input.home } : {}),\n\t\t});\n\t\tif (!provisioning) throw new TopicSubscriptionUnsigned(input.connectionKey);\n\t\tcredentials = (await awsClientConfig(provisioning, where ?? 'us-east-1'))\n\t\t\t.credentials;\n\t}\n\n\tconst override = endpoint ?? awsEndpoint(input.env, 'SNS');\n\treturn new SNSConnection({\n\t\ttopicArn,\n\t\t...(where ? { region: where } : {}),\n\t\t...(override ? { endpoint: override } : {}),\n\t\t...(credentials ? { credentials } : {}),\n\t});\n}\n\ntype SNSConnectionCredentials = NonNullable<\n\tConstructorParameters<typeof SNSConnection>[0]['credentials']\n>;\n\n/** A subscription still waiting to be confirmed once its worker is up. */\nexport class PushSubscriptionsUnconfirmed extends GkmError {\n\tconstructor(readonly endpoints: readonly string[]) {\n\t\tsuper(\n\t\t\t`SNS still waits for ${endpoints.join(', ')} to confirm ${endpoints.length === 1 ? 'its subscription' : 'their subscriptions'}, ` +\n\t\t\t\t`so nothing is pushed there yet. Check the worker's logs for the ` +\n\t\t\t\t`confirmation it refused, and that its host answers from the internet; ` +\n\t\t\t\t`the next deploy sends the confirmation again.`,\n\t\t);\n\t\tthis.name = 'PushSubscriptionsUnconfirmed';\n\t}\n}\n\n/**\n * Once the workers are up: every subscription recorded as pending is\n * subscribed again — SNS resends its confirmation to a worker now there to\n * answer it — and waited on until confirmed.\n *\n * The first deploy needs it: the subscription is made before the worker\n * starts, so SNS's first confirmation finds nobody.\n *\n * A bucket's subscriptions are reached with the deploy's provisioning\n * credentials; a hand-set topic's with the connection string they were made\n * with, read from the stage's secrets.\n *\n * @returns what is still pending when the wait ran out — none, normally.\n */\nexport async function confirmPendingSubscriptions(input: {\n\tworkspace: NormalizedWorkspace;\n\tstage: string;\n\tresources: Readonly<Record<string, ResourceRecord>> | undefined;\n\t/** The stage's secrets — a hand-set topic's connection string. */\n\tsecrets?: Readonly<Record<string, string>>;\n\tenv?: NodeJS.ProcessEnv;\n\thome?: string;\n\t/** How long to wait for confirmations, in milliseconds. */\n\ttimeoutMs?: number;\n\trecord?: (record: ResourceRecord) => Promise<void>;\n\tlog?: (line: string) => void;\n}): Promise<string[]> {\n\tconst env = input.env ?? process.env;\n\tconst records = Object.values(input.resources ?? {}).filter(\n\t\t(r) => r.type === SUBSCRIPTION_TYPE && r.id,\n\t);\n\tif (!records.some((r) => r.data?.pending === true)) return [];\n\n\tconst { SNSConnection, reconcileHttpSubscriptions } = await import(\n\t\t'@geekmidas/events/sns'\n\t);\n\tconst { GetSubscriptionAttributesCommand } = await import(\n\t\t'@aws-sdk/client-sns'\n\t);\n\tconst endpoint = awsEndpoint(env, 'SNS');\n\tlet provisioning: AwsProvisioning | undefined | null = null;\n\n\t// Every subscription to the same topic on the same host, not only the\n\t// pending ones: the reconcile removes what it is not handed.\n\tconst groups = new Map<string, ResourceRecord[]>();\n\tfor (const record of records) {\n\t\tconst host = new URL(String(record.data?.endpoint)).host;\n\t\tconst group = `${record.data?.topicArn}|${host}`;\n\t\tgroups.set(group, [...(groups.get(group) ?? []), record]);\n\t}\n\n\tconst left: string[] = [];\n\tfor (const [group, members] of groups) {\n\t\tconst pending = members.filter((r) => r.data?.pending === true);\n\t\tif (pending.length === 0) continue;\n\t\tconst [topicArn, host] = group.split('|') as [string, string];\n\t\tconst unreachable = () =>\n\t\t\tleft.push(...pending.map((r) => String(r.data?.endpoint)));\n\n\t\tlet connection: SNSConnection;\n\t\tconst connectionKey = members[0]!.data?.connectionKey;\n\t\tif (typeof connectionKey === 'string') {\n\t\t\tconst connectionString = input.secrets?.[connectionKey];\n\t\t\tif (!connectionString?.startsWith('sns:')) {\n\t\t\t\tunreachable();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconnection = await topicConnection({\n\t\t\t\tconnectionKey,\n\t\t\t\tconnectionString,\n\t\t\t\tstage: input.stage,\n\t\t\t\tenv,\n\t\t\t\t...(input.home ? { home: input.home } : {}),\n\t\t\t});\n\t\t} else {\n\t\t\tif (provisioning === null) {\n\t\t\t\tprovisioning = await awsProvisioningCredentials({\n\t\t\t\t\tstage: input.stage,\n\t\t\t\t\tenv,\n\t\t\t\t\t...(input.home ? { home: input.home } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (!provisioning) {\n\t\t\t\tunreachable();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The topic's own region, read off its ARN: a bucket may be elsewhere.\n\t\t\tconst region = topicArn.split(':')[3]!;\n\t\t\tconst { credentials } = await awsClientConfig(provisioning, region);\n\t\t\tconnection = new SNSConnection({\n\t\t\t\ttopicArn,\n\t\t\t\tregion,\n\t\t\t\t...(endpoint ? { endpoint } : {}),\n\t\t\t\t...(credentials ? { credentials } : {}),\n\t\t\t});\n\t\t}\n\n\t\tawait reconcileHttpSubscriptions(connection, {\n\t\t\tendpoints: members.map(specOf),\n\t\t\townedHost: host,\n\t\t});\n\n\t\tconst deadline = Date.now() + (input.timeoutMs ?? 60_000);\n\t\tfor (const record of pending) {\n\t\t\tlet confirmed = false;\n\t\t\twhile (!confirmed) {\n\t\t\t\tconst { Attributes = {} } = await connection.snsClient.send(\n\t\t\t\t\tnew GetSubscriptionAttributesCommand({\n\t\t\t\t\t\tSubscriptionArn: record.id!,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tconfirmed = Attributes.PendingConfirmation !== 'true';\n\t\t\t\tif (confirmed || Date.now() > deadline) break;\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, 1000));\n\t\t\t}\n\t\t\tif (confirmed) {\n\t\t\t\tinput.log?.(` ✓ ${record.data?.endpoint} confirmed its subscription`);\n\t\t\t\tawait input.record?.({\n\t\t\t\t\t...record,\n\t\t\t\t\tdata: { ...record.data, pending: false },\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tleft.push(String(record.data?.endpoint));\n\t\t\t}\n\t\t}\n\t\tawait connection.close();\n\t}\n\treturn left;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6BA,eAAsB,2BACrB,QACuC;CACvC,MAAM,SAAS,OAAO,IAAI,cAAc,OAAO,IAAI;CACnD,MAAM,QAAQ,SAAS,EAAE,OAAO,IAAI,CAAC;CACrC,IAAI,OAAO,SAAS,OAAO;EAAE,SAAS,OAAO;EAAS,GAAG;CAAM;CAE/D,MAAM,SAAS,MAAM,kBAAkB;EACtC,KAAK,OAAO;EACZ,GAAI,OAAO,OAAO,EAAE,MAAM,OAAO,KAAK,IAAI,CAAC;CAC5C,CAAC,CAAC,CAAC,IAAI;EAAE,MAAM;EAAO,OAAO,OAAO;CAAM,CAAC;CAC3C,IAAI,QAAQ,OAAO;CAEnB,IAAI;EACH,MAAM,EAAE,0BAA0B,MAAM,OACvC;EAED,MAAM,sBAAsB;GAAE,SAAS;GAAM,YAAY;EAAE,CAAC,CAAC,CAAC;EAC9D,OAAO;GAAE,OAAO;GAAM,GAAG;EAAM;CAChC,QAAQ;EAC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I,cAAc;IAC9B;IACA;IACA,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;IAC/B,GAAI,cAAc,EAAE,YAAY,IAAI,CAAC;GACtC,CAAC;EACF;EAEA,MAAM,2BAA2B,YAAY;GAC5C,WAAW,QAAQ,IAAI,MAAM;GAC7B,WAAW;EACZ,CAAC;EAED,MAAM,WAAW,KAAK,IAAI,KAAK,MAAM,aAAa;EAClD,KAAK,MAAM,UAAU,SAAS;GAC7B,IAAI,YAAY;GAChB,OAAO,CAAC,WAAW;IAClB,MAAM,EAAE,aAAa,CAAC,MAAM,MAAM,WAAW,UAAU,KACtD,IAAI,iCAAiC,EACpC,iBAAiB,OAAO,GACzB,CAAC,CACF;IACA,YAAY,WAAW,wBAAwB;IAC/C,IAAI,aAAa,KAAK,IAAI,IAAI,UAAU;IACxC,MAAM,IAAI,SAAS,YAAY,WAAW,SAAS,GAAI,CAAC;GACzD;GACA,IAAI,WAAW;IACd,MAAM,MAAM,QAAQ,OAAO,MAAM,SAAS,4BAA4B;IACtE,MAAM,MAAM,SAAS;KACpB,GAAG;KACH,MAAM;MAAE,GAAG,OAAO;MAAM,SAAS;KAAM;IACxC,CAAC;GACF,OACC,KAAK,KAAK,OAAO,OAAO,MAAM,QAAQ,CAAC;EAEzC;EACA,MAAM,WAAW,MAAM;CACxB;CACA,OAAO;AACR"}
@@ -0,0 +1,462 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
2
+ import { t as GkmError } from "./errors-D8Gwp5kU.mjs";
3
+ import { rt as CommandFailed, t as MissingCredential } from "./credentials-DRfP9aG7.mjs";
4
+ import { t as defineTarget } from "./define-6poNqm5O.mjs";
5
+ import { g as appKey } from "./config-BLrAd7Of.mjs";
6
+ import { m as activeSandbox } from "./discover-DbDrCQ8h.mjs";
7
+ import { s as deployedInboxEnv } from "./stack-BZG5HoVN.mjs";
8
+ import { t as LocalSandbox } from "./local-DBtepRK5.mjs";
9
+ import { n as detectPackageManager } from "./utils-D_fxUqvU.mjs";
10
+ import { join } from "node:path";
11
+ import { existsSync } from "node:fs";
12
+ import { readFile, rm } from "node:fs/promises";
13
+ import { kebabCase } from "@geekmidas/manifest";
14
+ //#region src/target/sst/health.ts
15
+ /**
16
+ * Whether a released surface answers.
17
+ *
18
+ * The paths are the ones the local stack's healthchecks use
19
+ * (`reconcile/apps.ts`): an API's `/health`, a site's `/`. A surface is
20
+ * asked a few times, because a fresh deploy can take a moment to answer — a
21
+ * Lambda's first start, a distribution still settling — and healthy means a
22
+ * 2xx, after redirects.
23
+ */
24
+ /** Surfaces that never answered healthy. */
25
+ var SurfacesUnhealthy = class extends GkmError {
26
+ stage;
27
+ surfaces;
28
+ constructor(stage, surfaces) {
29
+ const lines = surfaces.map(({ app, url, status, error }) => ` - ${app}: ${url} → ${status ?? error ?? "no answer"}`);
30
+ super(`The "${stage}" stage was deployed, but ${surfaces.length === 1 ? "a surface does" : "surfaces do"} not answer healthy:\n${lines.join("\n")}\nCheck its logs in CloudWatch, fix it, and deploy again.`);
31
+ this.stage = stage;
32
+ this.surfaces = surfaces;
33
+ this.name = "SurfacesUnhealthy";
34
+ }
35
+ };
36
+ /** `path` under `base`, keeping any path `base` already has. */
37
+ function healthUrl(base, path) {
38
+ const root = base.endsWith("/") ? base : `${base}/`;
39
+ return new URL(path.replace(/^\//, ""), root).toString();
40
+ }
41
+ /**
42
+ * Ask `url` until it answers 2xx or the attempts run out, emitting
43
+ * `health.checked` for each. Resolves with the last answer.
44
+ */
45
+ async function checkHealth(app, url, options) {
46
+ let last = { healthy: false };
47
+ for (let attempt = 1; attempt <= options.attempts; attempt++) {
48
+ options.signal.throwIfAborted();
49
+ try {
50
+ const response = await fetch(url, {
51
+ redirect: "follow",
52
+ signal: AbortSignal.any([options.signal, AbortSignal.timeout(options.timeoutMs)])
53
+ });
54
+ await response.arrayBuffer().catch(() => void 0);
55
+ last = {
56
+ healthy: response.ok,
57
+ status: response.status
58
+ };
59
+ } catch (error) {
60
+ options.signal.throwIfAborted();
61
+ last = {
62
+ healthy: false,
63
+ error: error instanceof Error ? error.message : String(error)
64
+ };
65
+ }
66
+ options.emit({
67
+ type: "health.checked",
68
+ app,
69
+ url,
70
+ healthy: last.healthy,
71
+ ...last.status !== void 0 ? { status: last.status } : {},
72
+ attempt
73
+ });
74
+ if (last.healthy) return last;
75
+ if (attempt < options.attempts) await wait(options.delayMs, options.signal);
76
+ }
77
+ return last;
78
+ }
79
+ function wait(ms, signal) {
80
+ if (ms <= 0) return Promise.resolve();
81
+ return new Promise((resolve, reject) => {
82
+ const timer = setTimeout(() => {
83
+ signal.removeEventListener("abort", stop);
84
+ resolve();
85
+ }, ms);
86
+ const stop = () => {
87
+ clearTimeout(timer);
88
+ reject(signal.reason);
89
+ };
90
+ signal.addEventListener("abort", stop, { once: true });
91
+ });
92
+ }
93
+ //#endregion
94
+ //#region src/target/sst/outputs.ts
95
+ /**
96
+ * The surface URLs an `sst deploy` reports.
97
+ *
98
+ * SST writes whatever `run()` in `sst.config.ts` returns to
99
+ * `.sst/outputs.json` after every successful deploy — `{"Api": "https://…"}`.
100
+ * What `run()` returns is the project's to write, so this reads it leniently:
101
+ * nested objects are walked, anything that is not an http(s) URL is ignored,
102
+ * and an output names a surface by its id in any casing, with or without a
103
+ * `Url` suffix (`Api`, `api`, `ApiUrl`, `API_URL`, `Api.url`).
104
+ */
105
+ /** Where SST leaves the last successful deploy's outputs, under the project. */
106
+ const SST_OUTPUTS_FILE = join(".sst", "outputs.json");
107
+ /** `.sst/outputs.json` is there, and is not JSON. */
108
+ var SstOutputsUnreadable = class extends GkmError {
109
+ path;
110
+ reason;
111
+ constructor(path, reason) {
112
+ super(`Could not read SST's outputs at ${path}: ${reason}. It is rewritten by every successful \`sst deploy\`; delete it and deploy again.`);
113
+ this.path = path;
114
+ this.reason = reason;
115
+ this.name = "SstOutputsUnreadable";
116
+ }
117
+ };
118
+ /**
119
+ * Remove what an earlier deploy wrote, so the outputs read after this one
120
+ * are this one's — not another stage's, deployed from the same checkout.
121
+ */
122
+ async function clearOutputs(cwd) {
123
+ await rm(join(cwd, SST_OUTPUTS_FILE), { force: true });
124
+ }
125
+ /** The deploy's outputs, or `{}` when it wrote none. */
126
+ async function readOutputs(cwd) {
127
+ const path = join(cwd, SST_OUTPUTS_FILE);
128
+ if (!existsSync(path)) return {};
129
+ try {
130
+ return JSON.parse(await readFile(path, "utf8"));
131
+ } catch (error) {
132
+ throw new SstOutputsUnreadable(path, error instanceof Error ? error.message : String(error));
133
+ }
134
+ }
135
+ /** Every http(s) URL in `outputs`, by its key path: `['Api', 'url']`. */
136
+ function urlsIn(value, path = [], found = []) {
137
+ if (typeof value === "string") {
138
+ if (isHttpUrl(value)) found.push({
139
+ path,
140
+ url: value
141
+ });
142
+ } else if (value && typeof value === "object" && !Array.isArray(value)) for (const [key, child] of Object.entries(value)) urlsIn(child, [...path, key], found);
143
+ return found;
144
+ }
145
+ function isHttpUrl(value) {
146
+ try {
147
+ const { protocol } = new URL(value);
148
+ return protocol === "http:" || protocol === "https:";
149
+ } catch {
150
+ return false;
151
+ }
152
+ }
153
+ /**
154
+ * The app an output's key path names, kebab-cased as app keys are: its last
155
+ * segment, without a `url` suffix — or its parent's, when the last segment
156
+ * is only `url`. Exact names are tried first, so an app called `api-url`
157
+ * still finds `ApiUrl`.
158
+ */
159
+ function namesOf(path) {
160
+ const names = [];
161
+ for (const segment of [...path].reverse()) {
162
+ const name = kebabCase(segment);
163
+ names.push(name);
164
+ const bare = name.replace(/-?url$/, "");
165
+ if (bare) {
166
+ names.push(bare);
167
+ break;
168
+ }
169
+ }
170
+ return names;
171
+ }
172
+ /**
173
+ * Each app's URL from the outputs, for the apps given. An app no output
174
+ * names is left out.
175
+ */
176
+ function surfaceUrls(outputs, apps) {
177
+ const found = urlsIn(outputs);
178
+ const urls = {};
179
+ for (const app of apps) {
180
+ const exact = found.find(({ path }) => namesOf(path)[0] === app);
181
+ const loose = found.find(({ path }) => namesOf(path).includes(app));
182
+ const match = exact ?? loose;
183
+ if (match) urls[app] = match.url;
184
+ }
185
+ return urls;
186
+ }
187
+ //#endregion
188
+ //#region src/target/sst/index.ts
189
+ /**
190
+ * The built-in `sst` target: `gkm build` writes the manifest, `sst deploy`
191
+ * provisions it, and the surfaces SST reports are health-checked.
192
+ *
193
+ * `@geekmidas/cloud` is unchanged by it: `sst.config.ts` still reads
194
+ * `.gkm/manifest/aws.ts` and `fromManifest` still makes every resource. What
195
+ * the target adds is the run around the two commands — the lock, the events,
196
+ * verification, and credentials kept where they belong.
197
+ *
198
+ * Both commands run in the sandbox: the build executes the project's code,
199
+ * and so does `sst deploy`, which evaluates `sst.config.ts`. Only the second
200
+ * needs AWS, so the AWS credential goes into that one command's environment
201
+ * and nowhere else — not the build's, not the process the deploy runs in.
202
+ * What `sst deploy` needs beyond them, the sandbox already passes: `PATH`
203
+ * for node and the package manager, and `HOME`, under which SST keeps its
204
+ * toolchain (`~/.config/sst`: bun, pulumi and its plugins) and the AWS SDK
205
+ * finds `~/.aws` for a profile. Its state — the Pulumi backend and the
206
+ * passphrase — is in the stage's own account, reached with that credential.
207
+ */
208
+ var sst_exports = /* @__PURE__ */ __exportAll({
209
+ SstConfigNotFound: () => SstConfigNotFound,
210
+ awsEnv: () => awsEnv,
211
+ createSstTarget: () => createSstTarget,
212
+ inboxEnv: () => inboxEnv,
213
+ projectCommand: () => projectCommand,
214
+ sstTarget: () => sstTarget
215
+ });
216
+ /** A cold build of every handler and site. */
217
+ const BUILD_TIMEOUT_MS = 18e5;
218
+ /**
219
+ * A first deploy creates CloudFront distributions and, with a database, a
220
+ * VPC and an RDS instance — each of which alone can take a quarter of an hour.
221
+ */
222
+ const DEPLOY_TIMEOUT_MS = 54e5;
223
+ /** The workspace has no `sst.config.ts` for `sst deploy` to run. */
224
+ var SstConfigNotFound = class extends GkmError {
225
+ cwd;
226
+ constructor(cwd) {
227
+ super(`No sst.config.ts in ${cwd}. The sst target runs \`sst deploy\` at the workspace root: scaffold one with \`gkm init --deploy sst\` and copy its sst.config.ts, or deploy through another target with --target.`);
228
+ this.cwd = cwd;
229
+ this.name = "SstConfigNotFound";
230
+ }
231
+ };
232
+ /**
233
+ * The project's own copy of `bin`, through its package manager — never one
234
+ * `npx` would download, which would be code nobody installed.
235
+ */
236
+ function projectCommand(pm, bin, args) {
237
+ switch (pm) {
238
+ case "pnpm": return ["pnpm", [
239
+ "exec",
240
+ bin,
241
+ ...args
242
+ ]];
243
+ case "yarn": return ["yarn", [bin, ...args]];
244
+ case "bun": return ["bunx", [bin, ...args]];
245
+ case "npm": return ["npx", [
246
+ "--no-install",
247
+ bin,
248
+ ...args
249
+ ]];
250
+ }
251
+ }
252
+ /**
253
+ * The variables `credential` is to the AWS SDK and to SST.
254
+ *
255
+ * A profile is passed alone: given keys too, every SDK would take the keys.
256
+ */
257
+ function awsEnv(credential) {
258
+ const region = credential.region ? {
259
+ AWS_REGION: credential.region,
260
+ AWS_DEFAULT_REGION: credential.region
261
+ } : {};
262
+ if ("profile" in credential) return {
263
+ AWS_PROFILE: credential.profile,
264
+ ...region
265
+ };
266
+ return {
267
+ AWS_ACCESS_KEY_ID: credential.accessKeyId,
268
+ AWS_SECRET_ACCESS_KEY: credential.secretAccessKey,
269
+ ...credential.sessionToken ? { AWS_SESSION_TOKEN: credential.sessionToken } : {},
270
+ ...region
271
+ };
272
+ }
273
+ /**
274
+ * `env` without any `AWS_*`, so a host sandbox that passes some cannot put
275
+ * a second account beside the one the credential names.
276
+ */
277
+ function withoutAws(env) {
278
+ return Object.fromEntries(Object.entries(env).filter(([name]) => !name.startsWith("AWS_")));
279
+ }
280
+ /** Each app's kind in the manifest, by app key: `rest-api` or `site`. */
281
+ function kindsOf(manifest) {
282
+ return new Map(Object.entries(manifest).map(([id, declaration]) => [appKey(id), declaration.kind]));
283
+ }
284
+ async function exec(ctx, run, [command, args], options) {
285
+ const result = await run.sandbox.exec(command, args, {
286
+ cwd: ctx.cwd,
287
+ env: options.env,
288
+ timeoutMs: options.timeoutMs,
289
+ output: ctx.childOutput,
290
+ signal: ctx.signal
291
+ });
292
+ if (result.exitCode !== 0) throw new CommandFailed(command, args, result.exitCode, result.signal);
293
+ }
294
+ /**
295
+ * What SST reads for each inbox, by key: the stage's domain, and what the
296
+ * inbox's provider made — its bucket's URL and its topic's string — from the
297
+ * stage's secrets, read by the same rule as on compose. SST provisions none
298
+ * of it; `fromManifest` references the topic and links the inbox's values.
299
+ */
300
+ async function inboxEnv(ctx) {
301
+ if (!Object.values(ctx.manifest).some((d) => d.kind === "inbox")) return {};
302
+ const stored = await ctx.secrets.read();
303
+ const domain = ctx.workspace.domains?.[ctx.stage];
304
+ const env = deployedInboxEnv(ctx.manifest, {
305
+ reader: "sst deploy",
306
+ stage: ctx.stage,
307
+ domain,
308
+ secrets: stored?.custom ?? {}
309
+ });
310
+ for (const value of Object.values(env)) if (value !== domain) ctx.secrets.mask(value);
311
+ return env;
312
+ }
313
+ /** The `sst` target, with its health checks tuned — for tests and hosts. */
314
+ function createSstTarget(options = {}) {
315
+ const health = {
316
+ attempts: options.health?.attempts ?? 6,
317
+ delayMs: options.health?.delayMs ?? 5e3,
318
+ timeoutMs: options.health?.timeoutMs ?? 1e4
319
+ };
320
+ return defineTarget({
321
+ name: "sst",
322
+ runtime: "aws",
323
+ capabilities: {
324
+ rollback: false,
325
+ migrations: "target",
326
+ images: false
327
+ },
328
+ credentials: ["aws"],
329
+ async validate(ctx) {
330
+ if (!existsSync(join(ctx.cwd, "sst.config.ts"))) throw new SstConfigNotFound(ctx.cwd);
331
+ const aws = await ctx.credentials.get({
332
+ kind: "aws",
333
+ stage: ctx.stage
334
+ }, { signal: ctx.signal });
335
+ if (!aws) throw new MissingCredential("aws", ctx.stage);
336
+ if (!("profile" in aws)) {
337
+ ctx.secrets.mask(aws.secretAccessKey);
338
+ if (aws.sessionToken) ctx.secrets.mask(aws.sessionToken);
339
+ }
340
+ for (const app of ctx.apps) if (ctx.workspace.apps[app]?.type === "mobile") ctx.skip(app, "mobile apps deploy through their own toolchain");
341
+ const skipped = new Set(ctx.skipped.map(({ app }) => app));
342
+ const apps = ctx.apps.filter((app) => !skipped.has(app));
343
+ ctx.logger.info(`\n🚀 Deploying "${ctx.workspace.name}" to the "${ctx.stage}" stage with SST`);
344
+ ctx.logger.info(` AWS: ${"profile" in aws ? `profile "${aws.profile}"` : "access keys"}`);
345
+ const deployable = Object.values(ctx.workspace.apps).filter((app) => app.type !== "mobile").length;
346
+ if (apps.length < deployable) ctx.logger.warn(` sst deploy deploys every construct of the stage, not only ${apps.join(", ")}.`);
347
+ return {
348
+ sandbox: activeSandbox() ?? new LocalSandbox({ root: ctx.cwd }),
349
+ pm: detectPackageManager(ctx.cwd),
350
+ aws,
351
+ apps,
352
+ urls: {}
353
+ };
354
+ },
355
+ async plan(ctx, run) {
356
+ const kinds = kindsOf(ctx.manifest);
357
+ for (const app of run.apps) ctx.emit({
358
+ type: "resource.planned",
359
+ key: `application:${app}`,
360
+ resourceType: kinds.get(app) ?? "application",
361
+ action: "ensure"
362
+ });
363
+ const [build, buildArgs] = buildCommand(ctx, run);
364
+ const [deploy, deployArgs] = deployCommand(ctx, run);
365
+ ctx.logger.info(` Would run: ${[build, ...buildArgs].join(" ")}`);
366
+ ctx.logger.info(` Would run: ${[deploy, ...deployArgs].join(" ")}`);
367
+ },
368
+ async build(ctx, run) {
369
+ ctx.logger.info("\n📦 Building the manifest SST deploys");
370
+ await exec(ctx, run, buildCommand(ctx, run), {
371
+ env: { ...run.sandbox.env },
372
+ timeoutMs: BUILD_TIMEOUT_MS
373
+ });
374
+ },
375
+ async release(ctx, run) {
376
+ ctx.logger.info(`\n☁️ sst deploy --stage ${ctx.stage}`);
377
+ await clearOutputs(ctx.cwd);
378
+ await exec(ctx, run, deployCommand(ctx, run), {
379
+ env: {
380
+ ...withoutAws(run.sandbox.env),
381
+ ...await inboxEnv(ctx),
382
+ ...awsEnv(run.aws)
383
+ },
384
+ timeoutMs: DEPLOY_TIMEOUT_MS
385
+ });
386
+ run.urls = surfaceUrls(await readOutputs(ctx.cwd), run.apps);
387
+ for (const app of run.apps) ctx.emit({
388
+ type: "app.deployed",
389
+ app,
390
+ applicationId: ctx.name(app),
391
+ imageRef: "",
392
+ url: run.urls[app] ?? ""
393
+ });
394
+ },
395
+ async verify(ctx, run) {
396
+ const unhealthy = [];
397
+ for (const app of run.apps) {
398
+ const base = run.urls[app];
399
+ if (!base) {
400
+ ctx.logger.warn(` ⚠ No URL for ${app} in SST's outputs, so it was not checked. Return it from run() in sst.config.ts — { ${app}: <its url> } — to have it checked.`);
401
+ continue;
402
+ }
403
+ const url = healthUrl(base, ctx.workspace.apps[app]?.type === "backend" ? "/health" : "/");
404
+ const answer = await checkHealth(app, url, {
405
+ ...health,
406
+ signal: ctx.signal,
407
+ emit: ctx.emit
408
+ });
409
+ if (answer.healthy) ctx.logger.info(` ✓ ${app}: ${url}`);
410
+ else unhealthy.push({
411
+ app,
412
+ url,
413
+ ...answer.status !== void 0 ? { status: answer.status } : {},
414
+ ...answer.error ? { error: answer.error } : {}
415
+ });
416
+ }
417
+ if (unhealthy.length > 0) throw new SurfacesUnhealthy(ctx.stage, unhealthy);
418
+ },
419
+ result(ctx, run) {
420
+ return {
421
+ apps: run.apps.map((appName) => ({
422
+ appName,
423
+ type: ctx.workspace.apps[appName]?.type ?? "backend",
424
+ success: true,
425
+ ...run.urls[appName] ? { url: run.urls[appName] } : {}
426
+ })),
427
+ projectId: "",
428
+ environmentId: "",
429
+ successCount: ctx.dryRun ? 0 : run.apps.length,
430
+ failedCount: 0,
431
+ stage: ctx.stage,
432
+ identity: ctx.identity.key,
433
+ tag: ctx.tag,
434
+ dryRun: ctx.dryRun,
435
+ skipped: [...ctx.skipped],
436
+ urls: { ...run.urls },
437
+ changes: []
438
+ };
439
+ }
440
+ });
441
+ }
442
+ function buildCommand(ctx, run) {
443
+ return projectCommand(run.pm, "gkm", [
444
+ "build",
445
+ "--provider",
446
+ "aws",
447
+ "--stage",
448
+ ctx.stage
449
+ ]);
450
+ }
451
+ function deployCommand(ctx, run) {
452
+ return projectCommand(run.pm, "sst", [
453
+ "deploy",
454
+ "--stage",
455
+ ctx.stage
456
+ ]);
457
+ }
458
+ const sstTarget = createSstTarget();
459
+ //#endregion
460
+ export { SurfacesUnhealthy as i, sst_exports as n, SstOutputsUnreadable as r, SstConfigNotFound as t };
461
+
462
+ //# sourceMappingURL=sst-D6Dvhr6H.mjs.map