@geekmidas/cli 10.0.0-alpha.187 → 10.0.0-alpha.189
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.
- package/dist/{LegacyStateStore-BYJwVE8_.mjs → LegacyStateStore-BI0-sXct.mjs} +2 -2
- package/dist/{LegacyStateStore-BYJwVE8_.mjs.map → LegacyStateStore-BI0-sXct.mjs.map} +1 -1
- package/dist/{LegacyStateStore-B3kv1Dlb.cjs → LegacyStateStore-DSl-Kjhn.cjs} +2 -2
- package/dist/{LegacyStateStore-B3kv1Dlb.cjs.map → LegacyStateStore-DSl-Kjhn.cjs.map} +1 -1
- package/dist/{LocalStateStore-CIT6SyRe.mjs → LocalStateStore-CKoytnSh.mjs} +2 -2
- package/dist/{LocalStateStore-CIT6SyRe.mjs.map → LocalStateStore-CKoytnSh.mjs.map} +1 -1
- package/dist/{LocalStateStore-D7QcuAVb.cjs → LocalStateStore-DlXihNk5.cjs} +2 -2
- package/dist/{LocalStateStore-D7QcuAVb.cjs.map → LocalStateStore-DlXihNk5.cjs.map} +1 -1
- package/dist/{S3StateStore-BufODsIW.mjs → S3StateStore-BWiLJgjA.mjs} +4 -4
- package/dist/{S3StateStore-BufODsIW.mjs.map → S3StateStore-BWiLJgjA.mjs.map} +1 -1
- package/dist/{S3StateStore-DenzHSZI.cjs → S3StateStore-DAQh1WJ_.cjs} +4 -4
- package/dist/{S3StateStore-DenzHSZI.cjs.map → S3StateStore-DAQh1WJ_.cjs.map} +1 -1
- package/dist/{SSMStateStore-BcsFXUE4.cjs → SSMStateStore-CwpsKiqW.cjs} +2 -2
- package/dist/{SSMStateStore-BcsFXUE4.cjs.map → SSMStateStore-CwpsKiqW.cjs.map} +1 -1
- package/dist/{SSMStateStore-DK8GsGGP.mjs → SSMStateStore-Dtjc3Tcy.mjs} +2 -2
- package/dist/{SSMStateStore-DK8GsGGP.mjs.map → SSMStateStore-Dtjc3Tcy.mjs.map} +1 -1
- package/dist/{add-Bp-Rr-CO.mjs → add-CgR8OZmf.mjs} +4 -4
- package/dist/{add-Bp-Rr-CO.mjs.map → add-CgR8OZmf.mjs.map} +1 -1
- package/dist/{add-BWr0-iEz.cjs → add-DgoqWfHX.cjs} +4 -4
- package/dist/{add-BWr0-iEz.cjs.map → add-DgoqWfHX.cjs.map} +1 -1
- package/dist/{bundler-aW-QiGWN.mjs → bundler-B0GTqknw.mjs} +6 -6
- package/dist/{bundler-aW-QiGWN.mjs.map → bundler-B0GTqknw.mjs.map} +1 -1
- package/dist/{bundler-Cox-23P6.cjs → bundler-ZNjpx5xS.cjs} +6 -6
- package/dist/{bundler-Cox-23P6.cjs.map → bundler-ZNjpx5xS.cjs.map} +1 -1
- package/dist/{cli-Crhs1fmo.cjs → cli-DqEhTw8n.cjs} +4 -4
- package/dist/{cli-Crhs1fmo.cjs.map → cli-DqEhTw8n.cjs.map} +1 -1
- package/dist/{cli-BsiXqFrT.mjs → cli-bjBjd1zg.mjs} +4 -4
- package/dist/{cli-BsiXqFrT.mjs.map → cli-bjBjd1zg.mjs.map} +1 -1
- package/dist/{clientTelemetry-Bzc4KXz5.d.mts → clientTelemetry-C3GsvvLK.d.cts} +2 -2
- package/dist/clientTelemetry-C3GsvvLK.d.cts.map +1 -0
- package/dist/{clientTelemetry-N8NAguGI.d.cts → clientTelemetry-Dcp0jgkV.d.mts} +2 -2
- package/dist/clientTelemetry-Dcp0jgkV.d.mts.map +1 -0
- package/dist/{compose-BcL1Swdp.mjs → compose-BE2Fi1Bs.mjs} +186 -33
- package/dist/compose-BE2Fi1Bs.mjs.map +1 -0
- package/dist/{compose-BiQ6kNhM.cjs → compose-QHm47c8E.cjs} +197 -32
- package/dist/compose-QHm47c8E.cjs.map +1 -0
- package/dist/{config-KFyPSS0R.d.cts → config-B_pfl-ZN.d.cts} +3 -3
- package/dist/{config-DpqIrrRJ.d.mts.map → config-B_pfl-ZN.d.cts.map} +1 -1
- package/dist/{config-DpqIrrRJ.d.mts → config-CDulXPTe.d.mts} +3 -3
- package/dist/{config-KFyPSS0R.d.cts.map → config-CDulXPTe.d.mts.map} +1 -1
- package/dist/config.cjs +1 -1
- package/dist/config.d.cts +3 -3
- package/dist/config.d.mts +3 -3
- package/dist/config.mjs +1 -1
- package/dist/{credentials-CJyYk-m9.cjs → credentials--QL1R8mL.cjs} +40 -5
- package/dist/credentials--QL1R8mL.cjs.map +1 -0
- package/dist/{credentials-N_yElkgc.mjs → credentials-0Kmo6GAw.mjs} +7 -6
- package/dist/credentials-0Kmo6GAw.mjs.map +1 -0
- package/dist/{credentials-8EmlMGSU.mjs → credentials-CRgp0huX.mjs} +29 -6
- package/dist/credentials-CRgp0huX.mjs.map +1 -0
- package/dist/{credentials-BsgMQm1V.cjs → credentials-No8csre7.cjs} +6 -5
- package/dist/credentials-No8csre7.cjs.map +1 -0
- package/dist/{dbTunnel-CZ-6PUzq.cjs → dbTunnel-CEHBYvbM.cjs} +5 -5
- package/dist/{dbTunnel-CZ-6PUzq.cjs.map → dbTunnel-CEHBYvbM.cjs.map} +1 -1
- package/dist/{dbTunnel-Bmj9fmXv.mjs → dbTunnel-DOiMt-yL.mjs} +5 -5
- package/dist/{dbTunnel-Bmj9fmXv.mjs.map → dbTunnel-DOiMt-yL.mjs.map} +1 -1
- package/dist/deploy/public.cjs +10 -10
- package/dist/deploy/public.d.cts +5 -5
- package/dist/deploy/public.d.mts +5 -5
- package/dist/deploy/public.mjs +10 -10
- package/dist/{deploy-DokDmyUV.mjs → deploy-KdBFBME1.mjs} +12 -11
- package/dist/deploy-KdBFBME1.mjs.map +1 -0
- package/dist/{deploy-DtO1rC_U.cjs → deploy-Pkvk9jIL.cjs} +12 -11
- package/dist/deploy-Pkvk9jIL.cjs.map +1 -0
- package/dist/{destroy-BwKhuhFd.mjs → destroy-CFc0rdP4.mjs} +10 -9
- package/dist/{destroy-BwKhuhFd.mjs.map → destroy-CFc0rdP4.mjs.map} +1 -1
- package/dist/{destroy-BKZY6QLy.cjs → destroy-oqNna46x.cjs} +10 -9
- package/dist/{destroy-BKZY6QLy.cjs.map → destroy-oqNna46x.cjs.map} +1 -1
- package/dist/{dokploy-Clnb-dRK.mjs → dokploy-BkwTpeNU.mjs} +2 -2
- package/dist/{dokploy-Clnb-dRK.mjs.map → dokploy-BkwTpeNU.mjs.map} +1 -1
- package/dist/{dokploy-BJEAhFPx.cjs → dokploy-CxEzce91.cjs} +2 -2
- package/dist/{dokploy-BJEAhFPx.cjs.map → dokploy-CxEzce91.cjs.map} +1 -1
- package/dist/{eas-PwJTBvEv.cjs → eas-DbDHF2WZ.cjs} +3 -3
- package/dist/{eas-PwJTBvEv.cjs.map → eas-DbDHF2WZ.cjs.map} +1 -1
- package/dist/{eas-RRLe1Ykb.mjs → eas-vzSPhv0B.mjs} +3 -3
- package/dist/{eas-RRLe1Ykb.mjs.map → eas-vzSPhv0B.mjs.map} +1 -1
- package/dist/{encryption-C0Obifb1.cjs → encryption-4xb0WByC.cjs} +3 -3
- package/dist/{encryption-C0Obifb1.cjs.map → encryption-4xb0WByC.cjs.map} +1 -1
- package/dist/{encryption-DsiFDtEs.mjs → encryption-BJirKe8H.mjs} +3 -3
- package/dist/{encryption-DsiFDtEs.mjs.map → encryption-BJirKe8H.mjs.map} +1 -1
- package/dist/{engine-C0gShT3p.mjs → engine-Blw0271a.mjs} +7 -7
- package/dist/{engine-C0gShT3p.mjs.map → engine-Blw0271a.mjs.map} +1 -1
- package/dist/{engine-DVDe8Hx_.cjs → engine-C-tyF0OQ.cjs} +7 -7
- package/dist/{engine-DVDe8Hx_.cjs.map → engine-C-tyF0OQ.cjs.map} +1 -1
- package/dist/{github-B0Al5cId.cjs → github-Aydv6vu5.cjs} +7 -7
- package/dist/{github-B0Al5cId.cjs.map → github-Aydv6vu5.cjs.map} +1 -1
- package/dist/{github-o9OKgpAz.mjs → github-C_h3NRr7.mjs} +7 -7
- package/dist/{github-o9OKgpAz.mjs.map → github-C_h3NRr7.mjs.map} +1 -1
- package/dist/{googlePlay-CgEgbCVa.mjs → googlePlay-B7AYn6Pc.mjs} +4 -4
- package/dist/{googlePlay-CgEgbCVa.mjs.map → googlePlay-B7AYn6Pc.mjs.map} +1 -1
- package/dist/{googlePlay-INjqj3Sc.cjs → googlePlay-DpJTysGZ.cjs} +4 -4
- package/dist/{googlePlay-INjqj3Sc.cjs.map → googlePlay-DpJTysGZ.cjs.map} +1 -1
- package/dist/{iam-DloEBLXZ.mjs → iam-CE1QQeEQ.mjs} +2 -2
- package/dist/{iam-DloEBLXZ.mjs.map → iam-CE1QQeEQ.mjs.map} +1 -1
- package/dist/{iam-SxPKYCI_.cjs → iam-DlPqLzjO.cjs} +2 -2
- package/dist/{iam-SxPKYCI_.cjs.map → iam-DlPqLzjO.cjs.map} +1 -1
- package/dist/{index-BThTZV8T.d.mts → index-CBl51bCQ.d.cts} +2 -2
- package/dist/{index-BThTZV8T.d.mts.map → index-CBl51bCQ.d.cts.map} +1 -1
- package/dist/{index-Cgd-ouyI.d.cts → index-Dqp1lLjF.d.mts} +2 -2
- package/dist/{index-Cgd-ouyI.d.cts.map → index-Dqp1lLjF.d.mts.map} +1 -1
- package/dist/index.cjs +126 -72
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +126 -72
- package/dist/index.mjs.map +1 -1
- package/dist/{local-BiM__VCH.cjs → local-BEM8UVsa.cjs} +2 -2
- package/dist/{local-BiM__VCH.cjs.map → local-BEM8UVsa.cjs.map} +1 -1
- package/dist/{local-Cnbc8rQp.mjs → local-ZaXGH2eP.mjs} +2 -2
- package/dist/{local-Cnbc8rQp.mjs.map → local-ZaXGH2eP.mjs.map} +1 -1
- package/dist/{migrate-dgTtl7hO.mjs → migrate-BuReWK8R.mjs} +5 -5
- package/dist/{migrate-dgTtl7hO.mjs.map → migrate-BuReWK8R.mjs.map} +1 -1
- package/dist/{migrate-DgONWHqx.mjs → migrate-CkeIl9YW.mjs} +3 -3
- package/dist/{migrate-DgONWHqx.mjs.map → migrate-CkeIl9YW.mjs.map} +1 -1
- package/dist/{migrate-BIuREfyX.cjs → migrate-Cq4s3V1M.cjs} +3 -3
- package/dist/{migrate-BIuREfyX.cjs.map → migrate-Cq4s3V1M.cjs.map} +1 -1
- package/dist/{migrate-DMePGfDk.cjs → migrate-DTMYWQn6.cjs} +5 -5
- package/dist/{migrate-DMePGfDk.cjs.map → migrate-DTMYWQn6.cjs.map} +1 -1
- package/dist/openapi.cjs +1 -1
- package/dist/openapi.d.cts +2 -2
- package/dist/openapi.d.mts +2 -2
- package/dist/openapi.mjs +1 -1
- package/dist/{projectBucket-DS8YAcjG.mjs → projectBucket-BaZfu9b6.mjs} +2 -2
- package/dist/{projectBucket-DS8YAcjG.mjs.map → projectBucket-BaZfu9b6.mjs.map} +1 -1
- package/dist/{projectBucket-D33fcuVv.cjs → projectBucket-CBzCpLML.cjs} +2 -2
- package/dist/{projectBucket-D33fcuVv.cjs.map → projectBucket-CBzCpLML.cjs.map} +1 -1
- package/dist/{publish-DTESp-zL.cjs → publish-CLYnKn-k.cjs} +2 -2
- package/dist/{publish-DTESp-zL.cjs.map → publish-CLYnKn-k.cjs.map} +1 -1
- package/dist/{publish-DayqXMgK.mjs → publish-UxavszCu.mjs} +2 -2
- package/dist/{publish-DayqXMgK.mjs.map → publish-UxavszCu.mjs.map} +1 -1
- package/dist/reconcile/public.d.cts +1 -1
- package/dist/reconcile/public.d.mts +1 -1
- package/dist/{resolve-CFrS9f8t.mjs → resolve-Bk9a9BVj.mjs} +4 -4
- package/dist/{resolve-CFrS9f8t.mjs.map → resolve-Bk9a9BVj.mjs.map} +1 -1
- package/dist/{resolve-smEj5R9u.cjs → resolve-CeeNr_ex.cjs} +4 -4
- package/dist/{resolve-smEj5R9u.cjs.map → resolve-CeeNr_ex.cjs.map} +1 -1
- package/dist/{rollback-Di2aDQd8.cjs → rollback-D6AdPlie.cjs} +7 -7
- package/dist/{rollback-Di2aDQd8.cjs.map → rollback-D6AdPlie.cjs.map} +1 -1
- package/dist/{rollback-Nh0ECNZP.mjs → rollback-DyMVhn7L.mjs} +7 -7
- package/dist/{rollback-Nh0ECNZP.mjs.map → rollback-DyMVhn7L.mjs.map} +1 -1
- package/dist/{runtime-Ct41f0tN.d.mts → runtime-DFG1CAWA.d.mts} +2 -2
- package/dist/{runtime-BtoiRP5G.d.cts.map → runtime-DFG1CAWA.d.mts.map} +1 -1
- package/dist/{runtime-BtoiRP5G.d.cts → runtime-DjhB4Oxn.d.cts} +2 -2
- package/dist/{runtime-Ct41f0tN.d.mts.map → runtime-DjhB4Oxn.d.cts.map} +1 -1
- package/dist/{s3-NJ6g9LT4.mjs → s3-B9UimcQe.mjs} +3 -3
- package/dist/{s3-NJ6g9LT4.mjs.map → s3-B9UimcQe.mjs.map} +1 -1
- package/dist/{s3-w4NEUmAb.cjs → s3-FbPmbPft.cjs} +3 -3
- package/dist/{s3-w4NEUmAb.cjs.map → s3-FbPmbPft.cjs.map} +1 -1
- package/dist/{serverSetup-C7M3XUzI.mjs → serverSetup-BH7_Zt0N.mjs} +7 -7
- package/dist/{serverSetup-C7M3XUzI.mjs.map → serverSetup-BH7_Zt0N.mjs.map} +1 -1
- package/dist/{serverSetup-QLq-WZ-0.cjs → serverSetup-CeFkPTVz.cjs} +7 -7
- package/dist/{serverSetup-QLq-WZ-0.cjs.map → serverSetup-CeFkPTVz.cjs.map} +1 -1
- package/dist/{sniffer-Cg5jF0Ks.mjs → sniffer-8TlRbqb0.mjs} +7 -7
- package/dist/{sniffer-Cg5jF0Ks.mjs.map → sniffer-8TlRbqb0.mjs.map} +1 -1
- package/dist/{sniffer-DaDiVZV2.cjs → sniffer-B83jVMSA.cjs} +7 -7
- package/dist/{sniffer-DaDiVZV2.cjs.map → sniffer-B83jVMSA.cjs.map} +1 -1
- package/dist/{snsSubscriptions-5EWtnPvE.cjs → snsSubscriptions-B7uEpoJ2.cjs} +12 -6
- package/dist/snsSubscriptions-B7uEpoJ2.cjs.map +1 -0
- package/dist/{snsSubscriptions-Ct4_v2HZ.mjs → snsSubscriptions-BQcD_3UK.mjs} +12 -6
- package/dist/snsSubscriptions-BQcD_3UK.mjs.map +1 -0
- package/dist/{sst-BlXVHMle.cjs → sst-D0t-8yEl.cjs} +6 -6
- package/dist/{sst-BlXVHMle.cjs.map → sst-D0t-8yEl.cjs.map} +1 -1
- package/dist/{sst-DD9MlGXY.mjs → sst-w90IUOX_.mjs} +6 -6
- package/dist/{sst-DD9MlGXY.mjs.map → sst-w90IUOX_.mjs.map} +1 -1
- package/dist/{stack-DWsG_ZL-.mjs → stack-B5-pHmtX.mjs} +64 -28
- package/dist/stack-B5-pHmtX.mjs.map +1 -0
- package/dist/{stack-dyeQ8u3c.cjs → stack-CBgOAZDP.cjs} +63 -27
- package/dist/stack-CBgOAZDP.cjs.map +1 -0
- package/dist/{stage-QJk7pMSh.mjs → stage-C6ogkiRu.mjs} +5 -5
- package/dist/{stage-QJk7pMSh.mjs.map → stage-C6ogkiRu.mjs.map} +1 -1
- package/dist/{stage-Dkd13Ije.cjs → stage-EnQ76HLW.cjs} +5 -5
- package/dist/{stage-Dkd13Ije.cjs.map → stage-EnQ76HLW.cjs.map} +1 -1
- package/dist/{stages-Dk6Lv7DY.cjs → stages-C8HQ9ozh.cjs} +2 -2
- package/dist/{stages-Dk6Lv7DY.cjs.map → stages-C8HQ9ozh.cjs.map} +1 -1
- package/dist/{stages-DFvE7iEO.mjs → stages-DnN6lwL4.mjs} +2 -2
- package/dist/{stages-DFvE7iEO.mjs.map → stages-DnN6lwL4.mjs.map} +1 -1
- package/dist/target/public.cjs +1 -1
- package/dist/target/public.d.cts +2 -2
- package/dist/target/public.d.mts +2 -2
- package/dist/target/public.mjs +1 -1
- package/dist/{terminal-ByYXHXDB.mjs → terminal-Cb58S1Yx.mjs} +2 -2
- package/dist/{terminal-ByYXHXDB.mjs.map → terminal-Cb58S1Yx.mjs.map} +1 -1
- package/dist/{terminal-CsRESfL9.cjs → terminal-D9abUcq9.cjs} +2 -2
- package/dist/{terminal-CsRESfL9.cjs.map → terminal-D9abUcq9.cjs.map} +1 -1
- package/dist/{types-CJTKWLkK.d.mts → types-B-ohhDwy.d.mts} +13 -1
- package/dist/types-B-ohhDwy.d.mts.map +1 -0
- package/dist/{types-BVDaaLas.d.cts → types-BAqI--_q.d.cts} +13 -1
- package/dist/types-BAqI--_q.d.cts.map +1 -0
- package/dist/workspace/index.cjs +1 -1
- package/dist/workspace/index.d.cts +2 -2
- package/dist/workspace/index.d.mts +2 -2
- package/dist/workspace/index.mjs +1 -1
- package/dist/{workspace-CdiCMRap.mjs → workspace-BSGUH2DO.mjs} +5 -3
- package/dist/workspace-BSGUH2DO.mjs.map +1 -0
- package/dist/{workspace-CTspddnJ.cjs → workspace-K403npiD.cjs} +5 -3
- package/dist/workspace-K403npiD.cjs.map +1 -0
- package/package.json +16 -16
- package/dist/clientTelemetry-Bzc4KXz5.d.mts.map +0 -1
- package/dist/clientTelemetry-N8NAguGI.d.cts.map +0 -1
- package/dist/compose-BcL1Swdp.mjs.map +0 -1
- package/dist/compose-BiQ6kNhM.cjs.map +0 -1
- package/dist/credentials-8EmlMGSU.mjs.map +0 -1
- package/dist/credentials-BsgMQm1V.cjs.map +0 -1
- package/dist/credentials-CJyYk-m9.cjs.map +0 -1
- package/dist/credentials-N_yElkgc.mjs.map +0 -1
- package/dist/deploy-DokDmyUV.mjs.map +0 -1
- package/dist/deploy-DtO1rC_U.cjs.map +0 -1
- package/dist/snsSubscriptions-5EWtnPvE.cjs.map +0 -1
- package/dist/snsSubscriptions-Ct4_v2HZ.mjs.map +0 -1
- package/dist/stack-DWsG_ZL-.mjs.map +0 -1
- package/dist/stack-dyeQ8u3c.cjs.map +0 -1
- package/dist/types-BVDaaLas.d.cts.map +0 -1
- package/dist/types-CJTKWLkK.d.mts.map +0 -1
- package/dist/workspace-CTspddnJ.cjs.map +0 -1
- package/dist/workspace-CdiCMRap.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_errors = require("./errors-D1x8duqI.cjs");
|
|
2
|
-
const require_stack = require("./stack-
|
|
3
|
-
const require_workspace = require("./workspace-
|
|
2
|
+
const require_stack = require("./stack-CBgOAZDP.cjs");
|
|
3
|
+
const require_workspace = require("./workspace-K403npiD.cjs");
|
|
4
4
|
let node_net = require("node:net");
|
|
5
5
|
let _geekmidas_edge_routes = require("@geekmidas/edge/routes");
|
|
6
6
|
let node_dns_promises = require("node:dns/promises");
|
|
@@ -259,7 +259,8 @@ function providerResolver(options) {
|
|
|
259
259
|
return options.providerFor ?? ((config) => require_stack.createDnsProvider({
|
|
260
260
|
config,
|
|
261
261
|
...options.credentials ? { godaddy: options.credentials } : {},
|
|
262
|
-
...options.hostinger ? { hostinger: options.hostinger } : {}
|
|
262
|
+
...options.hostinger ? { hostinger: options.hostinger } : {},
|
|
263
|
+
...options.cloudflare ? { cloudflare: options.cloudflare } : {}
|
|
263
264
|
}));
|
|
264
265
|
}
|
|
265
266
|
/** Two values compared as DNS does: case, a trailing dot and spacing aside. */
|
|
@@ -643,8 +644,12 @@ function dnsFix(input, bad) {
|
|
|
643
644
|
/** The environment variable each token-authenticated provider reads. */
|
|
644
645
|
const DNS_TOKEN_KEYS = {
|
|
645
646
|
godaddy: "GODADDY_API_TOKEN",
|
|
646
|
-
hostinger: "HOSTINGER_API_TOKEN"
|
|
647
|
+
hostinger: "HOSTINGER_API_TOKEN",
|
|
648
|
+
cloudflare: "CLOUDFLARE_API_TOKEN"
|
|
647
649
|
};
|
|
650
|
+
function isTokenDnsProvider(provider) {
|
|
651
|
+
return typeof provider === "string" && Object.hasOwn(DNS_TOKEN_KEYS, provider);
|
|
652
|
+
}
|
|
648
653
|
/**
|
|
649
654
|
* A domain whose records the deploy writes, and no token to write them with.
|
|
650
655
|
* Raised before anything is built, started or written.
|
|
@@ -687,7 +692,7 @@ async function dnsCredentials(stage, domains, credentials) {
|
|
|
687
692
|
const found = {};
|
|
688
693
|
for (const { domain, config } of domains) {
|
|
689
694
|
const provider = config.provider;
|
|
690
|
-
if (provider
|
|
695
|
+
if (!isTokenDnsProvider(provider)) continue;
|
|
691
696
|
if (found[provider]) continue;
|
|
692
697
|
const token = await credentials.get({ kind: provider });
|
|
693
698
|
if (!token?.token) throw new DnsCredentialMissing(stage, domain, provider, DNS_TOKEN_KEYS[provider]);
|
|
@@ -738,6 +743,7 @@ async function stageDns(input) {
|
|
|
738
743
|
log
|
|
739
744
|
},
|
|
740
745
|
...tokens.hostinger ? { hostinger: tokens.hostinger } : {},
|
|
746
|
+
...tokens.cloudflare ? { cloudflare: tokens.cloudflare } : {},
|
|
741
747
|
...input.providerFor ? { providerFor: input.providerFor } : {}
|
|
742
748
|
};
|
|
743
749
|
const applied = !input.dns ? {
|
|
@@ -1131,4 +1137,4 @@ Object.defineProperty(exports, "topicConnection", {
|
|
|
1131
1137
|
}
|
|
1132
1138
|
});
|
|
1133
1139
|
|
|
1134
|
-
//# sourceMappingURL=snsSubscriptions-
|
|
1140
|
+
//# sourceMappingURL=snsSubscriptions-B7uEpoJ2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snsSubscriptions-B7uEpoJ2.cjs","names":["SERVER_IPV4_KEY","GkmError","SERVER_IPV6_KEY","isIPv6","isIPv4","routeHosts","normalizeDnsConfig","extractSubdomain","findRootDomain","cnameTarget","createDnsProvider","DnsRecordsUnreadable","dnsLookup","GkmError","awsProvisioningCredentials","awsClientConfig","awsEndpoint"],"sources":["../src/compose/dns.ts","../src/deploy/snsSubscriptions.ts"],"sourcesContent":["/**\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 {\n\ttype DnsProvider,\n\ttype DnsRecord,\n\tDnsRecordsUnreadable,\n} from '@geekmidas/edge/dns';\nimport type {\n\tCloudflareCredential,\n\tCredentialProvider,\n\tGoDaddyCredential,\n\tHostingerCredential,\n} from '../deploy/credentials';\nimport type { DnsResourceRecord } from '../deploy/dnsResources';\nimport {\n\textractSubdomain,\n\tfindRootDomain,\n\tnormalizeDnsConfig,\n} from '../dns/index';\nimport {\n\tcreateDnsProvider,\n\ttype GoDaddyOptions,\n\ttype DnsConfig as SchemaDnsConfig,\n} from '../dns/providers';\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 { routeHosts } from '@geekmidas/edge/routes';\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/**\n * Every public host the stack serves, once each, sorted — each route's\n * aliases and redirects included, which need a record and a certificate as\n * much as its own host does.\n */\nexport function stackHosts(stack: Pick<ComposeStack, 'routes'>): string[] {\n\treturn [...new Set(stack.routes.flatMap(routeHosts))].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?: GoDaddyOptions;\n\t/** The Hostinger token, when the caller already has it. */\n\thostinger?: HostingerCredential;\n\t/** The Cloudflare token, when the caller already has it. */\n\tcloudflare?: CloudflareCredential;\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' | 'cloudflare'\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\t...(options.cloudflare ? { cloudflare: options.cloudflare } : {}),\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'\n\t\t| 'log'\n\t\t| 'credentials'\n\t\t| 'hostinger'\n\t\t| 'cloudflare'\n\t\t| '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\tcloudflare: 'CLOUDFLARE_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\nfunction isTokenDnsProvider(provider: unknown): provider is TokenDnsProvider {\n\treturn (\n\t\ttypeof provider === 'string' && Object.hasOwn(DNS_TOKEN_KEYS, provider)\n\t);\n}\n\n/** The tokens a stage's records are written with. */\nexport interface DnsCredentials {\n\tgodaddy?: GoDaddyCredential;\n\thostinger?: HostingerCredential;\n\tcloudflare?: CloudflareCredential;\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 (!isTokenDnsProvider(provider)) 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<GoDaddyOptions, '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...(tokens.cloudflare ? { cloudflare: tokens.cloudflare } : {}),\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/**\n * The type a topic the stage's providers made has in its state — a watched\n * bucket's, an inbox's. Written by `ensureTopic`, with the topic's ARN as id.\n */\nexport const TOPIC_TYPE = 'sns-topic';\n\n/**\n * The ARNs of the topics the stage's providers made. The deploy manages\n * their subscriptions with its own credentials: the key in such a topic's\n * connection string is the running app's, and may only confirm.\n */\nexport function provisionedTopics(\n\tresources: Readonly<Record<string, ResourceRecord>> | undefined,\n): Set<string> {\n\treturn new Set(\n\t\tObject.values(resources ?? {})\n\t\t\t.filter((record) => record.type === TOPIC_TYPE && record.id)\n\t\t\t.map((record) => record.id!),\n\t);\n}\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 naming the topic — a topic subscribed to by its\n\t * connection string. Made with that string's keys when the stage set it\n\t * by hand; with the deploy's provisioning credentials when the stage's\n\t * providers made the topic (an inbox's). Absent for a bucket's, made with\n\t * 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/** A topic the stage made, with no deploy credentials to manage it with. */\nexport class ProvisionedTopicUnsigned extends GkmError {\n\tconstructor(readonly topicArn: string) {\n\t\tsuper(\n\t\t\t`${topicArn} is a topic this stage's deploy made, and its ` +\n\t\t\t\t`subscriptions are managed with the deploy's own AWS credentials — ` +\n\t\t\t\t`the key in its connection string is the app's, which may only ` +\n\t\t\t\t`confirm. Sign in with \\`gkm login\\`, or set AWS credentials in the ` +\n\t\t\t\t`environment, and deploy again.`,\n\t\t);\n\t\tthis.name = 'ProvisionedTopicUnsigned';\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. A topic the stage's\n * providers made (`provisioned`) is always signed with the deploy's: its\n * string carries the app's key, which may only confirm a subscription.\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 * @throws {ProvisionedTopicUnsigned} for a provisioned topic, with no\n * deploy credentials\n */\nexport async function topicConnection(input: {\n\tconnectionKey: string;\n\tconnectionString: string;\n\tstage: string;\n\tenv: NodeJS.ProcessEnv;\n\thome?: string;\n\t/** The stage's providers made the topic: sign with the deploy's keys. */\n\tprovisioned?: boolean;\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 && !input.provisioned) {\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) {\n\t\t\tthrow input.provisioned\n\t\t\t\t? new ProvisionedTopicUnsigned(topicArn)\n\t\t\t\t: new TopicSubscriptionUnsigned(input.connectionKey);\n\t\t}\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, and those to any topic the stage's providers\n * made, are reached with the deploy's provisioning credentials; a hand-set\n * topic's with the connection string they were made with, read from the\n * 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\tconst provisioned = provisionedTopics(input.resources);\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' && !provisioned.has(topicArn)) {\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,SAAgB,kBAAkB,OAAuB;CACxD,OAAO,mBAAmBA,kBAAAA,gBAAgB,kBAAkB;AAC7D;;AAGA,IAAa,uBAAb,cAA0CC,eAAAA,SAAS;CAExC;CACA;CACA;CAHV,YACC,OACA,KACA,OACC;EACD,MAAM,OAAO,QAAQD,kBAAAA;EACrB,MACC,GAAG,IAAI,WAAW,MAAM,uBAAuB,KAAK,UAAU,KAAK,EAAE,oBACjD,OAAO,qCAAqC,mCAAmC,qDAC9C,IAAI,kBAAkB,MAAM,EAClF;EATS,KAAA,QAAA;EACA,KAAA,MAAA;EACA,KAAA,QAAA;EAQT,KAAK,OAAO;CACb;AACD;;;;;AAMA,IAAa,uBAAb,cAA0CC,eAAAA,SAAS;CAExC;CACA;CAFV,YACC,OACA,QACC;EACD,MACC,QAAQ,MAAM,iBAAiB,OAAO,2BAClCD,kBAAAA,gBAAgB,+JAEwB,kBAAkB,KAAK,EAA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aAAa,IAAI,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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as GkmError } from "./errors-C9uIyIDt.mjs";
|
|
2
|
-
import { C as createDnsProvider, F as awsClientConfig, I as awsEndpoint, L as awsProvisioningCredentials, b as normalizeDnsConfig, v as extractSubdomain, y as findRootDomain } from "./stack-
|
|
3
|
-
import { Ft as SERVER_IPV4_KEY, It as SERVER_IPV6_KEY, Lt as cnameTarget } from "./workspace-
|
|
2
|
+
import { C as createDnsProvider, F as awsClientConfig, I as awsEndpoint, L as awsProvisioningCredentials, b as normalizeDnsConfig, v as extractSubdomain, y as findRootDomain } from "./stack-B5-pHmtX.mjs";
|
|
3
|
+
import { Ft as SERVER_IPV4_KEY, It as SERVER_IPV6_KEY, Lt as cnameTarget } from "./workspace-BSGUH2DO.mjs";
|
|
4
4
|
import { isIPv4, isIPv6 } from "node:net";
|
|
5
5
|
import { routeHosts } from "@geekmidas/edge/routes";
|
|
6
6
|
import { lookup } from "node:dns/promises";
|
|
@@ -259,7 +259,8 @@ function providerResolver(options) {
|
|
|
259
259
|
return options.providerFor ?? ((config) => createDnsProvider({
|
|
260
260
|
config,
|
|
261
261
|
...options.credentials ? { godaddy: options.credentials } : {},
|
|
262
|
-
...options.hostinger ? { hostinger: options.hostinger } : {}
|
|
262
|
+
...options.hostinger ? { hostinger: options.hostinger } : {},
|
|
263
|
+
...options.cloudflare ? { cloudflare: options.cloudflare } : {}
|
|
263
264
|
}));
|
|
264
265
|
}
|
|
265
266
|
/** Two values compared as DNS does: case, a trailing dot and spacing aside. */
|
|
@@ -643,8 +644,12 @@ function dnsFix(input, bad) {
|
|
|
643
644
|
/** The environment variable each token-authenticated provider reads. */
|
|
644
645
|
const DNS_TOKEN_KEYS = {
|
|
645
646
|
godaddy: "GODADDY_API_TOKEN",
|
|
646
|
-
hostinger: "HOSTINGER_API_TOKEN"
|
|
647
|
+
hostinger: "HOSTINGER_API_TOKEN",
|
|
648
|
+
cloudflare: "CLOUDFLARE_API_TOKEN"
|
|
647
649
|
};
|
|
650
|
+
function isTokenDnsProvider(provider) {
|
|
651
|
+
return typeof provider === "string" && Object.hasOwn(DNS_TOKEN_KEYS, provider);
|
|
652
|
+
}
|
|
648
653
|
/**
|
|
649
654
|
* A domain whose records the deploy writes, and no token to write them with.
|
|
650
655
|
* Raised before anything is built, started or written.
|
|
@@ -687,7 +692,7 @@ async function dnsCredentials(stage, domains, credentials) {
|
|
|
687
692
|
const found = {};
|
|
688
693
|
for (const { domain, config } of domains) {
|
|
689
694
|
const provider = config.provider;
|
|
690
|
-
if (provider
|
|
695
|
+
if (!isTokenDnsProvider(provider)) continue;
|
|
691
696
|
if (found[provider]) continue;
|
|
692
697
|
const token = await credentials.get({ kind: provider });
|
|
693
698
|
if (!token?.token) throw new DnsCredentialMissing(stage, domain, provider, DNS_TOKEN_KEYS[provider]);
|
|
@@ -738,6 +743,7 @@ async function stageDns(input) {
|
|
|
738
743
|
log
|
|
739
744
|
},
|
|
740
745
|
...tokens.hostinger ? { hostinger: tokens.hostinger } : {},
|
|
746
|
+
...tokens.cloudflare ? { cloudflare: tokens.cloudflare } : {},
|
|
741
747
|
...input.providerFor ? { providerFor: input.providerFor } : {}
|
|
742
748
|
};
|
|
743
749
|
const applied = !input.dns ? {
|
|
@@ -1006,4 +1012,4 @@ async function confirmPendingSubscriptions(input) {
|
|
|
1006
1012
|
//#endregion
|
|
1007
1013
|
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 };
|
|
1008
1014
|
|
|
1009
|
-
//# sourceMappingURL=snsSubscriptions-
|
|
1015
|
+
//# sourceMappingURL=snsSubscriptions-BQcD_3UK.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snsSubscriptions-BQcD_3UK.mjs","names":["dnsLookup"],"sources":["../src/compose/dns.ts","../src/deploy/snsSubscriptions.ts"],"sourcesContent":["/**\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 {\n\ttype DnsProvider,\n\ttype DnsRecord,\n\tDnsRecordsUnreadable,\n} from '@geekmidas/edge/dns';\nimport type {\n\tCloudflareCredential,\n\tCredentialProvider,\n\tGoDaddyCredential,\n\tHostingerCredential,\n} from '../deploy/credentials';\nimport type { DnsResourceRecord } from '../deploy/dnsResources';\nimport {\n\textractSubdomain,\n\tfindRootDomain,\n\tnormalizeDnsConfig,\n} from '../dns/index';\nimport {\n\tcreateDnsProvider,\n\ttype GoDaddyOptions,\n\ttype DnsConfig as SchemaDnsConfig,\n} from '../dns/providers';\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 { routeHosts } from '@geekmidas/edge/routes';\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/**\n * Every public host the stack serves, once each, sorted — each route's\n * aliases and redirects included, which need a record and a certificate as\n * much as its own host does.\n */\nexport function stackHosts(stack: Pick<ComposeStack, 'routes'>): string[] {\n\treturn [...new Set(stack.routes.flatMap(routeHosts))].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?: GoDaddyOptions;\n\t/** The Hostinger token, when the caller already has it. */\n\thostinger?: HostingerCredential;\n\t/** The Cloudflare token, when the caller already has it. */\n\tcloudflare?: CloudflareCredential;\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' | 'cloudflare'\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\t...(options.cloudflare ? { cloudflare: options.cloudflare } : {}),\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'\n\t\t| 'log'\n\t\t| 'credentials'\n\t\t| 'hostinger'\n\t\t| 'cloudflare'\n\t\t| '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\tcloudflare: 'CLOUDFLARE_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\nfunction isTokenDnsProvider(provider: unknown): provider is TokenDnsProvider {\n\treturn (\n\t\ttypeof provider === 'string' && Object.hasOwn(DNS_TOKEN_KEYS, provider)\n\t);\n}\n\n/** The tokens a stage's records are written with. */\nexport interface DnsCredentials {\n\tgodaddy?: GoDaddyCredential;\n\thostinger?: HostingerCredential;\n\tcloudflare?: CloudflareCredential;\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 (!isTokenDnsProvider(provider)) 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<GoDaddyOptions, '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...(tokens.cloudflare ? { cloudflare: tokens.cloudflare } : {}),\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/**\n * The type a topic the stage's providers made has in its state — a watched\n * bucket's, an inbox's. Written by `ensureTopic`, with the topic's ARN as id.\n */\nexport const TOPIC_TYPE = 'sns-topic';\n\n/**\n * The ARNs of the topics the stage's providers made. The deploy manages\n * their subscriptions with its own credentials: the key in such a topic's\n * connection string is the running app's, and may only confirm.\n */\nexport function provisionedTopics(\n\tresources: Readonly<Record<string, ResourceRecord>> | undefined,\n): Set<string> {\n\treturn new Set(\n\t\tObject.values(resources ?? {})\n\t\t\t.filter((record) => record.type === TOPIC_TYPE && record.id)\n\t\t\t.map((record) => record.id!),\n\t);\n}\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 naming the topic — a topic subscribed to by its\n\t * connection string. Made with that string's keys when the stage set it\n\t * by hand; with the deploy's provisioning credentials when the stage's\n\t * providers made the topic (an inbox's). Absent for a bucket's, made with\n\t * 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/** A topic the stage made, with no deploy credentials to manage it with. */\nexport class ProvisionedTopicUnsigned extends GkmError {\n\tconstructor(readonly topicArn: string) {\n\t\tsuper(\n\t\t\t`${topicArn} is a topic this stage's deploy made, and its ` +\n\t\t\t\t`subscriptions are managed with the deploy's own AWS credentials — ` +\n\t\t\t\t`the key in its connection string is the app's, which may only ` +\n\t\t\t\t`confirm. Sign in with \\`gkm login\\`, or set AWS credentials in the ` +\n\t\t\t\t`environment, and deploy again.`,\n\t\t);\n\t\tthis.name = 'ProvisionedTopicUnsigned';\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. A topic the stage's\n * providers made (`provisioned`) is always signed with the deploy's: its\n * string carries the app's key, which may only confirm a subscription.\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 * @throws {ProvisionedTopicUnsigned} for a provisioned topic, with no\n * deploy credentials\n */\nexport async function topicConnection(input: {\n\tconnectionKey: string;\n\tconnectionString: string;\n\tstage: string;\n\tenv: NodeJS.ProcessEnv;\n\thome?: string;\n\t/** The stage's providers made the topic: sign with the deploy's keys. */\n\tprovisioned?: boolean;\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 && !input.provisioned) {\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) {\n\t\t\tthrow input.provisioned\n\t\t\t\t? new ProvisionedTopicUnsigned(topicArn)\n\t\t\t\t: new TopicSubscriptionUnsigned(input.connectionKey);\n\t\t}\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, and those to any topic the stage's providers\n * made, are reached with the deploy's provisioning credentials; a hand-set\n * topic's with the connection string they were made with, read from the\n * 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\tconst provisioned = provisionedTopics(input.resources);\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' && !provisioned.has(topicArn)) {\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,SAAgB,kBAAkB,OAAuB;CACxD,OAAO,mBAAmB,gBAAgB,kBAAkB;AAC7D;;AAGA,IAAa,uBAAb,cAA0C,SAAS;CAExC;CACA;CACA;CAHV,YACC,OACA,KACA,OACC;EACD,MAAM,OAAO,QAAQ;EACrB,MACC,GAAG,IAAI,WAAW,MAAM,uBAAuB,KAAK,UAAU,KAAK,EAAE,oBACjD,OAAO,qCAAqC,mCAAmC,qDAC9C,IAAI,kBAAkB,MAAM,EAClF;EATS,KAAA,QAAA;EACA,KAAA,MAAA;EACA,KAAA,QAAA;EAQT,KAAK,OAAO;CACb;AACD;;;;;AAMA,IAAa,uBAAb,cAA0C,SAAS;CAExC;CACA;CAFV,YACC,OACA,QACC;EACD,MACC,QAAQ,MAAM,iBAAiB,OAAO,2B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;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"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
2
2
|
const require_errors = require("./errors-D1x8duqI.cjs");
|
|
3
|
-
const require_credentials = require("./credentials
|
|
4
|
-
const require_stack = require("./stack-
|
|
5
|
-
const require_workspace = require("./workspace-
|
|
3
|
+
const require_credentials = require("./credentials--QL1R8mL.cjs");
|
|
4
|
+
const require_stack = require("./stack-CBgOAZDP.cjs");
|
|
5
|
+
const require_workspace = require("./workspace-K403npiD.cjs");
|
|
6
6
|
const require_define = require("./define-zKgLY65H.cjs");
|
|
7
|
-
const require_credentials$1 = require("./credentials-
|
|
7
|
+
const require_credentials$1 = require("./credentials-No8csre7.cjs");
|
|
8
8
|
const require_discover = require("./discover-OXczlq08.cjs");
|
|
9
|
-
const require_local = require("./local-
|
|
9
|
+
const require_local = require("./local-BEM8UVsa.cjs");
|
|
10
10
|
const require_utils = require("./utils-DBqXbB8P.cjs");
|
|
11
11
|
let node_path = require("node:path");
|
|
12
12
|
let node_fs = require("node:fs");
|
|
@@ -511,4 +511,4 @@ Object.defineProperty(exports, "sst_exports", {
|
|
|
511
511
|
}
|
|
512
512
|
});
|
|
513
513
|
|
|
514
|
-
//# sourceMappingURL=sst-
|
|
514
|
+
//# sourceMappingURL=sst-D0t-8yEl.cjs.map
|