@geekmidas/cli 10.0.0-alpha.18 → 10.0.0-alpha.181

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 (448) hide show
  1. package/README.md +323 -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-CBKH87_b.mjs +1043 -0
  7. package/dist/EndpointGenerator-CBKH87_b.mjs.map +1 -0
  8. package/dist/EndpointGenerator-iyA3HkOH.cjs +1102 -0
  9. package/dist/EndpointGenerator-iyA3HkOH.cjs.map +1 -0
  10. package/dist/LegacyStateStore-DvufVJjQ.cjs +124 -0
  11. package/dist/LegacyStateStore-DvufVJjQ.cjs.map +1 -0
  12. package/dist/LegacyStateStore-p-_Z8ucw.mjs +124 -0
  13. package/dist/LegacyStateStore-p-_Z8ucw.mjs.map +1 -0
  14. package/dist/LocalStateStore-BKAi5XsN.mjs +167 -0
  15. package/dist/LocalStateStore-BKAi5XsN.mjs.map +1 -0
  16. package/dist/LocalStateStore-DLDD6udB.cjs +178 -0
  17. package/dist/LocalStateStore-DLDD6udB.cjs.map +1 -0
  18. package/dist/OpenApiTsGenerator-CoVA3Ykv.mjs +534 -0
  19. package/dist/OpenApiTsGenerator-CoVA3Ykv.mjs.map +1 -0
  20. package/dist/OpenApiTsGenerator-vy-fOJgs.cjs +539 -0
  21. package/dist/OpenApiTsGenerator-vy-fOJgs.cjs.map +1 -0
  22. package/dist/S3StateStore-C8thID2w.mjs +223 -0
  23. package/dist/S3StateStore-C8thID2w.mjs.map +1 -0
  24. package/dist/S3StateStore-J3FztlVC.cjs +222 -0
  25. package/dist/S3StateStore-J3FztlVC.cjs.map +1 -0
  26. package/dist/SSMStateStore-0TQsme40.mjs +205 -0
  27. package/dist/SSMStateStore-0TQsme40.mjs.map +1 -0
  28. package/dist/SSMStateStore-DhkkSF1D.cjs +204 -0
  29. package/dist/SSMStateStore-DhkkSF1D.cjs.map +1 -0
  30. package/dist/SubscriberGenerator-B3jHf26s.mjs +787 -0
  31. package/dist/SubscriberGenerator-B3jHf26s.mjs.map +1 -0
  32. package/dist/SubscriberGenerator-JhwVlWBS.cjs +852 -0
  33. package/dist/SubscriberGenerator-JhwVlWBS.cjs.map +1 -0
  34. package/dist/add-DWCzdPLz.mjs +711 -0
  35. package/dist/add-DWCzdPLz.mjs.map +1 -0
  36. package/dist/add-gs34ewLG.cjs +713 -0
  37. package/dist/add-gs34ewLG.cjs.map +1 -0
  38. package/dist/appPorts-BoXMwolc.mjs +249 -0
  39. package/dist/appPorts-BoXMwolc.mjs.map +1 -0
  40. package/dist/appPorts-IW-OZmRi.cjs +296 -0
  41. package/dist/appPorts-IW-OZmRi.cjs.map +1 -0
  42. package/dist/apps-C27qrbEe.cjs +5174 -0
  43. package/dist/apps-C27qrbEe.cjs.map +1 -0
  44. package/dist/apps-D2oTQasd.mjs +4650 -0
  45. package/dist/apps-D2oTQasd.mjs.map +1 -0
  46. package/dist/aws-BXfiWNbi.cjs +108 -0
  47. package/dist/aws-BXfiWNbi.cjs.map +1 -0
  48. package/dist/aws-BjvSTTcE.mjs +97 -0
  49. package/dist/aws-BjvSTTcE.mjs.map +1 -0
  50. package/dist/awsStore-BYYCmXiq.mjs +121 -0
  51. package/dist/awsStore-BYYCmXiq.mjs.map +1 -0
  52. package/dist/awsStore-DKQUElJL.cjs +138 -0
  53. package/dist/awsStore-DKQUElJL.cjs.map +1 -0
  54. package/dist/{backup-provisioner-DIVCbfee.mjs → backup-provisioner-C8DnCmxK.mjs} +2 -2
  55. package/dist/backup-provisioner-C8DnCmxK.mjs.map +1 -0
  56. package/dist/{backup-provisioner-BmhIO_Yr.cjs → backup-provisioner-oDEsPj02.cjs} +2 -2
  57. package/dist/backup-provisioner-oDEsPj02.cjs.map +1 -0
  58. package/dist/backups/runner.cjs +519 -0
  59. package/dist/backups/runner.cjs.map +1 -0
  60. package/dist/backups/runner.d.cts +102 -0
  61. package/dist/backups/runner.d.cts.map +1 -0
  62. package/dist/backups/runner.d.mts +102 -0
  63. package/dist/backups/runner.d.mts.map +1 -0
  64. package/dist/backups/runner.mjs +506 -0
  65. package/dist/backups/runner.mjs.map +1 -0
  66. package/dist/{bundler-mwH7WOb1.mjs → bundler-CbT4y4H_.mjs} +68 -15
  67. package/dist/bundler-CbT4y4H_.mjs.map +1 -0
  68. package/dist/{bundler-mjqGAvu1.cjs → bundler-DGeOugof.cjs} +67 -14
  69. package/dist/bundler-DGeOugof.cjs.map +1 -0
  70. package/dist/cli-C-jUNT69.cjs +80 -0
  71. package/dist/cli-C-jUNT69.cjs.map +1 -0
  72. package/dist/cli-DKEJryS7.mjs +80 -0
  73. package/dist/cli-DKEJryS7.mjs.map +1 -0
  74. package/dist/clientTelemetry-BAwj6MOf.d.cts +10 -0
  75. package/dist/clientTelemetry-BAwj6MOf.d.cts.map +1 -0
  76. package/dist/clientTelemetry-CvamPJj_.d.mts +10 -0
  77. package/dist/clientTelemetry-CvamPJj_.d.mts.map +1 -0
  78. package/dist/compose-BpnSP2x7.mjs +2434 -0
  79. package/dist/compose-BpnSP2x7.mjs.map +1 -0
  80. package/dist/compose-DJAaJEqL.cjs +2925 -0
  81. package/dist/compose-DJAaJEqL.cjs.map +1 -0
  82. package/dist/compose-DmtR2f0l.cjs +3564 -0
  83. package/dist/compose-DmtR2f0l.cjs.map +1 -0
  84. package/dist/compose-Glqs13is.mjs +3451 -0
  85. package/dist/compose-Glqs13is.mjs.map +1 -0
  86. package/dist/config-BODxZemw.d.mts +291 -0
  87. package/dist/config-BODxZemw.d.mts.map +1 -0
  88. package/dist/config-C3U5HulX.d.cts +291 -0
  89. package/dist/config-C3U5HulX.d.cts.map +1 -0
  90. package/dist/config.cjs +457 -9
  91. package/dist/config.cjs.map +1 -0
  92. package/dist/config.d.cts +4 -117
  93. package/dist/config.d.mts +4 -117
  94. package/dist/config.mjs +441 -3
  95. package/dist/config.mjs.map +1 -0
  96. package/dist/credentialSchemas-D_85KW2k.mjs +236 -0
  97. package/dist/credentialSchemas-D_85KW2k.mjs.map +1 -0
  98. package/dist/credentialSchemas-DjK6xKMk.cjs +271 -0
  99. package/dist/credentialSchemas-DjK6xKMk.cjs.map +1 -0
  100. package/dist/databases-CV22HzrI.mjs +588 -0
  101. package/dist/databases-CV22HzrI.mjs.map +1 -0
  102. package/dist/databases-DwYYH2mX.cjs +703 -0
  103. package/dist/databases-DwYYH2mX.cjs.map +1 -0
  104. package/dist/dbTunnel-DUudiQWj.cjs +154 -0
  105. package/dist/dbTunnel-DUudiQWj.cjs.map +1 -0
  106. package/dist/dbTunnel-KgbAh2v1.mjs +154 -0
  107. package/dist/dbTunnel-KgbAh2v1.mjs.map +1 -0
  108. package/dist/define-BfrNaY82.mjs +106 -0
  109. package/dist/define-BfrNaY82.mjs.map +1 -0
  110. package/dist/define-zKgLY65H.cjs +153 -0
  111. package/dist/define-zKgLY65H.cjs.map +1 -0
  112. package/dist/deploy/public.cjs +211 -0
  113. package/dist/deploy/public.cjs.map +1 -0
  114. package/dist/deploy/public.d.cts +659 -0
  115. package/dist/deploy/public.d.cts.map +1 -0
  116. package/dist/deploy/public.d.mts +659 -0
  117. package/dist/deploy/public.d.mts.map +1 -0
  118. package/dist/deploy/public.mjs +144 -0
  119. package/dist/deploy/public.mjs.map +1 -0
  120. package/dist/deploy/sniffer-envparser-worker.cjs +54 -0
  121. package/dist/deploy/sniffer-envparser-worker.cjs.map +1 -0
  122. package/dist/deploy/sniffer-envparser-worker.d.cts +1 -0
  123. package/dist/deploy/sniffer-envparser-worker.d.mts +1 -0
  124. package/dist/deploy/sniffer-envparser-worker.mjs +55 -0
  125. package/dist/deploy/sniffer-envparser-worker.mjs.map +1 -0
  126. package/dist/deploy/sniffer-hooks.cjs +1 -1
  127. package/dist/deploy/sniffer-hooks.mjs +1 -1
  128. package/dist/deploy/sniffer-loader.cjs +2 -2
  129. package/dist/deploy/sniffer-loader.mjs +1 -1
  130. package/dist/deploy/sniffer-routes-worker.cjs +2 -2
  131. package/dist/deploy/sniffer-routes-worker.mjs +1 -1
  132. package/dist/deploy-UkAiPzTp.mjs +3838 -0
  133. package/dist/deploy-UkAiPzTp.mjs.map +1 -0
  134. package/dist/deploy-ycRCutW9.cjs +3894 -0
  135. package/dist/deploy-ycRCutW9.cjs.map +1 -0
  136. package/dist/destroy-Cq5Un0kf.mjs +789 -0
  137. package/dist/destroy-Cq5Un0kf.mjs.map +1 -0
  138. package/dist/destroy-DzRzQcAR.cjs +790 -0
  139. package/dist/destroy-DzRzQcAR.cjs.map +1 -0
  140. package/dist/discover-Dfmn6HQ7.mjs +940 -0
  141. package/dist/discover-Dfmn6HQ7.mjs.map +1 -0
  142. package/dist/discover-OXczlq08.cjs +1085 -0
  143. package/dist/discover-OXczlq08.cjs.map +1 -0
  144. package/dist/dns-7zc-Mc9k.cjs +2257 -0
  145. package/dist/dns-7zc-Mc9k.cjs.map +1 -0
  146. package/dist/dns-dl7WUWmB.mjs +1820 -0
  147. package/dist/dns-dl7WUWmB.mjs.map +1 -0
  148. package/dist/docker-BDqp9Pfn.cjs +1798 -0
  149. package/dist/docker-BDqp9Pfn.cjs.map +1 -0
  150. package/dist/docker-MjMWQSEN.mjs +1649 -0
  151. package/dist/docker-MjMWQSEN.mjs.map +1 -0
  152. package/dist/dokploy-B0xtYCzY.mjs +38 -0
  153. package/dist/dokploy-B0xtYCzY.mjs.map +1 -0
  154. package/dist/dokploy-D-pBRnSV.cjs +38 -0
  155. package/dist/dokploy-D-pBRnSV.cjs.map +1 -0
  156. package/dist/drivers-BQRb3KsL.mjs +294 -0
  157. package/dist/drivers-BQRb3KsL.mjs.map +1 -0
  158. package/dist/drivers-DP7__dJX.cjs +377 -0
  159. package/dist/drivers-DP7__dJX.cjs.map +1 -0
  160. package/dist/eas-9danFNrJ.mjs +334 -0
  161. package/dist/eas-9danFNrJ.mjs.map +1 -0
  162. package/dist/eas-BJRA27vb.cjs +337 -0
  163. package/dist/eas-BJRA27vb.cjs.map +1 -0
  164. package/dist/emit-C4KSXOeS.mjs +153 -0
  165. package/dist/emit-C4KSXOeS.mjs.map +1 -0
  166. package/dist/emit-DiW0kbue.cjs +164 -0
  167. package/dist/emit-DiW0kbue.cjs.map +1 -0
  168. package/dist/encryption-0IiNCA3O.cjs +90 -0
  169. package/dist/encryption-0IiNCA3O.cjs.map +1 -0
  170. package/dist/encryption-ZDhvgGvu.mjs +89 -0
  171. package/dist/encryption-ZDhvgGvu.mjs.map +1 -0
  172. package/dist/engine-Csnr6XDu.mjs +3217 -0
  173. package/dist/engine-Csnr6XDu.mjs.map +1 -0
  174. package/dist/engine-DpjIgsGn.cjs +3330 -0
  175. package/dist/engine-DpjIgsGn.cjs.map +1 -0
  176. package/dist/errors-C9uIyIDt.mjs +27 -0
  177. package/dist/errors-C9uIyIDt.mjs.map +1 -0
  178. package/dist/errors-D1x8duqI.cjs +38 -0
  179. package/dist/errors-D1x8duqI.cjs.map +1 -0
  180. package/dist/github-Dej8EWxH.mjs +986 -0
  181. package/dist/github-Dej8EWxH.mjs.map +1 -0
  182. package/dist/github-HHxVur1m.cjs +987 -0
  183. package/dist/github-HHxVur1m.cjs.map +1 -0
  184. package/dist/googlePlay-DNrD-67X.mjs +931 -0
  185. package/dist/googlePlay-DNrD-67X.mjs.map +1 -0
  186. package/dist/googlePlay-NK1zgJJm.cjs +931 -0
  187. package/dist/googlePlay-NK1zgJJm.cjs.map +1 -0
  188. package/dist/iam-BzFyFf7T.mjs +442 -0
  189. package/dist/iam-BzFyFf7T.mjs.map +1 -0
  190. package/dist/iam-WIoKnLBp.cjs +521 -0
  191. package/dist/iam-WIoKnLBp.cjs.map +1 -0
  192. package/dist/{index-RCUizGxL.d.cts → index-BKgOlfK2.d.mts} +38 -14
  193. package/dist/index-BKgOlfK2.d.mts.map +1 -0
  194. package/dist/{index-B4H4XF7A.d.mts → index-zPzigXh-.d.cts} +38 -14
  195. package/dist/index-zPzigXh-.d.cts.map +1 -0
  196. package/dist/index.cjs +14502 -12767
  197. package/dist/index.cjs.map +1 -1
  198. package/dist/index.mjs +15137 -13400
  199. package/dist/index.mjs.map +1 -1
  200. package/dist/local-BW_VIsx0.cjs +241 -0
  201. package/dist/local-BW_VIsx0.cjs.map +1 -0
  202. package/dist/local-CVp-4wDb.mjs +224 -0
  203. package/dist/local-CVp-4wDb.mjs.map +1 -0
  204. package/dist/migrate-B8fq5egU.cjs +272 -0
  205. package/dist/migrate-B8fq5egU.cjs.map +1 -0
  206. package/dist/migrate-C8yCZ5P3.mjs +181 -0
  207. package/dist/migrate-C8yCZ5P3.mjs.map +1 -0
  208. package/dist/migrate-CkSq2f7k.mjs +267 -0
  209. package/dist/migrate-CkSq2f7k.mjs.map +1 -0
  210. package/dist/migrate-FOc2erAl.cjs +181 -0
  211. package/dist/migrate-FOc2erAl.cjs.map +1 -0
  212. package/dist/next.cjs +59 -0
  213. package/dist/next.cjs.map +1 -0
  214. package/dist/next.d.cts +44 -0
  215. package/dist/next.d.cts.map +1 -0
  216. package/dist/next.d.mts +44 -0
  217. package/dist/next.d.mts.map +1 -0
  218. package/dist/next.mjs +58 -0
  219. package/dist/next.mjs.map +1 -0
  220. package/dist/notes--JQyDHim.cjs +510 -0
  221. package/dist/notes--JQyDHim.cjs.map +1 -0
  222. package/dist/notes-DXl9qERh.mjs +409 -0
  223. package/dist/notes-DXl9qERh.mjs.map +1 -0
  224. package/dist/openapi.cjs +213 -7
  225. package/dist/openapi.cjs.map +1 -0
  226. package/dist/openapi.d.cts +27 -8
  227. package/dist/openapi.d.cts.map +1 -1
  228. package/dist/openapi.d.mts +27 -8
  229. package/dist/openapi.d.mts.map +1 -1
  230. package/dist/openapi.mjs +208 -2
  231. package/dist/openapi.mjs.map +1 -0
  232. package/dist/projectBucket-CGpcWqyY.cjs +263 -0
  233. package/dist/projectBucket-CGpcWqyY.cjs.map +1 -0
  234. package/dist/projectBucket-TigJy25c.mjs +222 -0
  235. package/dist/projectBucket-TigJy25c.mjs.map +1 -0
  236. package/dist/provider-BvjDbsTR.mjs +46 -0
  237. package/dist/provider-BvjDbsTR.mjs.map +1 -0
  238. package/dist/provider-DLhgo-mB.cjs +57 -0
  239. package/dist/provider-DLhgo-mB.cjs.map +1 -0
  240. package/dist/publish-BPfW3DWi.mjs +123 -0
  241. package/dist/publish-BPfW3DWi.mjs.map +1 -0
  242. package/dist/publish-D4pC6_G0.cjs +124 -0
  243. package/dist/publish-D4pC6_G0.cjs.map +1 -0
  244. package/dist/ready-BcV28QoW.mjs +375 -0
  245. package/dist/ready-BcV28QoW.mjs.map +1 -0
  246. package/dist/ready-ByQvw4-W.cjs +404 -0
  247. package/dist/ready-ByQvw4-W.cjs.map +1 -0
  248. package/dist/reconcile/public.cjs +3 -5
  249. package/dist/reconcile/public.d.cts +33 -89
  250. package/dist/reconcile/public.d.cts.map +1 -1
  251. package/dist/reconcile/public.d.mts +33 -89
  252. package/dist/reconcile/public.d.mts.map +1 -1
  253. package/dist/reconcile/public.mjs +3 -3
  254. package/dist/reconcile--I7V4Klj.mjs +34 -0
  255. package/dist/reconcile--I7V4Klj.mjs.map +1 -0
  256. package/dist/reconcile-CuCQBa5-.cjs +34 -0
  257. package/dist/reconcile-CuCQBa5-.cjs.map +1 -0
  258. package/dist/resolve-BmBR1vBr.cjs +316 -0
  259. package/dist/resolve-BmBR1vBr.cjs.map +1 -0
  260. package/dist/resolve-DA1kORng.mjs +263 -0
  261. package/dist/resolve-DA1kORng.mjs.map +1 -0
  262. package/dist/rollback-DlgQDX8m.mjs +136 -0
  263. package/dist/rollback-DlgQDX8m.mjs.map +1 -0
  264. package/dist/rollback-tsy4pyEp.cjs +165 -0
  265. package/dist/rollback-tsy4pyEp.cjs.map +1 -0
  266. package/dist/runtime-CaejlcZt.d.mts +82 -0
  267. package/dist/runtime-CaejlcZt.d.mts.map +1 -0
  268. package/dist/runtime-D3jD4Dvn.d.cts +82 -0
  269. package/dist/runtime-D3jD4Dvn.d.cts.map +1 -0
  270. package/dist/s3-BLEF-PQU.cjs +240 -0
  271. package/dist/s3-BLEF-PQU.cjs.map +1 -0
  272. package/dist/s3-DVYiOqWs.mjs +240 -0
  273. package/dist/s3-DVYiOqWs.mjs.map +1 -0
  274. package/dist/sandbox/config-worker.cjs +43 -0
  275. package/dist/sandbox/config-worker.cjs.map +1 -0
  276. package/dist/sandbox/config-worker.d.cts +1 -0
  277. package/dist/sandbox/config-worker.d.mts +1 -0
  278. package/dist/sandbox/config-worker.mjs +44 -0
  279. package/dist/sandbox/config-worker.mjs.map +1 -0
  280. package/dist/sandbox/credentials-worker.cjs +53 -0
  281. package/dist/sandbox/credentials-worker.cjs.map +1 -0
  282. package/dist/sandbox/credentials-worker.d.cts +1 -0
  283. package/dist/sandbox/credentials-worker.d.mts +1 -0
  284. package/dist/sandbox/credentials-worker.mjs +54 -0
  285. package/dist/sandbox/credentials-worker.mjs.map +1 -0
  286. package/dist/sandbox/discover-worker.cjs +47 -0
  287. package/dist/sandbox/discover-worker.cjs.map +1 -0
  288. package/dist/sandbox/discover-worker.d.cts +1 -0
  289. package/dist/sandbox/discover-worker.d.mts +1 -0
  290. package/dist/sandbox/discover-worker.mjs +48 -0
  291. package/dist/sandbox/discover-worker.mjs.map +1 -0
  292. package/dist/sandbox/migrate-worker.cjs +75 -0
  293. package/dist/sandbox/migrate-worker.cjs.map +1 -0
  294. package/dist/sandbox/migrate-worker.d.cts +1 -0
  295. package/dist/sandbox/migrate-worker.d.mts +1 -0
  296. package/dist/sandbox/migrate-worker.mjs +76 -0
  297. package/dist/sandbox/migrate-worker.mjs.map +1 -0
  298. package/dist/{workspace-CRD9YinV.cjs → schemas-BCwKKA42.mjs} +399 -1179
  299. package/dist/schemas-BCwKKA42.mjs.map +1 -0
  300. package/dist/{workspace-Bu3xNCej.mjs → schemas-BQ_v0lEX.cjs} +487 -982
  301. package/dist/schemas-BQ_v0lEX.cjs.map +1 -0
  302. package/dist/secretsManager-CjTo6CRq.mjs +113 -0
  303. package/dist/secretsManager-CjTo6CRq.mjs.map +1 -0
  304. package/dist/secretsManager-CvmBGjdM.cjs +124 -0
  305. package/dist/secretsManager-CvmBGjdM.cjs.map +1 -0
  306. package/dist/seeds-Bc3niNVb.cjs +382 -0
  307. package/dist/seeds-Bc3niNVb.cjs.map +1 -0
  308. package/dist/seeds-Ccn0Ru2T.mjs +299 -0
  309. package/dist/seeds-Ccn0Ru2T.mjs.map +1 -0
  310. package/dist/serverSetup-B_O65wLb.cjs +685 -0
  311. package/dist/serverSetup-B_O65wLb.cjs.map +1 -0
  312. package/dist/serverSetup-Dsy8drIb.mjs +685 -0
  313. package/dist/serverSetup-Dsy8drIb.mjs.map +1 -0
  314. package/dist/sniffer-Ckx4cr-o.cjs +1997 -0
  315. package/dist/sniffer-Ckx4cr-o.cjs.map +1 -0
  316. package/dist/sniffer-fBefNUuJ.mjs +1824 -0
  317. package/dist/sniffer-fBefNUuJ.mjs.map +1 -0
  318. package/dist/snsSubscriptions-BJ0LErGk.mjs +1010 -0
  319. package/dist/snsSubscriptions-BJ0LErGk.mjs.map +1 -0
  320. package/dist/snsSubscriptions-ChbFp-QP.cjs +1135 -0
  321. package/dist/snsSubscriptions-ChbFp-QP.cjs.map +1 -0
  322. package/dist/sst-BnuPeGyy.cjs +501 -0
  323. package/dist/sst-BnuPeGyy.cjs.map +1 -0
  324. package/dist/sst-Y7H_zaEZ.mjs +478 -0
  325. package/dist/sst-Y7H_zaEZ.mjs.map +1 -0
  326. package/dist/stack-BAipv5Js.cjs +1887 -0
  327. package/dist/stack-BAipv5Js.cjs.map +1 -0
  328. package/dist/stack-BHrGbsGA.mjs +1777 -0
  329. package/dist/stack-BHrGbsGA.mjs.map +1 -0
  330. package/dist/stage-BSZ9890H.mjs +303 -0
  331. package/dist/stage-BSZ9890H.mjs.map +1 -0
  332. package/dist/stage-D7vBtLXL.cjs +332 -0
  333. package/dist/stage-D7vBtLXL.cjs.map +1 -0
  334. package/dist/stages-BeSQQQ4z.cjs +190 -0
  335. package/dist/stages-BeSQQQ4z.cjs.map +1 -0
  336. package/dist/stages-DjFKQv08.mjs +190 -0
  337. package/dist/stages-DjFKQv08.mjs.map +1 -0
  338. package/dist/target/public.cjs +15 -0
  339. package/dist/target/public.d.cts +28 -0
  340. package/dist/target/public.d.cts.map +1 -0
  341. package/dist/target/public.d.mts +28 -0
  342. package/dist/target/public.d.mts.map +1 -0
  343. package/dist/target/public.mjs +4 -0
  344. package/dist/terminal-B7G-FtkD.cjs +85 -0
  345. package/dist/terminal-B7G-FtkD.cjs.map +1 -0
  346. package/dist/terminal-lp8RwHdX.mjs +85 -0
  347. package/dist/terminal-lp8RwHdX.mjs.map +1 -0
  348. package/dist/{types-7R81hu0i.d.mts → types-CLxsw-QY.d.cts} +2135 -428
  349. package/dist/types-CLxsw-QY.d.cts.map +1 -0
  350. package/dist/{types-N7c2O2m7.d.cts → types-wLlwkSib.d.mts} +2133 -428
  351. package/dist/types-wLlwkSib.d.mts.map +1 -0
  352. package/dist/utils-D2Nk1Nv2.cjs +205 -0
  353. package/dist/utils-D2Nk1Nv2.cjs.map +1 -0
  354. package/dist/utils-D_fxUqvU.mjs +156 -0
  355. package/dist/utils-D_fxUqvU.mjs.map +1 -0
  356. package/dist/vitest.cjs +65 -0
  357. package/dist/vitest.cjs.map +1 -0
  358. package/dist/vitest.d.cts +29 -0
  359. package/dist/vitest.d.cts.map +1 -0
  360. package/dist/vitest.d.mts +29 -0
  361. package/dist/vitest.d.mts.map +1 -0
  362. package/dist/vitest.mjs +65 -0
  363. package/dist/vitest.mjs.map +1 -0
  364. package/dist/workerRuntime-BXfhbe13.cjs +108 -0
  365. package/dist/workerRuntime-BXfhbe13.cjs.map +1 -0
  366. package/dist/workerRuntime-CsOyBRx2.mjs +79 -0
  367. package/dist/workerRuntime-CsOyBRx2.mjs.map +1 -0
  368. package/dist/workspace/index.cjs +6 -2
  369. package/dist/workspace/index.d.cts +3 -3
  370. package/dist/workspace/index.d.mts +3 -3
  371. package/dist/workspace/index.mjs +2 -2
  372. package/dist/workspace-DJjhfAGf.mjs +3027 -0
  373. package/dist/workspace-DJjhfAGf.mjs.map +1 -0
  374. package/dist/workspace-wTLnc1Ef.cjs +3577 -0
  375. package/dist/workspace-wTLnc1Ef.cjs.map +1 -0
  376. package/package.json +76 -13
  377. package/dist/HostingerProvider-BY26bWwB.mjs +0 -243
  378. package/dist/HostingerProvider-BY26bWwB.mjs.map +0 -1
  379. package/dist/HostingerProvider-BZFGYYVA.cjs +0 -243
  380. package/dist/HostingerProvider-BZFGYYVA.cjs.map +0 -1
  381. package/dist/LocalStateProvider-7HR6SS2t.cjs +0 -48
  382. package/dist/LocalStateProvider-7HR6SS2t.cjs.map +0 -1
  383. package/dist/LocalStateProvider-D7QyJoLM.mjs +0 -48
  384. package/dist/LocalStateProvider-D7QyJoLM.mjs.map +0 -1
  385. package/dist/Route53Provider-Cvj40A8I.mjs +0 -209
  386. package/dist/Route53Provider-Cvj40A8I.mjs.map +0 -1
  387. package/dist/Route53Provider-DVILBsvV.cjs +0 -209
  388. package/dist/Route53Provider-DVILBsvV.cjs.map +0 -1
  389. package/dist/SSMStateProvider-B0Hu1MKZ.mjs +0 -75
  390. package/dist/SSMStateProvider-B0Hu1MKZ.mjs.map +0 -1
  391. package/dist/SSMStateProvider-VrQ-yeqd.cjs +0 -74
  392. package/dist/SSMStateProvider-VrQ-yeqd.cjs.map +0 -1
  393. package/dist/backup-provisioner-BmhIO_Yr.cjs.map +0 -1
  394. package/dist/backup-provisioner-DIVCbfee.mjs.map +0 -1
  395. package/dist/bundler-mjqGAvu1.cjs.map +0 -1
  396. package/dist/bundler-mwH7WOb1.mjs.map +0 -1
  397. package/dist/config-DSXI480r.cjs +0 -467
  398. package/dist/config-DSXI480r.cjs.map +0 -1
  399. package/dist/config-DdKkoUE1.mjs +0 -414
  400. package/dist/config-DdKkoUE1.mjs.map +0 -1
  401. package/dist/config.d.cts.map +0 -1
  402. package/dist/config.d.mts.map +0 -1
  403. package/dist/credentials-C6Pfn6GY.cjs +0 -2939
  404. package/dist/credentials-C6Pfn6GY.cjs.map +0 -1
  405. package/dist/credentials-lbv-j0Be.mjs +0 -2802
  406. package/dist/credentials-lbv-j0Be.mjs.map +0 -1
  407. package/dist/discover-BERGFg8v.cjs +0 -288
  408. package/dist/discover-BERGFg8v.cjs.map +0 -1
  409. package/dist/discover-CK-n3w6b.mjs +0 -244
  410. package/dist/discover-CK-n3w6b.mjs.map +0 -1
  411. package/dist/emit-BdoPFjZf.cjs +0 -253
  412. package/dist/emit-BdoPFjZf.cjs.map +0 -1
  413. package/dist/emit-Bzq7JsMP.mjs +0 -224
  414. package/dist/emit-Bzq7JsMP.mjs.map +0 -1
  415. package/dist/generator-LfZU7NlU.mjs +0 -247
  416. package/dist/generator-LfZU7NlU.mjs.map +0 -1
  417. package/dist/generator-Wdfp0jCS.cjs +0 -282
  418. package/dist/generator-Wdfp0jCS.cjs.map +0 -1
  419. package/dist/github-DlIrXPee.mjs +0 -216
  420. package/dist/github-DlIrXPee.mjs.map +0 -1
  421. package/dist/github-n7N9yOff.cjs +0 -216
  422. package/dist/github-n7N9yOff.cjs.map +0 -1
  423. package/dist/index-B4H4XF7A.d.mts.map +0 -1
  424. package/dist/index-RCUizGxL.d.cts.map +0 -1
  425. package/dist/openapi-B8bu_OXN.cjs +0 -2038
  426. package/dist/openapi-B8bu_OXN.cjs.map +0 -1
  427. package/dist/openapi-DfjbhrsM.mjs +0 -1991
  428. package/dist/openapi-DfjbhrsM.mjs.map +0 -1
  429. package/dist/reconcile-Cq4cO83R.cjs +0 -136
  430. package/dist/reconcile-Cq4cO83R.cjs.map +0 -1
  431. package/dist/reconcile-fmoluZmZ.mjs +0 -113
  432. package/dist/reconcile-fmoluZmZ.mjs.map +0 -1
  433. package/dist/ssm-BKN1Cg4z.mjs +0 -60
  434. package/dist/ssm-BKN1Cg4z.mjs.map +0 -1
  435. package/dist/ssm-FxeSAt35.cjs +0 -60
  436. package/dist/ssm-FxeSAt35.cjs.map +0 -1
  437. package/dist/storage-DgypfSD6.cjs +0 -351
  438. package/dist/storage-DgypfSD6.cjs.map +0 -1
  439. package/dist/storage-TP0x118M.mjs +0 -304
  440. package/dist/storage-TP0x118M.mjs.map +0 -1
  441. package/dist/transfer-2aRVVJ6I.mjs +0 -122
  442. package/dist/transfer-2aRVVJ6I.mjs.map +0 -1
  443. package/dist/transfer-C3WZVmj_.cjs +0 -151
  444. package/dist/transfer-C3WZVmj_.cjs.map +0 -1
  445. package/dist/types-7R81hu0i.d.mts.map +0 -1
  446. package/dist/types-N7c2O2m7.d.cts.map +0 -1
  447. package/dist/workspace-Bu3xNCej.mjs.map +0 -1
  448. package/dist/workspace-CRD9YinV.cjs.map +0 -1
@@ -0,0 +1,1010 @@
1
+ import { t as GkmError } from "./errors-C9uIyIDt.mjs";
2
+ import { n as findRootDomain, o as createDnsProvider, r as normalizeDnsConfig, t as extractSubdomain } from "./dns-dl7WUWmB.mjs";
3
+ import { Ft as SERVER_IPV4_KEY, It as SERVER_IPV6_KEY, Lt as cnameTarget } from "./workspace-DJjhfAGf.mjs";
4
+ import { _ as awsEndpoint, g as awsClientConfig, v as awsProvisioningCredentials } from "./stack-BHrGbsGA.mjs";
5
+ import { isIPv4, isIPv6 } from "node:net";
6
+ import { routeHosts } from "@geekmidas/edge/routes";
7
+ import { lookup } from "node:dns/promises";
8
+ import { DnsRecordsUnreadable } from "@geekmidas/edge/dns";
9
+ //#region src/compose/dns.ts
10
+ /**
11
+ * A compose stage's DNS: the records its public hosts need, and the check that
12
+ * they resolve to its server before a certificate is asked for.
13
+ *
14
+ * - **The server** (`serverAddress`): the stage's own secrets hold its public
15
+ * addresses — `GKM_SERVER_IPV4`, and `GKM_SERVER_IPV6` where it has one.
16
+ * Reserved for gkm: never handed to an app.
17
+ * - **The plan** (`planStackDns`, pure): every public host the stack serves —
18
+ * its apex, each app, each file server, the public log UI — pointed at the
19
+ * server. An A record per host (and an AAAA with an IPv6 address), or, where
20
+ * the domain's `dns` entry says `records: { mode: 'cname', target }`, one A
21
+ * record for the target and a CNAME to it for every other host but the
22
+ * apex, which DNS forbids a CNAME at.
23
+ * - **Applying it** (`applyStackDns`): through the domain's provider in `dns`,
24
+ * a record set at a time. A record with the right value is left alone; one
25
+ * with another value is replaced and the change printed. A `manual` domain
26
+ * is printed and nothing else. A dry run reads, prints and writes nothing.
27
+ * - **The check** (`checkStackDns`): each host resolved with the system
28
+ * resolver. One that is not the server stops the deploy with
29
+ * {@link HostNotPointingAtServer}, before Caddy or Traefik ask Let's Encrypt
30
+ * for a certificate it cannot get — and use up the rate limit trying.
31
+ * - **What gkm wrote before** (`diffRecordedDns`, pure): the plan against the
32
+ * records the stage's state says gkm wrote — added, kept, and stale: a
33
+ * host the stage no longer serves, after a domain or an app changed.
34
+ * - **The prune** (`pruneStackDns`): each stale record deleted through its
35
+ * domain's provider, if it still holds the value gkm wrote. One someone
36
+ * pointed elsewhere is left alone; one no provider can delete is printed.
37
+ * - **The step** (`stageDns`): all of it, as every deploy runs it — the plan applied through each provider,
38
+ * what was written read back from the provider, the stale records pruned,
39
+ * and only the hosts no provider wrote resolved publicly. A brand-new name
40
+ * is never looked up before its record exists, so no resolver caches it as
41
+ * missing.
42
+ */
43
+ /** The line that says how to set the server's address. */
44
+ function serverAddressHint(stage) {
45
+ return `gkm secrets:set ${SERVER_IPV4_KEY} '<ip>' --stage ${stage}`;
46
+ }
47
+ /** A server address in the stage's secrets that is not an address. */
48
+ var ServerAddressInvalid = class extends GkmError {
49
+ stage;
50
+ key;
51
+ value;
52
+ constructor(stage, key, value) {
53
+ const ipv4 = key === SERVER_IPV4_KEY;
54
+ super(`${key} in the '${stage}' stage's secrets is ${JSON.stringify(value)}, which is not an ${ipv4 ? "IPv4 address (like 203.0.113.10)" : "IPv6 address (like 2001:db8::10)"}. Set the server's public address: gkm secrets:set ${key} '<ip>' --stage ${stage}.`);
55
+ this.stage = stage;
56
+ this.key = key;
57
+ this.value = value;
58
+ this.name = "ServerAddressInvalid";
59
+ }
60
+ };
61
+ /**
62
+ * A compose stage that serves real domains with no server address: its hosts
63
+ * cannot be pointed or checked, and a certificate would be asked for blind.
64
+ */
65
+ var ServerAddressMissing = class extends GkmError {
66
+ stage;
67
+ domain;
68
+ constructor(stage, domain) {
69
+ super(`The '${stage}' stage serves ${domain} and its secrets hold no ${SERVER_IPV4_KEY} — the public address of the server its stack runs on, which its hosts' DNS records point at and every deploy checks before asking for certificates. Set it: ${serverAddressHint(stage)} (and ${SERVER_IPV6_KEY} for an IPv6 address).`);
70
+ this.stage = stage;
71
+ this.domain = domain;
72
+ this.name = "ServerAddressMissing";
73
+ }
74
+ };
75
+ /**
76
+ * The server's address from the stage's secrets, checked — `undefined` when
77
+ * `GKM_SERVER_IPV4` is not set.
78
+ *
79
+ * @throws {ServerAddressInvalid} for a value that is not an address
80
+ */
81
+ function serverAddress(stage, custom) {
82
+ const ipv4 = custom?.[SERVER_IPV4_KEY]?.trim();
83
+ const ipv6 = custom?.[SERVER_IPV6_KEY]?.trim();
84
+ if (ipv6 && !isIPv6(ipv6)) throw new ServerAddressInvalid(stage, SERVER_IPV6_KEY, ipv6);
85
+ if (!ipv4) return void 0;
86
+ if (!isIPv4(ipv4)) throw new ServerAddressInvalid(stage, SERVER_IPV4_KEY, ipv4);
87
+ return {
88
+ ipv4,
89
+ ...ipv6 ? { ipv6 } : {}
90
+ };
91
+ }
92
+ /**
93
+ * A name that resolves to this machine by definition — `localhost` and every
94
+ * `*.localhost` — and is in nobody's DNS.
95
+ */
96
+ function isLocalHost(host) {
97
+ const name = host.toLowerCase().replace(/\.$/, "");
98
+ return name === "localhost" || name.endsWith(".localhost");
99
+ }
100
+ /**
101
+ * The server's address, required where the stage serves real domains — not
102
+ * `*.localhost` ones, which point at this machine already.
103
+ *
104
+ * @throws {ServerAddressMissing} when the stage has a domain and no address
105
+ * @throws {ServerAddressInvalid} for a value that is not an address
106
+ */
107
+ function requiredServerAddress(stage, domain, custom) {
108
+ const server = serverAddress(stage, custom);
109
+ if (!server && domain && !isLocalHost(domain)) throw new ServerAddressMissing(stage, domain);
110
+ return server;
111
+ }
112
+ /** The types that point a name somewhere — a name holds a CNAME or the others. */
113
+ const ADDRESS_TYPES = [
114
+ "A",
115
+ "AAAA",
116
+ "CNAME"
117
+ ];
118
+ /**
119
+ * Every public host the stack serves, once each, sorted — each route's
120
+ * aliases and redirects included, which need a record and a certificate as
121
+ * much as its own host does.
122
+ */
123
+ function stackHosts(stack) {
124
+ return [...new Set(stack.routes.flatMap(routeHosts))].sort();
125
+ }
126
+ /** The TTL a domain's records are written with. */
127
+ function recordTtl(config) {
128
+ const ttl = "ttl" in config ? config.ttl : void 0;
129
+ if (ttl) return ttl;
130
+ return config.provider === "godaddy" ? 600 : 300;
131
+ }
132
+ function providerName(config) {
133
+ return typeof config.provider === "string" ? config.provider : "custom";
134
+ }
135
+ /**
136
+ * A wildcard host that is not the stage's wildcard site's: gkm writes one
137
+ * record per public host, so a stage on another server — or a name someone
138
+ * else points elsewhere — is never caught by a record it did not ask for.
139
+ * Only `*.<domain>` for a site declared `subdomain: '*'` is written, and it
140
+ * covers no name that has a record of its own.
141
+ */
142
+ var DnsWildcardRefused = class extends GkmError {
143
+ stage;
144
+ host;
145
+ constructor(stage, host) {
146
+ super(`'${stage}' would point ${host} at its server, and gkm never writes a wildcard record: each public host gets its own. Give the app a subdomain of its own instead.`);
147
+ this.stage = stage;
148
+ this.host = host;
149
+ this.name = "DnsWildcardRefused";
150
+ }
151
+ };
152
+ /** The records a stage's hosts need — pure. */
153
+ function planStackDns(input) {
154
+ const { stage, server } = input;
155
+ const dns = input.dns ? normalizeDnsConfig(input.dns) : {};
156
+ const records = /* @__PURE__ */ new Map();
157
+ const uncovered = [];
158
+ const add = (host, domain, type, value) => {
159
+ const name = extractSubdomain(host, domain);
160
+ records.set(`${domain} ${name} ${type}`, {
161
+ host,
162
+ domain,
163
+ name,
164
+ type,
165
+ value,
166
+ ttl: recordTtl(dns[domain])
167
+ });
168
+ };
169
+ const pointAt = (host, domain) => {
170
+ add(host, domain, "A", server.ipv4);
171
+ if (server.ipv6) add(host, domain, "AAAA", server.ipv6);
172
+ };
173
+ for (const raw of input.hosts) {
174
+ const host = raw.toLowerCase();
175
+ if (host.includes("*") && host !== input.wildcard?.toLowerCase()) throw new DnsWildcardRefused(stage, host);
176
+ const domain = findRootDomain(host, dns);
177
+ if (!domain) {
178
+ uncovered.push(host);
179
+ continue;
180
+ }
181
+ const target = cnameTarget(dns[domain].records, stage);
182
+ if (target) pointAt(target, domain);
183
+ if (target && host !== domain && host !== target) add(host, domain, "CNAME", target);
184
+ else pointAt(host, domain);
185
+ }
186
+ const domains = /* @__PURE__ */ new Map();
187
+ for (const record of [...records.values()].sort((a, b) => a.domain.localeCompare(b.domain) || a.name.localeCompare(b.name) || a.type.localeCompare(b.type))) {
188
+ const config = dns[record.domain];
189
+ const plan = domains.get(record.domain) ?? {
190
+ domain: record.domain,
191
+ provider: providerName(config),
192
+ config,
193
+ records: []
194
+ };
195
+ plan.records.push(record);
196
+ domains.set(record.domain, plan);
197
+ }
198
+ return {
199
+ stage,
200
+ server,
201
+ domains: [...domains.values()],
202
+ uncovered: uncovered.sort()
203
+ };
204
+ }
205
+ /** Records a provider accepted and then did not read back with their value. */
206
+ var DnsRecordsNotConfirmed = class extends GkmError {
207
+ stage;
208
+ domain;
209
+ provider;
210
+ records;
211
+ constructor(stage, domain, provider, records) {
212
+ const lines = records.map((r) => ` - ${r.host} ${r.type}: ${r.found.length > 0 ? r.found.join(", ") : "nothing"}, expected ${r.expected}`);
213
+ super(`${provider} accepted '${stage}''s records for ${domain}, and reading them back does not show them:\n${lines.join("\n")}\nDeploy again; if it persists, check the records in the provider's console — another tool may be writing the same names.`);
214
+ this.stage = stage;
215
+ this.domain = domain;
216
+ this.provider = provider;
217
+ this.records = records;
218
+ this.name = "DnsRecordsNotConfirmed";
219
+ }
220
+ };
221
+ /** `api.example.com A 203.0.113.10 (TTL 600)` */
222
+ function describe(record) {
223
+ return `${record.host.padEnd(32)} ${record.type.padEnd(5)} ${record.value} (TTL ${record.ttl})`;
224
+ }
225
+ function printManual(plan, log, why) {
226
+ log(` ${plan.domain}: ${why} — create these records at its DNS host:`);
227
+ for (const record of plan.records) log(` ${describe(record)}`);
228
+ return plan.records.map((r) => ({
229
+ domain: r.domain,
230
+ name: r.name,
231
+ type: r.type,
232
+ action: "manual",
233
+ value: r.value,
234
+ ttl: r.ttl
235
+ }));
236
+ }
237
+ /**
238
+ * The existing records of every planned name: A, AAAA and CNAME where one of
239
+ * them is planned — what the name points at, and what a change of mode
240
+ * deletes — and MX where an MX is. No other type is read.
241
+ */
242
+ async function existingRecords(provider, plan) {
243
+ const wanted = /* @__PURE__ */ new Map();
244
+ for (const record of plan.records) {
245
+ const types = ADDRESS_TYPES.includes(record.type) ? ADDRESS_TYPES : [record.type];
246
+ for (const type of types) wanted.set(`${record.name} ${type}`, {
247
+ name: record.name,
248
+ type
249
+ });
250
+ }
251
+ return readRecords(provider, plan.domain, [...wanted.values()]);
252
+ }
253
+ /** Exactly these names and types, as the provider holds them. */
254
+ async function readRecords(provider, domain, wanted) {
255
+ if (provider.readRecords) return provider.readRecords(domain, wanted);
256
+ return (await provider.getRecords(domain)).filter((r) => wanted.some((w) => w.name === r.name && w.type === r.type));
257
+ }
258
+ /** The provider for a domain's config: `providerFor`, or the real one. */
259
+ function providerResolver(options) {
260
+ return options.providerFor ?? ((config) => createDnsProvider({
261
+ config,
262
+ ...options.credentials ? { godaddy: options.credentials } : {},
263
+ ...options.hostinger ? { hostinger: options.hostinger } : {}
264
+ }));
265
+ }
266
+ /** Two values compared as DNS does: case, a trailing dot and spacing aside. */
267
+ const same = (a, b) => {
268
+ const normalize = (value) => value.trim().replace(/\.$/, "").replace(/\s+/g, " ").toLowerCase();
269
+ return normalize(a) === normalize(b);
270
+ };
271
+ /**
272
+ * What each domain's records need, compared with what is there: creates,
273
+ * updates, and the deletes a change of mode needs — a name moving from an A
274
+ * record to a CNAME, or back, cannot hold both. Nothing else is deleted: an
275
+ * MX planned at a name deletes nothing, and a CNAME or A planned at a name
276
+ * never deletes its MX.
277
+ */
278
+ function diffDomainDns(plan, existing) {
279
+ const changes = [];
280
+ const find = (name, type) => existing.find((r) => r.name === name && r.type === type);
281
+ const planned = /* @__PURE__ */ new Map();
282
+ for (const record of plan.records) {
283
+ const types = planned.get(record.name) ?? /* @__PURE__ */ new Set();
284
+ types.add(record.type);
285
+ planned.set(record.name, types);
286
+ }
287
+ for (const [name, types] of planned) {
288
+ const conflicting = types.has("CNAME") ? ["A", "AAAA"] : types.has("A") || types.has("AAAA") ? ["CNAME"] : [];
289
+ for (const type of conflicting) {
290
+ const found = find(name, type);
291
+ if (!found || found.values.length === 0) continue;
292
+ changes.push({
293
+ domain: plan.domain,
294
+ name,
295
+ type,
296
+ action: "delete",
297
+ previous: found.values.join(", ")
298
+ });
299
+ }
300
+ }
301
+ for (const record of plan.records) {
302
+ const found = find(record.name, record.type);
303
+ const base = {
304
+ domain: plan.domain,
305
+ name: record.name,
306
+ type: record.type,
307
+ value: record.value,
308
+ ttl: record.ttl
309
+ };
310
+ if (!found || found.values.length === 0) changes.push({
311
+ ...base,
312
+ action: "create"
313
+ });
314
+ else if (found.values.length === 1 && same(found.values[0], record.value)) changes.push({
315
+ ...base,
316
+ action: "unchanged"
317
+ });
318
+ else changes.push({
319
+ ...base,
320
+ action: "update",
321
+ previous: found.values.join(", ")
322
+ });
323
+ }
324
+ return changes;
325
+ }
326
+ /** A host's full name from a domain and a relative name. */
327
+ function fullName(domain, name) {
328
+ return name === "@" ? domain : `${name}.${domain}`;
329
+ }
330
+ function printChange(change, dryRun, log) {
331
+ const host = fullName(change.domain, change.name).padEnd(32);
332
+ const type = change.type.padEnd(5);
333
+ const would = dryRun ? "would " : "";
334
+ switch (change.action) {
335
+ case "unchanged":
336
+ log(` ✓ ${host} ${type} ${change.value} (TTL ${change.ttl}) — up to date`);
337
+ break;
338
+ case "create":
339
+ log(` + ${host} ${type} ${change.value} (TTL ${change.ttl}) — ${would}create`);
340
+ break;
341
+ case "update":
342
+ log(` ~ ${host} ${type} ${change.previous} → ${change.value} (TTL ${change.ttl}) — ${would}update`);
343
+ break;
344
+ case "write":
345
+ log(dryRun ? ` ? ${host} ${type} ${change.value} (TTL ${change.ttl}) — would write; current value unknown (key cannot read DNS)` : ` ! ${host} ${type} ${change.value} (TTL ${change.ttl}) — written (not diffed)`);
346
+ break;
347
+ case "delete": log(` - ${host} ${type} ${change.previous} — ${would}delete (a name cannot hold a CNAME and an A record)`);
348
+ }
349
+ }
350
+ /**
351
+ * Each domain's records, through its provider — and, with `confirm`, what was
352
+ * written read back from it. A record already holding its value is neither
353
+ * written nor read again.
354
+ *
355
+ * @throws {DnsRecordsNotConfirmed} when a written record does not read back
356
+ */
357
+ async function settleStackDns(plan, options = {}) {
358
+ const dryRun = options.dryRun === true;
359
+ const log = options.log ?? ((line) => console.log(line));
360
+ const providerFor = providerResolver(options);
361
+ const changes = [];
362
+ const confirmed = /* @__PURE__ */ new Set();
363
+ const unconfirmed = /* @__PURE__ */ new Set();
364
+ const hostsOf = (domain) => new Set(domain.records.map((r) => r.host));
365
+ for (const host of plan.uncovered) log(` ⚠ ${host} is under no domain in dns — point it at ${plan.server.ipv4} yourself`);
366
+ for (const domain of plan.domains) {
367
+ if (domain.provider === "manual") {
368
+ changes.push(...printManual(domain, log, "manual"));
369
+ for (const host of hostsOf(domain)) unconfirmed.add(host);
370
+ continue;
371
+ }
372
+ const provider = await providerFor(domain.config);
373
+ if (!provider) {
374
+ changes.push(...printManual(domain, log, "manual"));
375
+ for (const host of hostsOf(domain)) unconfirmed.add(host);
376
+ continue;
377
+ }
378
+ log(` ${domain.domain} (${provider.name})${dryRun ? " — dry run" : ""}`);
379
+ let existing;
380
+ let diff;
381
+ let unreadable = false;
382
+ try {
383
+ existing = await existingRecords(provider, domain);
384
+ diff = diffDomainDns(domain, existing);
385
+ } catch (error) {
386
+ if (!(error instanceof DnsRecordsUnreadable)) throw error;
387
+ log(` ℹ The ${provider.name} key cannot read ${domain.domain}'s DNS records, so changes cannot be diffed: every record is written (idempotent).`);
388
+ unreadable = true;
389
+ existing = [];
390
+ diff = domain.records.map((r) => ({
391
+ domain: r.domain,
392
+ name: r.name,
393
+ type: r.type,
394
+ action: "write",
395
+ value: r.value,
396
+ ttl: r.ttl
397
+ }));
398
+ }
399
+ for (const change of diff) printChange(change, dryRun, log);
400
+ if (!plan.server.ipv6) for (const name of new Set(domain.records.map((r) => r.name))) {
401
+ const aaaa = existing.find((r) => r.name === name && r.type === "AAAA");
402
+ const planned = domain.records.find((r) => r.name === name && r.type === "A");
403
+ if (aaaa && planned && aaaa.values.length > 0) log(` ⚠ ${fullName(domain.domain, name)} also has AAAA ${aaaa.values.join(", ")}: set ${SERVER_IPV6_KEY} in the '${plan.stage}' stage's secrets to the server's IPv6 address, or remove that record, or IPv6 clients go elsewhere`);
404
+ }
405
+ changes.push(...diff);
406
+ const written = new Set(diff.filter((c) => c.action !== "unchanged").map((c) => fullName(c.domain, c.name)));
407
+ for (const host of hostsOf(domain)) if (unreadable) {
408
+ if (!dryRun) unconfirmed.add(host);
409
+ } else if (!written.has(host)) confirmed.add(host);
410
+ if (dryRun) continue;
411
+ const deletes = diff.filter((c) => c.action === "delete");
412
+ if (deletes.length > 0) await provider.deleteRecords(domain.domain, deletes.map((c) => ({
413
+ name: c.name,
414
+ type: c.type
415
+ })));
416
+ const writes = diff.filter((c) => c.action === "create" || c.action === "update" || c.action === "write");
417
+ if (writes.length > 0) await provider.upsertRecords(domain.domain, writes.map((c) => ({
418
+ name: c.name,
419
+ type: c.type,
420
+ value: c.value,
421
+ ttl: c.ttl
422
+ })));
423
+ if (!options.confirm || unreadable || written.size === 0) continue;
424
+ const rewritten = {
425
+ ...domain,
426
+ records: domain.records.filter((r) => written.has(r.host))
427
+ };
428
+ const after = await existingRecords(provider, rewritten);
429
+ const missing = [];
430
+ for (const record of rewritten.records) {
431
+ const values = after.find((r) => r.name === record.name && r.type === record.type)?.values ?? [];
432
+ if (values.length !== 1 || !same(values[0], record.value)) missing.push({
433
+ host: record.host,
434
+ type: record.type,
435
+ expected: record.value,
436
+ found: values
437
+ });
438
+ }
439
+ if (missing.length > 0) throw new DnsRecordsNotConfirmed(plan.stage, domain.domain, provider.name, missing);
440
+ for (const host of written) confirmed.add(host);
441
+ log(` ✓ ${written.size} host${written.size === 1 ? "" : "s"} read back from ${provider.name}`);
442
+ }
443
+ for (const host of plan.uncovered) unconfirmed.add(host);
444
+ return {
445
+ changes,
446
+ confirmed: [...confirmed].sort(),
447
+ unconfirmed: [...unconfirmed].filter((h) => !confirmed.has(h)).sort()
448
+ };
449
+ }
450
+ /** `api.example.com A` — a record's identity, whatever its value. */
451
+ const recordKey = (fqdn, type) => `${fqdn.trim().replace(/\.$/, "").toLowerCase()} ${type.toUpperCase()}`;
452
+ /**
453
+ * The plan against the records gkm wrote for the stage — pure. A record is
454
+ * its full name and its type: one the plan has at another value is kept (the
455
+ * apply updates it), and one whose name or type the plan no longer has is
456
+ * stale — a host the stage stopped serving when its domain or an app changed,
457
+ * or an AAAA once its server has no IPv6 address.
458
+ */
459
+ function diffRecordedDns(plan, recorded) {
460
+ const planned = plan.domains.flatMap((domain) => domain.records);
461
+ const wanted = new Set(planned.map((r) => recordKey(r.host, r.type)));
462
+ const written = new Set(recorded.map((r) => recordKey(r.fqdn, r.type)));
463
+ return {
464
+ added: planned.filter((r) => !written.has(recordKey(r.host, r.type))),
465
+ kept: planned.filter((r) => written.has(recordKey(r.host, r.type))),
466
+ stale: recorded.filter((r) => !wanted.has(recordKey(r.fqdn, r.type)))
467
+ };
468
+ }
469
+ /**
470
+ * Each stale record deleted through its domain's provider — only where the
471
+ * provider still holds exactly the value gkm wrote, so a name someone has
472
+ * since pointed elsewhere is never taken from them. Where no provider can
473
+ * read and delete it — a `manual` domain, one gone from `dns`, a key that
474
+ * can only write — it is printed for a person to remove. A dry run reads
475
+ * and prints, and deletes nothing.
476
+ */
477
+ async function pruneStackDns(stale, options) {
478
+ if (stale.length === 0) return [];
479
+ const dryRun = options.dryRun === true;
480
+ const log = options.log ?? ((line) => console.log(line));
481
+ const providerFor = providerResolver(options);
482
+ const dns = options.dns ? normalizeDnsConfig(options.dns) : {};
483
+ const byDomain = /* @__PURE__ */ new Map();
484
+ for (const record of stale) byDomain.set(record.domain, [...byDomain.get(record.domain) ?? [], record]);
485
+ log(` No longer served by '${options.stage}':`);
486
+ const pruned = [];
487
+ const byHand = (domain, records, why) => {
488
+ log(` ${domain}: ${why} — remove these records at its DNS host:`);
489
+ for (const record of records) {
490
+ log(` ${record.fqdn.padEnd(32)} ${record.type.padEnd(5)} ${record.value}`);
491
+ pruned.push({
492
+ record,
493
+ action: "manual"
494
+ });
495
+ }
496
+ };
497
+ for (const [domain, records] of byDomain) {
498
+ const config = dns[domain];
499
+ if (!config) {
500
+ byHand(domain, records, "no longer in dns");
501
+ continue;
502
+ }
503
+ const provider = providerName(config) === "manual" ? null : await providerFor(config);
504
+ if (!provider) {
505
+ byHand(domain, records, "manual");
506
+ continue;
507
+ }
508
+ let existing;
509
+ try {
510
+ existing = await readRecords(provider, domain, records.map((r) => ({
511
+ name: r.name,
512
+ type: r.type
513
+ })));
514
+ } catch (error) {
515
+ if (!(error instanceof DnsRecordsUnreadable)) throw error;
516
+ byHand(domain, records, `the ${provider.name} key cannot read its records, so none is deleted unchecked`);
517
+ continue;
518
+ }
519
+ const would = dryRun ? "would " : "";
520
+ const deletes = [];
521
+ for (const record of records) {
522
+ const host = record.fqdn.padEnd(32);
523
+ const type = record.type.padEnd(5);
524
+ const found = existing.find((r) => r.name === record.name && r.type === record.type)?.values ?? [];
525
+ if (found.length === 0) {
526
+ log(` · ${host} ${type} already gone`);
527
+ pruned.push({
528
+ record,
529
+ action: "gone"
530
+ });
531
+ } else if (found.length === 1 && same(found[0], record.value)) {
532
+ log(` - ${host} ${type} ${record.value} — ${would}delete`);
533
+ deletes.push({
534
+ record,
535
+ action: "delete"
536
+ });
537
+ } else {
538
+ log(` ⚠ ${host} ${type} ${found.join(", ")} — pointed elsewhere since gkm wrote ${record.value}; left as it is`);
539
+ pruned.push({
540
+ record,
541
+ action: "changed",
542
+ found
543
+ });
544
+ }
545
+ }
546
+ if (!dryRun && deletes.length > 0) await provider.deleteRecords(domain, deletes.map(({ record }) => ({
547
+ name: record.name,
548
+ type: record.type
549
+ })));
550
+ pruned.push(...deletes);
551
+ }
552
+ return pruned;
553
+ }
554
+ /** The system resolver: what the server's own clients would be told. */
555
+ const systemLookup = async (host) => {
556
+ return (await lookup(host, { all: true })).map((a) => a.address);
557
+ };
558
+ /** Hosts that do not resolve to the stage's server. */
559
+ var HostNotPointingAtServer = class extends GkmError {
560
+ stage;
561
+ hosts;
562
+ expected;
563
+ fix;
564
+ constructor(stage, hosts, expected, fix) {
565
+ const want = expected.ipv6 ? `${expected.ipv4} (and ${expected.ipv6})` : expected.ipv4;
566
+ const lines = hosts.map((h) => ` - ${h.host} → ${h.resolved.length > 0 ? h.resolved.join(", ") : `nothing${h.error ? ` (${h.error})` : ""}`}, expected ${want}`);
567
+ super(`${hosts.length === 1 ? "A host" : `${hosts.length} hosts`} of '${stage}' do${hosts.length === 1 ? "es" : ""} not resolve to its server, so a certificate for ${hosts.length === 1 ? "it" : "them"} cannot be issued:\n${lines.join("\n")}\n${fix}\nRecords can take a few minutes to propagate. With a CDN or proxy in front of the server, pass --skip-dns.`);
568
+ this.stage = stage;
569
+ this.hosts = hosts;
570
+ this.expected = expected;
571
+ this.fix = fix;
572
+ this.name = "HostNotPointingAtServer";
573
+ }
574
+ };
575
+ /**
576
+ * The name a wildcard record is resolved through: one label no app takes,
577
+ * which only the `*` record answers.
578
+ */
579
+ const WILDCARD_PROBE = "gkm-wildcard-check";
580
+ /**
581
+ * Every host resolved: each must resolve to the server's IPv4 address and to
582
+ * nothing but the server's addresses.
583
+ *
584
+ * @throws {HostNotPointingAtServer} naming every host that does not
585
+ */
586
+ async function checkStackDns(input) {
587
+ const lookup = input.lookup ?? systemLookup;
588
+ const { server } = input;
589
+ const ours = new Set([server.ipv4, server.ipv6].filter(Boolean).map((a) => a.toLowerCase()));
590
+ const bad = [];
591
+ const ok = [];
592
+ for (const host of input.hosts) {
593
+ let resolved;
594
+ const asked = host.startsWith("*.") ? `${WILDCARD_PROBE}.${host.slice(2)}` : host;
595
+ try {
596
+ resolved = [...new Set(await lookup(asked))];
597
+ } catch (error) {
598
+ const code = error && typeof error === "object" && "code" in error ? String(error.code) : error instanceof Error ? error.message : String(error);
599
+ bad.push({
600
+ host,
601
+ resolved: [],
602
+ error: code
603
+ });
604
+ continue;
605
+ }
606
+ if (resolved.some((a) => a.toLowerCase() === server.ipv4.toLowerCase()) && resolved.every((a) => ours.has(a.toLowerCase()))) ok.push(host);
607
+ else bad.push({
608
+ host,
609
+ resolved
610
+ });
611
+ }
612
+ if (bad.length > 0) throw new HostNotPointingAtServer(input.stage, bad, {
613
+ ipv4: server.ipv4,
614
+ ...server.ipv6 ? { ipv6: server.ipv6 } : {}
615
+ }, dnsFix(input, bad));
616
+ return ok;
617
+ }
618
+ /** How to fix it: the deploy, or the records to create by hand. */
619
+ function dnsFix(input, bad) {
620
+ const hosts = bad.map((h) => h.host);
621
+ let plan;
622
+ try {
623
+ plan = planStackDns({
624
+ stage: input.stage,
625
+ hosts,
626
+ server: input.server,
627
+ dns: input.dns
628
+ });
629
+ } catch {
630
+ plan = {
631
+ stage: input.stage,
632
+ server: input.server,
633
+ domains: [],
634
+ uncovered: hosts
635
+ };
636
+ }
637
+ const automatic = plan.domains.filter((d) => d.provider !== "manual");
638
+ const byHand = [...plan.domains.filter((d) => d.provider === "manual").flatMap((d) => d.records.map(describe)), ...plan.uncovered.flatMap((host) => [`${host.padEnd(32)} A ${input.server.ipv4}`, ...input.server.ipv6 ? [`${host.padEnd(32)} AAAA ${input.server.ipv6}`] : []])];
639
+ const lines = [];
640
+ if (automatic.length > 0) lines.push(`Fix: gkm deploy --stage ${input.stage} writes the records for ${automatic.map((d) => d.domain).join(", ")} through their provider (--dry-run shows them first).`);
641
+ if (byHand.length > 0) lines.push(`${automatic.length > 0 ? "And create" : "Fix: create"} these records at the DNS host:`, ...byHand.map((line) => ` ${line}`));
642
+ return lines.join("\n");
643
+ }
644
+ /** The environment variable each token-authenticated provider reads. */
645
+ const DNS_TOKEN_KEYS = {
646
+ godaddy: "GODADDY_API_TOKEN",
647
+ hostinger: "HOSTINGER_API_TOKEN"
648
+ };
649
+ /**
650
+ * A domain whose records the deploy writes, and no token to write them with.
651
+ * Raised before anything is built, started or written.
652
+ */
653
+ var DnsCredentialMissing = class extends GkmError {
654
+ stage;
655
+ domain;
656
+ provider;
657
+ key;
658
+ constructor(stage, domain, provider, key) {
659
+ super(`'${stage}''s hosts are under ${domain}, whose DNS is ${provider}'s, and the deploy writes their records — but ${key} is not set. In CI, add ${key} as a secret on the '${stage}' GitHub environment and pass it to the step that writes the records: env: { ${key}: \${{ secrets.${key} }} }. On this machine, export ${key} or run gkm login --provider ${provider}. With a CDN or proxy in front of the server, pass --skip-dns.`);
660
+ this.stage = stage;
661
+ this.domain = domain;
662
+ this.provider = provider;
663
+ this.key = key;
664
+ this.name = "DnsCredentialMissing";
665
+ }
666
+ };
667
+ /**
668
+ * The `dns` domain a stage's own domain (`domains.<stage>`) is under — where
669
+ * its hosts' records go — or none.
670
+ */
671
+ function stageDnsDomains(stage, domains, dns) {
672
+ const own = domains?.[stage];
673
+ if (!own || !dns || isLocalHost(own)) return [];
674
+ const normalized = normalizeDnsConfig(dns);
675
+ const root = findRootDomain(own.toLowerCase(), normalized);
676
+ return root ? [{
677
+ domain: root,
678
+ config: normalized[root]
679
+ }] : [];
680
+ }
681
+ /**
682
+ * Each token the domains' providers need, from `credentials` — `manual`,
683
+ * Route53 (the AWS SDK's own chain) and a provider object need none.
684
+ *
685
+ * @throws {DnsCredentialMissing} naming the first domain with no token
686
+ */
687
+ async function dnsCredentials(stage, domains, credentials) {
688
+ const found = {};
689
+ for (const { domain, config } of domains) {
690
+ const provider = config.provider;
691
+ if (provider !== "godaddy" && provider !== "hostinger") continue;
692
+ if (found[provider]) continue;
693
+ const token = await credentials.get({ kind: provider });
694
+ if (!token?.token) throw new DnsCredentialMissing(stage, domain, provider, DNS_TOKEN_KEYS[provider]);
695
+ found[provider] = token;
696
+ }
697
+ return found;
698
+ }
699
+ /**
700
+ * A stage's DNS, as every deploy runs it: the
701
+ * stage's own hosts planned, written through each domain's provider where
702
+ * they differ, and read back from it — and each record gkm wrote for a host
703
+ * the stage no longer serves found, for `prune` to delete. Only A, AAAA and CNAME records of those
704
+ * names are touched; nothing is a wildcard but a wildcard site's
705
+ * `*.<domain>`, and no other name is read,
706
+ * written or deleted. What no provider confirms — a `manual` domain, a host
707
+ * under no domain in `dns`, a key that cannot read — is resolved publicly.
708
+ * A dry run prints the plan and writes nothing.
709
+ *
710
+ * @throws {DnsCredentialMissing} before anything is read or written
711
+ * @throws {DnsRecordsNotConfirmed} when a written record does not read back
712
+ * @throws {HostNotPointingAtServer} when a resolved host is not the server
713
+ */
714
+ async function stageDns(input) {
715
+ const { stage, server } = input;
716
+ const log = input.log ?? ((line) => console.log(line));
717
+ const plan = planStackDns({
718
+ stage,
719
+ hosts: input.hosts,
720
+ server,
721
+ dns: input.dns,
722
+ ...input.wildcard ? { wildcard: input.wildcard } : {}
723
+ });
724
+ const recorded = diffRecordedDns(plan, input.recorded ?? []);
725
+ const dns = input.dns ? normalizeDnsConfig(input.dns) : {};
726
+ const staleDomains = [...new Set(recorded.stale.map((r) => r.domain))].filter((domain) => dns[domain] && !plan.domains.some((d) => d.domain === domain)).map((domain) => ({
727
+ domain,
728
+ config: dns[domain]
729
+ }));
730
+ const tokens = await dnsCredentials(stage, [...plan.domains.map(({ domain, config }) => ({
731
+ domain,
732
+ config
733
+ })), ...staleDomains], input.credentials);
734
+ const providers = {
735
+ log,
736
+ credentials: {
737
+ ...input.godaddy ?? {},
738
+ ...tokens.godaddy ? { credential: tokens.godaddy } : {},
739
+ log
740
+ },
741
+ ...tokens.hostinger ? { hostinger: tokens.hostinger } : {},
742
+ ...input.providerFor ? { providerFor: input.providerFor } : {}
743
+ };
744
+ const applied = !input.dns ? {
745
+ changes: [],
746
+ confirmed: [],
747
+ unconfirmed: [...plan.uncovered]
748
+ } : await settleStackDns(plan, {
749
+ ...input.dryRun ? { dryRun: true } : { confirm: true },
750
+ ...providers
751
+ });
752
+ const deleted = new Set(applied.changes.filter((c) => c.action === "delete").map((c) => recordKey(fullName(c.domain, c.name), c.type)));
753
+ const stale = recorded.stale.filter((r) => !deleted.has(recordKey(r.fqdn, r.type)));
754
+ const prune = () => pruneStackDns(stale, {
755
+ stage,
756
+ dns: input.dns,
757
+ ...input.dryRun ? { dryRun: true } : {},
758
+ ...providers
759
+ });
760
+ let resolved = [];
761
+ if (applied.unconfirmed.length > 0) resolved = await checkStackDns({
762
+ stage,
763
+ hosts: applied.unconfirmed,
764
+ server,
765
+ dns: input.dns,
766
+ ...input.lookup ? { lookup: input.lookup } : {}
767
+ });
768
+ return {
769
+ plan,
770
+ changes: applied.changes,
771
+ confirmed: applied.confirmed,
772
+ resolved,
773
+ recorded,
774
+ prune
775
+ };
776
+ }
777
+ //#endregion
778
+ //#region src/deploy/snsSubscriptions.ts
779
+ /** The type every recorded subscription has in the stage's state. */
780
+ const SUBSCRIPTION_TYPE = "sns-subscription";
781
+ /**
782
+ * The type a topic the stage's providers made has in its state — a watched
783
+ * bucket's, an inbox's. Written by `ensureTopic`, with the topic's ARN as id.
784
+ */
785
+ const TOPIC_TYPE = "sns-topic";
786
+ /**
787
+ * The ARNs of the topics the stage's providers made. The deploy manages
788
+ * their subscriptions with its own credentials: the key in such a topic's
789
+ * connection string is the running app's, and may only confirm.
790
+ */
791
+ function provisionedTopics(resources) {
792
+ return new Set(Object.values(resources ?? {}).filter((record) => record.type === "sns-topic" && record.id).map((record) => record.id));
793
+ }
794
+ /** The state key a subscriber's SNS subscription is recorded under. */
795
+ const subscriptionKey = (worker, name) => `${SUBSCRIPTION_TYPE}:${worker}/${name}`;
796
+ /** What a recorded subscription is written to the stage's state as. */
797
+ function subscriptionResource(subscription, arn) {
798
+ const { name, ...data } = subscription;
799
+ return {
800
+ key: subscriptionKey(subscription.worker, name),
801
+ type: SUBSCRIPTION_TYPE,
802
+ id: arn,
803
+ status: "ready",
804
+ data: {
805
+ ...data,
806
+ ...data.events ? { events: [...data.events] } : {}
807
+ }
808
+ };
809
+ }
810
+ /** The subscription a record holds, as an endpoint to reconcile. */
811
+ function specOf(record) {
812
+ const events = record.data?.events;
813
+ return {
814
+ name: record.key.split("/").pop(),
815
+ endpoint: String(record.data?.endpoint),
816
+ ...record.data?.deadLetterQueueArn ? { deadLetterQueueArn: String(record.data.deadLetterQueueArn) } : {},
817
+ ...Array.isArray(events) ? { events: events.map(String) } : {}
818
+ };
819
+ }
820
+ /**
821
+ * The subscriptions the deploy recorded, by worker and export — what each
822
+ * worker is handed as `GKM_SNS_SUBSCRIPTIONS`.
823
+ */
824
+ function recordedPushSubscriptions(resources) {
825
+ const byWorker = {};
826
+ for (const record of Object.values(resources ?? {})) {
827
+ if (record.type !== "sns-subscription" || !record.id) continue;
828
+ const [worker, name] = record.key.slice(`${SUBSCRIPTION_TYPE}:`.length).split("/");
829
+ if (!worker || !name) continue;
830
+ byWorker[worker] = {
831
+ ...byWorker[worker],
832
+ [name]: record.id
833
+ };
834
+ }
835
+ return byWorker;
836
+ }
837
+ /** A topic connection string the deploy cannot sign with. */
838
+ var TopicSubscriptionUnsigned = class extends GkmError {
839
+ connectionKey;
840
+ constructor(connectionKey) {
841
+ super(`'${connectionKey}' carries no keys, and the deploy found no AWS credentials of its own to subscribe the worker's routes with. Put accessKeyId and secretAccessKey in it — keys allowed sns:Subscribe, sns:ListSubscriptionsByTopic, sns:GetSubscriptionAttributes, sns:SetSubscriptionAttributes and sns:Unsubscribe on the topic — or sign in with \`gkm login\`.`);
842
+ this.connectionKey = connectionKey;
843
+ this.name = "TopicSubscriptionUnsigned";
844
+ }
845
+ };
846
+ /** A topic the stage made, with no deploy credentials to manage it with. */
847
+ var ProvisionedTopicUnsigned = class extends GkmError {
848
+ topicArn;
849
+ constructor(topicArn) {
850
+ super(`${topicArn} is a topic this stage's deploy made, and its subscriptions are managed with the deploy's own AWS credentials — the key in its connection string is the app's, which may only confirm. Sign in with \`gkm login\`, or set AWS credentials in the environment, and deploy again.`);
851
+ this.topicArn = topicArn;
852
+ this.name = "ProvisionedTopicUnsigned";
853
+ }
854
+ };
855
+ /**
856
+ * A connection to the topic a stage's connection string names, signed with
857
+ * its own keys — or, carrying none, the deploy's. A topic the stage's
858
+ * providers made (`provisioned`) is always signed with the deploy's: its
859
+ * string carries the app's key, which may only confirm a subscription.
860
+ *
861
+ * The emulator the environment points the SDK at stands in for SNS, as it
862
+ * does for every provider: a string with no `endpoint` is SNS itself.
863
+ *
864
+ * @throws {TopicSubscriptionUnsigned} with no keys from either
865
+ * @throws {ProvisionedTopicUnsigned} for a provisioned topic, with no
866
+ * deploy credentials
867
+ */
868
+ async function topicConnection(input) {
869
+ const { SNSConnection, snsUrl } = await import("@geekmidas/events/sns");
870
+ const { topicArn, region, endpoint } = snsUrl.parse(input.connectionString);
871
+ const params = new URL(input.connectionString).searchParams;
872
+ const accessKeyId = params.get("accessKeyId");
873
+ const secretAccessKey = params.get("secretAccessKey");
874
+ const where = region ?? topicArn.split(":")[3];
875
+ let credentials;
876
+ if (accessKeyId && secretAccessKey && !input.provisioned) {
877
+ const sessionToken = params.get("sessionToken");
878
+ credentials = {
879
+ accessKeyId,
880
+ secretAccessKey,
881
+ ...sessionToken ? { sessionToken } : {}
882
+ };
883
+ } else {
884
+ const provisioning = await awsProvisioningCredentials({
885
+ stage: input.stage,
886
+ env: input.env,
887
+ ...input.home ? { home: input.home } : {}
888
+ });
889
+ if (!provisioning) throw input.provisioned ? new ProvisionedTopicUnsigned(topicArn) : new TopicSubscriptionUnsigned(input.connectionKey);
890
+ credentials = (await awsClientConfig(provisioning, where ?? "us-east-1")).credentials;
891
+ }
892
+ const override = endpoint ?? awsEndpoint(input.env, "SNS");
893
+ return new SNSConnection({
894
+ topicArn,
895
+ ...where ? { region: where } : {},
896
+ ...override ? { endpoint: override } : {},
897
+ ...credentials ? { credentials } : {}
898
+ });
899
+ }
900
+ /** A subscription still waiting to be confirmed once its worker is up. */
901
+ var PushSubscriptionsUnconfirmed = class extends GkmError {
902
+ endpoints;
903
+ constructor(endpoints) {
904
+ super(`SNS still waits for ${endpoints.join(", ")} to confirm ${endpoints.length === 1 ? "its subscription" : "their subscriptions"}, so nothing is pushed there yet. Check the worker's logs for the confirmation it refused, and that its host answers from the internet; the next deploy sends the confirmation again.`);
905
+ this.endpoints = endpoints;
906
+ this.name = "PushSubscriptionsUnconfirmed";
907
+ }
908
+ };
909
+ /**
910
+ * Once the workers are up: every subscription recorded as pending is
911
+ * subscribed again — SNS resends its confirmation to a worker now there to
912
+ * answer it — and waited on until confirmed.
913
+ *
914
+ * The first deploy needs it: the subscription is made before the worker
915
+ * starts, so SNS's first confirmation finds nobody.
916
+ *
917
+ * A bucket's subscriptions, and those to any topic the stage's providers
918
+ * made, are reached with the deploy's provisioning credentials; a hand-set
919
+ * topic's with the connection string they were made with, read from the
920
+ * stage's secrets.
921
+ *
922
+ * @returns what is still pending when the wait ran out — none, normally.
923
+ */
924
+ async function confirmPendingSubscriptions(input) {
925
+ const env = input.env ?? process.env;
926
+ const records = Object.values(input.resources ?? {}).filter((r) => r.type === "sns-subscription" && r.id);
927
+ if (!records.some((r) => r.data?.pending === true)) return [];
928
+ const { SNSConnection, reconcileHttpSubscriptions } = await import("@geekmidas/events/sns");
929
+ const { GetSubscriptionAttributesCommand } = await import("@aws-sdk/client-sns");
930
+ const endpoint = awsEndpoint(env, "SNS");
931
+ let provisioning = null;
932
+ const provisioned = provisionedTopics(input.resources);
933
+ const groups = /* @__PURE__ */ new Map();
934
+ for (const record of records) {
935
+ const host = new URL(String(record.data?.endpoint)).host;
936
+ const group = `${record.data?.topicArn}|${host}`;
937
+ groups.set(group, [...groups.get(group) ?? [], record]);
938
+ }
939
+ const left = [];
940
+ for (const [group, members] of groups) {
941
+ const pending = members.filter((r) => r.data?.pending === true);
942
+ if (pending.length === 0) continue;
943
+ const [topicArn, host] = group.split("|");
944
+ const unreachable = () => left.push(...pending.map((r) => String(r.data?.endpoint)));
945
+ let connection;
946
+ const connectionKey = members[0].data?.connectionKey;
947
+ if (typeof connectionKey === "string" && !provisioned.has(topicArn)) {
948
+ const connectionString = input.secrets?.[connectionKey];
949
+ if (!connectionString?.startsWith("sns:")) {
950
+ unreachable();
951
+ continue;
952
+ }
953
+ connection = await topicConnection({
954
+ connectionKey,
955
+ connectionString,
956
+ stage: input.stage,
957
+ env,
958
+ ...input.home ? { home: input.home } : {}
959
+ });
960
+ } else {
961
+ if (provisioning === null) provisioning = await awsProvisioningCredentials({
962
+ stage: input.stage,
963
+ env,
964
+ ...input.home ? { home: input.home } : {}
965
+ });
966
+ if (!provisioning) {
967
+ unreachable();
968
+ continue;
969
+ }
970
+ const region = topicArn.split(":")[3];
971
+ const { credentials } = await awsClientConfig(provisioning, region);
972
+ connection = new SNSConnection({
973
+ topicArn,
974
+ region,
975
+ ...endpoint ? { endpoint } : {},
976
+ ...credentials ? { credentials } : {}
977
+ });
978
+ }
979
+ await reconcileHttpSubscriptions(connection, {
980
+ endpoints: members.map(specOf),
981
+ ownedHost: host
982
+ });
983
+ const deadline = Date.now() + (input.timeoutMs ?? 6e4);
984
+ for (const record of pending) {
985
+ let confirmed = false;
986
+ while (!confirmed) {
987
+ const { Attributes = {} } = await connection.snsClient.send(new GetSubscriptionAttributesCommand({ SubscriptionArn: record.id }));
988
+ confirmed = Attributes.PendingConfirmation !== "true";
989
+ if (confirmed || Date.now() > deadline) break;
990
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
991
+ }
992
+ if (confirmed) {
993
+ input.log?.(` ✓ ${record.data?.endpoint} confirmed its subscription`);
994
+ await input.record?.({
995
+ ...record,
996
+ data: {
997
+ ...record.data,
998
+ pending: false
999
+ }
1000
+ });
1001
+ } else left.push(String(record.data?.endpoint));
1002
+ }
1003
+ await connection.close();
1004
+ }
1005
+ return left;
1006
+ }
1007
+ //#endregion
1008
+ export { settleStackDns as _, provisionedTopics as a, stageDnsDomains as b, subscriptionResource as c, dnsCredentials as d, isLocalHost as f, serverAddressHint as g, requiredServerAddress as h, confirmPendingSubscriptions as i, topicConnection as l, recordTtl as m, SUBSCRIPTION_TYPE as n, recordedPushSubscriptions as o, pruneStackDns as p, TOPIC_TYPE as r, subscriptionKey as s, PushSubscriptionsUnconfirmed as t, HostNotPointingAtServer as u, stackHosts as v, systemLookup as x, stageDns as y };
1009
+
1010
+ //# sourceMappingURL=snsSubscriptions-BJ0LErGk.mjs.map