@geekmidas/cli 10.0.0-alpha.168 → 10.0.0-alpha.169
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/{GoDaddyProvider-CJIYlkUN.mjs → GoDaddyProvider-Cvmy2SPq.mjs} +2 -2
- package/dist/{GoDaddyProvider-CJIYlkUN.mjs.map → GoDaddyProvider-Cvmy2SPq.mjs.map} +1 -1
- package/dist/{GoDaddyProvider-CYAlIeML.cjs → GoDaddyProvider-KmdZlFSL.cjs} +2 -2
- package/dist/{GoDaddyProvider-CYAlIeML.cjs.map → GoDaddyProvider-KmdZlFSL.cjs.map} +1 -1
- package/dist/{HostingerProvider-Ceqc_nlG.cjs → HostingerProvider--IyQKlIC.cjs} +2 -2
- package/dist/{HostingerProvider-Ceqc_nlG.cjs.map → HostingerProvider--IyQKlIC.cjs.map} +1 -1
- package/dist/{HostingerProvider-Tb0bnTpM.mjs → HostingerProvider-DYf1XT_W.mjs} +2 -2
- package/dist/{HostingerProvider-Tb0bnTpM.mjs.map → HostingerProvider-DYf1XT_W.mjs.map} +1 -1
- package/dist/{LegacyStateStore-Ci-CRqt2.cjs → LegacyStateStore-8GVMHI12.cjs} +2 -2
- package/dist/{LegacyStateStore-Ci-CRqt2.cjs.map → LegacyStateStore-8GVMHI12.cjs.map} +1 -1
- package/dist/{LegacyStateStore-DJWY64Jj.mjs → LegacyStateStore-BOZj8nj1.mjs} +2 -2
- package/dist/{LegacyStateStore-DJWY64Jj.mjs.map → LegacyStateStore-BOZj8nj1.mjs.map} +1 -1
- package/dist/{LocalStateStore-Enw_wV7d.cjs → LocalStateStore-CfBABk6G.cjs} +2 -2
- package/dist/{LocalStateStore-Enw_wV7d.cjs.map → LocalStateStore-CfBABk6G.cjs.map} +1 -1
- package/dist/{LocalStateStore-BFgjv29N.mjs → LocalStateStore-D3wY7Qkb.mjs} +2 -2
- package/dist/{LocalStateStore-BFgjv29N.mjs.map → LocalStateStore-D3wY7Qkb.mjs.map} +1 -1
- package/dist/{S3StateStore-B48M3z7L.cjs → S3StateStore-C-Fs7CWD.cjs} +4 -4
- package/dist/{S3StateStore-B48M3z7L.cjs.map → S3StateStore-C-Fs7CWD.cjs.map} +1 -1
- package/dist/{S3StateStore-Cwfd-ZnJ.mjs → S3StateStore-CO92LBQI.mjs} +4 -4
- package/dist/{S3StateStore-Cwfd-ZnJ.mjs.map → S3StateStore-CO92LBQI.mjs.map} +1 -1
- package/dist/{SSMStateStore-DYgE98Sm.mjs → SSMStateStore-Ns7FpnmB.mjs} +2 -2
- package/dist/{SSMStateStore-DYgE98Sm.mjs.map → SSMStateStore-Ns7FpnmB.mjs.map} +1 -1
- package/dist/{SSMStateStore-CuBe-NK5.cjs → SSMStateStore-t6mkXQew.cjs} +2 -2
- package/dist/{SSMStateStore-CuBe-NK5.cjs.map → SSMStateStore-t6mkXQew.cjs.map} +1 -1
- package/dist/{add-C85tazt0.mjs → add-Byp8-rRf.mjs} +5 -5
- package/dist/{add-C85tazt0.mjs.map → add-Byp8-rRf.mjs.map} +1 -1
- package/dist/{add-4AT0LlDK.cjs → add-C3oUiBAc.cjs} +5 -5
- package/dist/{add-4AT0LlDK.cjs.map → add-C3oUiBAc.cjs.map} +1 -1
- package/dist/{apps-CWGmV2nQ.mjs → apps-C21-TXqR.mjs} +72 -16
- package/dist/apps-C21-TXqR.mjs.map +1 -0
- package/dist/{apps-By6pnfzA.cjs → apps-D_-DXV0H.cjs} +76 -14
- package/dist/apps-D_-DXV0H.cjs.map +1 -0
- package/dist/{bundler-DPBLrtjT.cjs → bundler-D43S2YTJ.cjs} +6 -6
- package/dist/{bundler-DPBLrtjT.cjs.map → bundler-D43S2YTJ.cjs.map} +1 -1
- package/dist/{bundler-B9rkNGpK.mjs → bundler-DjfpJ0mX.mjs} +6 -6
- package/dist/{bundler-B9rkNGpK.mjs.map → bundler-DjfpJ0mX.mjs.map} +1 -1
- package/dist/{cli-DgL0QED8.mjs → cli-00fMnBFk.mjs} +4 -4
- package/dist/{cli-DgL0QED8.mjs.map → cli-00fMnBFk.mjs.map} +1 -1
- package/dist/{cli-BnWRqhwx.cjs → cli-CYBb8rgx.cjs} +4 -4
- package/dist/{cli-BnWRqhwx.cjs.map → cli-CYBb8rgx.cjs.map} +1 -1
- package/dist/{compose-CLM-sqgE.cjs → compose-D9ksPt5H.cjs} +8 -8
- package/dist/{compose-CLM-sqgE.cjs.map → compose-D9ksPt5H.cjs.map} +1 -1
- package/dist/{compose-DwjaxFFK.cjs → compose-Dgd-yfJT.cjs} +5 -5
- package/dist/{compose-DwjaxFFK.cjs.map → compose-Dgd-yfJT.cjs.map} +1 -1
- package/dist/{compose-CcK-QoYU.mjs → compose-MwgjPj_A.mjs} +8 -8
- package/dist/{compose-CcK-QoYU.mjs.map → compose-MwgjPj_A.mjs.map} +1 -1
- package/dist/{compose-DuRBnjxx.mjs → compose-rn_DWcup.mjs} +5 -5
- package/dist/{compose-DuRBnjxx.mjs.map → compose-rn_DWcup.mjs.map} +1 -1
- package/dist/config.cjs +1 -1
- package/dist/config.mjs +1 -1
- package/dist/{credentials-CCCAy3NL.cjs → credentials-C6n_kdu4.cjs} +6 -6
- package/dist/{credentials-CCCAy3NL.cjs.map → credentials-C6n_kdu4.cjs.map} +1 -1
- package/dist/{credentials-CeCOEKP3.mjs → credentials-kK0X754I.mjs} +6 -6
- package/dist/{credentials-CeCOEKP3.mjs.map → credentials-kK0X754I.mjs.map} +1 -1
- package/dist/deploy/public.cjs +11 -11
- package/dist/deploy/public.d.cts.map +1 -1
- package/dist/deploy/public.d.mts.map +1 -1
- package/dist/deploy/public.mjs +11 -11
- package/dist/{deploy-Dy5jyciI.cjs → deploy-C1gf4bT-.cjs} +25 -23
- package/dist/deploy-C1gf4bT-.cjs.map +1 -0
- package/dist/{deploy-F6GA-u59.mjs → deploy-CFuDCbTq.mjs} +26 -24
- package/dist/deploy-CFuDCbTq.mjs.map +1 -0
- package/dist/{destroy-B7-8EgCJ.cjs → destroy-CMz0BPEe.cjs} +9 -9
- package/dist/{destroy-B7-8EgCJ.cjs.map → destroy-CMz0BPEe.cjs.map} +1 -1
- package/dist/{destroy-Gyxrl5yO.mjs → destroy-UTWZmaGn.mjs} +9 -9
- package/dist/{destroy-Gyxrl5yO.mjs.map → destroy-UTWZmaGn.mjs.map} +1 -1
- package/dist/{docker-COHyyOkv.mjs → docker-BIuidyEB.mjs} +5 -5
- package/dist/{docker-COHyyOkv.mjs.map → docker-BIuidyEB.mjs.map} +1 -1
- package/dist/{docker-CP4bspkW.cjs → docker-BrdCdNwm.cjs} +5 -5
- package/dist/{docker-CP4bspkW.cjs.map → docker-BrdCdNwm.cjs.map} +1 -1
- package/dist/{dokploy-DBmB9vWu.mjs → dokploy--ndQ72iu.mjs} +2 -2
- package/dist/{dokploy-DBmB9vWu.mjs.map → dokploy--ndQ72iu.mjs.map} +1 -1
- package/dist/{dokploy-C7ampvzk.cjs → dokploy-D7ZChrtZ.cjs} +2 -2
- package/dist/{dokploy-C7ampvzk.cjs.map → dokploy-D7ZChrtZ.cjs.map} +1 -1
- package/dist/{eas-EXRkhGSM.mjs → eas-BCcpBC4k.mjs} +3 -3
- package/dist/{eas-EXRkhGSM.mjs.map → eas-BCcpBC4k.mjs.map} +1 -1
- package/dist/{eas-CbnTdz8d.cjs → eas-DCvA907G.cjs} +3 -3
- package/dist/{eas-CbnTdz8d.cjs.map → eas-DCvA907G.cjs.map} +1 -1
- package/dist/{encryption-CdDDSAu_.cjs → encryption-8TklMCh2.cjs} +3 -3
- package/dist/{encryption-CdDDSAu_.cjs.map → encryption-8TklMCh2.cjs.map} +1 -1
- package/dist/{encryption-lLZV2eMs.mjs → encryption-C2LzfQp8.mjs} +3 -3
- package/dist/{encryption-lLZV2eMs.mjs.map → encryption-C2LzfQp8.mjs.map} +1 -1
- package/dist/{engine-Cg92m1Xf.cjs → engine-BMoNLayn.cjs} +9 -9
- package/dist/{engine-Cg92m1Xf.cjs.map → engine-BMoNLayn.cjs.map} +1 -1
- package/dist/{engine-ZzUy2czq.mjs → engine-D-_nkxQL.mjs} +9 -9
- package/dist/{engine-ZzUy2czq.mjs.map → engine-D-_nkxQL.mjs.map} +1 -1
- package/dist/{github-CPpJmNgV.mjs → github-B_zfStMR.mjs} +7 -7
- package/dist/{github-CPpJmNgV.mjs.map → github-B_zfStMR.mjs.map} +1 -1
- package/dist/{github-BHqRcUgU.cjs → github-CZjNDPAp.cjs} +7 -7
- package/dist/{github-BHqRcUgU.cjs.map → github-CZjNDPAp.cjs.map} +1 -1
- package/dist/{googlePlay-Dg-0ASWN.mjs → googlePlay-BcVRYMh4.mjs} +4 -4
- package/dist/{googlePlay-Dg-0ASWN.mjs.map → googlePlay-BcVRYMh4.mjs.map} +1 -1
- package/dist/{googlePlay-DRz0ya3q.cjs → googlePlay-Btn0lut5.cjs} +4 -4
- package/dist/{googlePlay-DRz0ya3q.cjs.map → googlePlay-Btn0lut5.cjs.map} +1 -1
- package/dist/{iam-b4IvC1fm.cjs → iam-BoYPPNdM.cjs} +2 -2
- package/dist/{iam-b4IvC1fm.cjs.map → iam-BoYPPNdM.cjs.map} +1 -1
- package/dist/{iam-CLIne3Ny.mjs → iam-ra1_Y405.mjs} +2 -2
- package/dist/{iam-CLIne3Ny.mjs.map → iam-ra1_Y405.mjs.map} +1 -1
- package/dist/index.cjs +63 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +63 -63
- package/dist/index.mjs.map +1 -1
- package/dist/{local-Cin6exc0.mjs → local-B9Vniy-F.mjs} +2 -2
- package/dist/{local-Cin6exc0.mjs.map → local-B9Vniy-F.mjs.map} +1 -1
- package/dist/{local-BIrl0ENw.cjs → local-DxfqOu7A.cjs} +2 -2
- package/dist/{local-BIrl0ENw.cjs.map → local-DxfqOu7A.cjs.map} +1 -1
- package/dist/{migrate-BtkwylxW.cjs → migrate-C1u7Tl7D.cjs} +5 -5
- package/dist/{migrate-BtkwylxW.cjs.map → migrate-C1u7Tl7D.cjs.map} +1 -1
- package/dist/{migrate-CxI07Ey0.cjs → migrate-CcYfCpMe.cjs} +3 -3
- package/dist/{migrate-CxI07Ey0.cjs.map → migrate-CcYfCpMe.cjs.map} +1 -1
- package/dist/{migrate-DEU8I8sQ.mjs → migrate-b5rcr4sw.mjs} +5 -5
- package/dist/{migrate-DEU8I8sQ.mjs.map → migrate-b5rcr4sw.mjs.map} +1 -1
- package/dist/{migrate-DpLMJLCw.mjs → migrate-blnmh2Tm.mjs} +3 -3
- package/dist/{migrate-DpLMJLCw.mjs.map → migrate-blnmh2Tm.mjs.map} +1 -1
- package/dist/{notes-or_kXTal.mjs → notes-CT1jNLDC.mjs} +6 -5
- package/dist/notes-CT1jNLDC.mjs.map +1 -0
- package/dist/{notes-rTfi6rfN.cjs → notes-Cw3JQ0Y_.cjs} +5 -4
- package/dist/notes-Cw3JQ0Y_.cjs.map +1 -0
- package/dist/openapi.cjs +1 -1
- package/dist/openapi.mjs +1 -1
- package/dist/{projectBucket-CRa1b1Td.cjs → projectBucket-8hJmCusk.cjs} +2 -2
- package/dist/{projectBucket-CRa1b1Td.cjs.map → projectBucket-8hJmCusk.cjs.map} +1 -1
- package/dist/{projectBucket-Coh5K3-g.mjs → projectBucket-DJNi2yJL.mjs} +2 -2
- package/dist/{projectBucket-Coh5K3-g.mjs.map → projectBucket-DJNi2yJL.mjs.map} +1 -1
- package/dist/{publish-Bwhywmpz.mjs → publish-CMaPsMsT.mjs} +2 -2
- package/dist/{publish-Bwhywmpz.mjs.map → publish-CMaPsMsT.mjs.map} +1 -1
- package/dist/{publish-D9Yl4AzW.cjs → publish-Dlb-rrc5.cjs} +2 -2
- package/dist/{publish-D9Yl4AzW.cjs.map → publish-Dlb-rrc5.cjs.map} +1 -1
- package/dist/{resolve-BrJUFIUu.cjs → resolve-BKn4TTn3.cjs} +4 -4
- package/dist/{resolve-BrJUFIUu.cjs.map → resolve-BKn4TTn3.cjs.map} +1 -1
- package/dist/{resolve-B9tboVm2.mjs → resolve-DrFS2Ivb.mjs} +4 -4
- package/dist/{resolve-B9tboVm2.mjs.map → resolve-DrFS2Ivb.mjs.map} +1 -1
- package/dist/{rollback-D48bPMpD.cjs → rollback-6ZeoByXd.cjs} +6 -6
- package/dist/{rollback-D48bPMpD.cjs.map → rollback-6ZeoByXd.cjs.map} +1 -1
- package/dist/{rollback-M6b0z1tp.mjs → rollback-B3lHgwkj.mjs} +6 -6
- package/dist/{rollback-M6b0z1tp.mjs.map → rollback-B3lHgwkj.mjs.map} +1 -1
- package/dist/{s3-3iS3jlKU.cjs → s3-Cq1_F2J8.cjs} +3 -3
- package/dist/{s3-3iS3jlKU.cjs.map → s3-Cq1_F2J8.cjs.map} +1 -1
- package/dist/{s3-CNOSRjqH.mjs → s3-DfAM0soB.mjs} +3 -3
- package/dist/{s3-CNOSRjqH.mjs.map → s3-DfAM0soB.mjs.map} +1 -1
- package/dist/{serverSetup-DnOdoucM.cjs → serverSetup-DMNKsLKq.cjs} +6 -6
- package/dist/{serverSetup-DnOdoucM.cjs.map → serverSetup-DMNKsLKq.cjs.map} +1 -1
- package/dist/{serverSetup-CzLJ_RV0.mjs → serverSetup-lZ7tYUZJ.mjs} +6 -6
- package/dist/{serverSetup-CzLJ_RV0.mjs.map → serverSetup-lZ7tYUZJ.mjs.map} +1 -1
- package/dist/{sniffer-C5F7uYQB.cjs → sniffer-CUImZsQL.cjs} +7 -7
- package/dist/{sniffer-C5F7uYQB.cjs.map → sniffer-CUImZsQL.cjs.map} +1 -1
- package/dist/{sniffer-yeftYpWK.mjs → sniffer-DcT9RrAj.mjs} +7 -7
- package/dist/{sniffer-yeftYpWK.mjs.map → sniffer-DcT9RrAj.mjs.map} +1 -1
- package/dist/{snsSubscriptions-CXwELBil.cjs → snsSubscriptions-1lX1ze3u.cjs} +10 -5
- package/dist/snsSubscriptions-1lX1ze3u.cjs.map +1 -0
- package/dist/{snsSubscriptions-CXRa_bwG.mjs → snsSubscriptions-DFWhEgiA.mjs} +10 -5
- package/dist/snsSubscriptions-DFWhEgiA.mjs.map +1 -0
- package/dist/{sst-BAQrBaGa.mjs → sst-CB6rX5Zs.mjs} +5 -5
- package/dist/{sst-BAQrBaGa.mjs.map → sst-CB6rX5Zs.mjs.map} +1 -1
- package/dist/{sst-B_srWo15.cjs → sst-ct0Vhta9.cjs} +5 -5
- package/dist/{sst-B_srWo15.cjs.map → sst-ct0Vhta9.cjs.map} +1 -1
- package/dist/{stack-DaJ9D2Uc.cjs → stack-CkdkfmpN.cjs} +111 -34
- package/dist/stack-CkdkfmpN.cjs.map +1 -0
- package/dist/{stack-t2tN1jYo.mjs → stack-Dsl0l3fi.mjs} +106 -35
- package/dist/stack-Dsl0l3fi.mjs.map +1 -0
- package/dist/{stage-Clk6oQO_.cjs → stage-Cmn0dCV2.cjs} +6 -6
- package/dist/{stage-Clk6oQO_.cjs.map → stage-Cmn0dCV2.cjs.map} +1 -1
- package/dist/{stage-B4gqRg7l.mjs → stage-DfdUf2sj.mjs} +6 -6
- package/dist/{stage-B4gqRg7l.mjs.map → stage-DfdUf2sj.mjs.map} +1 -1
- package/dist/{stages-afi9P-Cd.cjs → stages-BWg3NU3J.cjs} +2 -2
- package/dist/{stages-afi9P-Cd.cjs.map → stages-BWg3NU3J.cjs.map} +1 -1
- package/dist/{stages-D1rnfO18.mjs → stages-COiipV8N.mjs} +2 -2
- package/dist/{stages-D1rnfO18.mjs.map → stages-COiipV8N.mjs.map} +1 -1
- package/dist/target/public.cjs +1 -1
- package/dist/target/public.mjs +1 -1
- package/dist/{terminal-D4kY5oz7.mjs → terminal-BDKhPIBA.mjs} +2 -2
- package/dist/{terminal-D4kY5oz7.mjs.map → terminal-BDKhPIBA.mjs.map} +1 -1
- package/dist/{terminal-JAudEZRC.cjs → terminal-CFeiyJxJ.cjs} +2 -2
- package/dist/{terminal-JAudEZRC.cjs.map → terminal-CFeiyJxJ.cjs.map} +1 -1
- package/dist/workspace/index.cjs +1 -1
- package/dist/workspace/index.mjs +1 -1
- package/dist/{workspace-p7gmCQVS.cjs → workspace-CEpojAus.cjs} +41 -14
- package/dist/workspace-CEpojAus.cjs.map +1 -0
- package/dist/{workspace-Gubg8xLJ.mjs → workspace-_aoe8v6u.mjs} +42 -15
- package/dist/workspace-_aoe8v6u.mjs.map +1 -0
- package/package.json +15 -15
- package/dist/apps-By6pnfzA.cjs.map +0 -1
- package/dist/apps-CWGmV2nQ.mjs.map +0 -1
- package/dist/deploy-Dy5jyciI.cjs.map +0 -1
- package/dist/deploy-F6GA-u59.mjs.map +0 -1
- package/dist/notes-or_kXTal.mjs.map +0 -1
- package/dist/notes-rTfi6rfN.cjs.map +0 -1
- package/dist/snsSubscriptions-CXRa_bwG.mjs.map +0 -1
- package/dist/snsSubscriptions-CXwELBil.cjs.map +0 -1
- package/dist/stack-DaJ9D2Uc.cjs.map +0 -1
- package/dist/stack-t2tN1jYo.mjs.map +0 -1
- package/dist/workspace-Gubg8xLJ.mjs.map +0 -1
- package/dist/workspace-p7gmCQVS.cjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"notes-or_kXTal.mjs","names":[],"sources":["../src/deploy/devServices.ts","../src/providers/types.ts","../src/providers/notes.ts"],"sourcesContent":["/**\n * Mail and object storage on a deployed stage: real ones, or — only when\n * someone asked — the dev services the local stage runs.\n *\n * Locally a declared `Email` is Mailpit and a declared bucket is MinIO, and\n * nobody has to configure either. Deployed, the same two containers would be\n * a stage that silently delivers no mail and keeps its files on one\n * container's disk. So a deployed stage on a server target takes both from\n * its secrets — the mail server's URL and sending address, and each bucket's\n * URL — and a stage missing any of them fails before anything is built,\n * provisioned or written, naming every key at once.\n *\n * A bucket's credentials are not checked: they are optional, and come from\n * either of two places. The bucket's URL may carry a key of its own\n * (`s3://KEY:SECRET@uploads`), which wins; otherwise the S3 client's default\n * chain applies — the stage's shared `AWS_ACCESS_KEY_ID`/\n * `AWS_SECRET_ACCESS_KEY` when it set them, or a role.\n *\n * `--allow-dev-services` is the way out for a stage that is not production —\n * a preview, a demo: every construct the stage does not account for gets the\n * dev service the local stage runs for it — a bucket MinIO, mail Mailpit —\n * and the target derives the keys from it. What the stage does account for\n * still wins: a key set in its secrets, or a provider (`deploy.objects`)\n * that backs the kind. Every run that uses one says so, loudly.\n *\n * Pure: what each target runs is decided here from declarations and the\n * stage's values, and the targets do the running.\n */\n\nimport {\n\ttype ConstructManifest,\n\tprovidedKeyFor,\n\tpublicEnvFor,\n} from '@geekmidas/manifest';\nimport { SERVER_IPV4_KEY, SERVER_IPV6_KEY } from '../compose/dnsConfig.js';\nimport { GkmError } from '../errors';\nimport { appEnvKeys, workerEnvKeys } from '../reconcile/apps.js';\nimport { appKey } from '../workspace/derive.js';\nimport { fileServerLabel } from '../workspace/fileServerLabel.js';\n\n/**\n * The dev services a deployed stage can run — one per kind that has one on\n * every server target: a bucket's MinIO and mail's Mailpit. A cache or a\n * database is not here because a server stage runs its own anyway.\n */\nexport const DEV_SERVICES = ['minio', 'mailpit'] as const;\n\nexport type DevService = (typeof DEV_SERVICES)[number];\n\n/**\n * The S3 client's shared key pair. Optional: a bucket whose URL carries its own\n * key (`s3://KEY:SECRET@bucket`) signs with that, and one without signs with\n * this pair when the stage set it, or with whatever else the SDK's default\n * chain finds — a role.\n */\nexport const STORAGE_KEY_PAIR = [\n\t'AWS_ACCESS_KEY_ID',\n\t'AWS_SECRET_ACCESS_KEY',\n] as const;\n\n/** Dev services asked of a target that runs no containers. */\nexport class DevServicesNeedServerTarget extends GkmError {\n\tconstructor(readonly target: string) {\n\t\tsuper(\n\t\t\t`--allow-dev-services applies to server targets only, and '${target}' ` +\n\t\t\t\t`deploys to AWS, where a bucket is S3 and mail is the stage's own. ` +\n\t\t\t\t'Drop --allow-dev-services.',\n\t\t);\n\t\tthis.name = 'DevServicesNeedServerTarget';\n\t}\n}\n\n/**\n * `--allow-dev-services` given a value — the list it used to take. It is a\n * switch now: every construct the stage does not account for gets its dev\n * service.\n */\nexport class AllowDevServicesTakesNoValue extends GkmError {\n\tconstructor(readonly value: string) {\n\t\tsuper(\n\t\t\t`--allow-dev-services takes no value (it was given '${value}'). It runs ` +\n\t\t\t\t'the dev service for every bucket and mail the stage does not account ' +\n\t\t\t\t'for — no key in its secrets, no provider in deploy.<kind>.<stage> — so ' +\n\t\t\t\t'there is nothing to list. Pass --allow-dev-services on its own.',\n\t\t);\n\t\tthis.name = 'AllowDevServicesTakesNoValue';\n\t}\n}\n\n/**\n * Refuses `--allow-dev-services <value>` and `--allow-dev-services=<value>` on\n * a command line, with the reason, before the parser calls the value an\n * excess argument. `gkm deploy` and `gkm compose` take no positional\n * argument, so whatever follows the flag and is not a flag was meant for it.\n *\n * @throws {AllowDevServicesTakesNoValue}\n */\nexport function assertDevServicesFlag(argv: readonly string[]): void {\n\tfor (let i = 0; i < argv.length; i++) {\n\t\tconst arg = argv[i]!;\n\t\tif (arg.startsWith('--allow-dev-services=')) {\n\t\t\tthrow new AllowDevServicesTakesNoValue(arg.slice(arg.indexOf('=') + 1));\n\t\t}\n\t\tconst next = argv[i + 1];\n\t\tif (arg === '--allow-dev-services' && next && !next.startsWith('-')) {\n\t\t\tthrow new AllowDevServicesTakesNoValue(next);\n\t\t}\n\t}\n}\n\n/** One key a deployed stage needs and its secrets do not hold. */\nexport interface MissingServiceKey {\n\tkey: string;\n\t/** The construct that reads it. */\n\tid: string;\n\t/** What it is, for the line that names it. */\n\twhat: string;\n\t/** A line after `what`, for what else there is to know about it. */\n\tnote?: string;\n\t/** A placeholder value to show in the `gkm secrets:set` line. */\n\texample: string;\n\t/** The dev service that would stand in for it, unless the stage accounts for it. */\n\tservice?: DevService;\n\t/** The apps that read it, where known. */\n\tapps?: readonly string[];\n\t/** What creates it, where a provider backs it on the stage. */\n\thint?: string;\n}\n\n/**\n * A deployed stage with mail or object storage that its secrets do not\n * configure — every missing key, across every app, at once.\n */\nexport class ExternalServicesNotConfigured extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly missing: readonly MissingServiceKey[],\n\t) {\n\t\tconst standIns = missing.some((m) => m.service !== undefined);\n\t\tconst lines = missing.map((m) => {\n\t\t\tconst by = m.apps?.length ? `, read by ${m.apps.join(', ')}` : '';\n\t\t\treturn (\n\t\t\t\t` gkm secrets:set ${m.key} '${m.example}' --stage ${stage}\\n` +\n\t\t\t\t` ${m.what}${by}` +\n\t\t\t\t(m.note ? `\\n ${m.note}` : '') +\n\t\t\t\t(m.hint ? `\\n ${m.hint}` : '')\n\t\t\t);\n\t\t});\n\t\tsuper(\n\t\t\t`The stage '${stage}' is deployed, and a deployed stage's mail and ` +\n\t\t\t\t`object storage are real services: gkm runs no Mailpit or MinIO for ` +\n\t\t\t\t`it. Set ${missing.length === 1 ? 'this key' : `these ${missing.length} keys`} in the stage's secrets:\\n\\n` +\n\t\t\t\t`${lines.join('\\n')}\\n\\n` +\n\t\t\t\t(standIns\n\t\t\t\t\t? `For a stage that is not production — a preview, a demo — the ` +\n\t\t\t\t\t\t`dev services can run instead, with --allow-dev-services. ` +\n\t\t\t\t\t\t`Mailpit delivers no mail, and MinIO keeps every object on one ` +\n\t\t\t\t\t\t`container's disk.\\n\\n`\n\t\t\t\t\t: '') +\n\t\t\t\t`Or run: gkm secrets:add --stage ${stage}`,\n\t\t);\n\t\tthis.name = 'ExternalServicesNotConfigured';\n\t}\n}\n\n/** A declaration that is mail or object storage. */\nexport interface ServiceDeclaration {\n\tid: string;\n\tkind: 'email' | 'objects' | 'file-server';\n\t/** A file server's bucket. */\n\tof?: string;\n\t/** The apps that read it, where known. */\n\tapps?: readonly string[];\n}\n\n/** The kinds a deployed stage takes from its secrets, or a dev service. */\nconst SERVICE_KINDS: Readonly<Record<string, ServiceDeclaration['kind']>> = {\n\temail: 'email',\n\tobjects: 'objects',\n\t'file-server': 'file-server',\n};\n\nexport interface StageServiceDeclarationsInput {\n\tmanifest: ConstructManifest;\n}\n\n/**\n * Every mail and storage construct a manifest declares, each with the apps\n * and workers that read it — a process's environment, a site's build args. A\n * file server's reader reads its bucket too.\n *\n * The one list a deploy's readiness check refuses a stage by, every server\n * target decides its dev services from, and `gkm secrets:add` offers — so\n * none of them can disagree.\n */\nexport function stageServiceDeclarations(\n\tinput: StageServiceDeclarationsInput,\n): ServiceDeclaration[] {\n\tconst { manifest } = input;\n\n\t// The construct each key belongs to.\n\tconst owners = new Map<string, string>();\n\tfor (const [id, declaration] of Object.entries(manifest)) {\n\t\tif (!SERVICE_KINDS[declaration.kind]) continue;\n\t\towners.set(\n\t\t\tprovidedKeyFor(\n\t\t\t\tid,\n\t\t\t\tdeclaration.kind,\n\t\t\t\tdeclaration.kind === 'objects' ? 'connectionString' : 'url',\n\t\t\t),\n\t\t\tid,\n\t\t);\n\t\tif (declaration.kind === 'email')\n\t\t\towners.set(providedKeyFor(id, declaration.kind, 'from'), id);\n\t}\n\n\t// Who reads which construct.\n\tconst readers = new Map<string, Set<string>>();\n\tconst read = (process: string, keys: Iterable<string>) => {\n\t\tfor (const key of keys) {\n\t\t\tconst id = owners.get(key);\n\t\t\tif (!id) continue;\n\t\t\tconst declaration = manifest[id];\n\t\t\tconst of =\n\t\t\t\tdeclaration?.kind === 'file-server' ? declaration.of : undefined;\n\t\t\tfor (const owner of of ? [id, of] : [id]) {\n\t\t\t\tconst set = readers.get(owner) ?? new Set<string>();\n\t\t\t\tset.add(process);\n\t\t\t\treaders.set(owner, set);\n\t\t\t}\n\t\t}\n\t};\n\tfor (const [id, declaration] of Object.entries(manifest)) {\n\t\tconst name = appKey(id);\n\t\tif (\n\t\t\tdeclaration.kind === 'rest-api' ||\n\t\t\tdeclaration.kind === 'websocket-api' ||\n\t\t\tdeclaration.kind === 'site' ||\n\t\t\tdeclaration.kind === 'mobile-app'\n\t\t) {\n\t\t\tread(name, appEnvKeys(manifest, name) ?? []);\n\t\t}\n\t\t// A site's build args, by the keys they rename.\n\t\tif (declaration.kind === 'site') {\n\t\t\tread(name, Object.values(publicEnvFor(declaration, manifest)));\n\t\t}\n\t\tif (declaration.kind === 'worker') {\n\t\t\tread(name, workerEnvKeys(manifest, id) ?? []);\n\t\t}\n\t}\n\n\treturn Object.entries(manifest).flatMap(\n\t\t([id, declaration]): ServiceDeclaration[] => {\n\t\t\tconst kind = SERVICE_KINDS[declaration.kind];\n\t\t\tif (!kind) return [];\n\t\t\tconst apps = [...(readers.get(id) ?? [])].sort();\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid,\n\t\t\t\t\tkind,\n\t\t\t\t\t...(declaration.kind === 'file-server' && declaration.of\n\t\t\t\t\t\t? { of: declaration.of }\n\t\t\t\t\t\t: {}),\n\t\t\t\t\t...(apps.length ? { apps } : {}),\n\t\t\t\t},\n\t\t\t];\n\t\t},\n\t);\n}\n\nexport interface ExternalServicesInput {\n\tstage: string;\n\t/** Every mail and storage construct something on the stage reads. */\n\tdeclarations: readonly ServiceDeclaration[];\n\t/** The stage's values by key — what `gkm secrets:set` stored. */\n\tsupplied: Readonly<Record<string, string>>;\n\t/**\n\t * `--allow-dev-services`: every construct the stage does not account for\n\t * gets its dev service.\n\t */\n\tallow: boolean;\n\t/** The stage's base domain, for the examples. */\n\tdomain?: string;\n\t/**\n\t * What the stage's providers say, by kind: a kind one backs is accounted\n\t * for, so no dev service stands in for it, and a missing key of it names\n\t * what creates it.\n\t */\n\tproviders?: StageProviderNotes;\n}\n\n/** The stage's providers, as a deploy's checks read them. */\nexport interface StageProviderNotes {\n\tobjects?: StageProviderNote;\n\temail?: StageProviderNote;\n}\n\n/** What the stage's provider says of one kind. */\nexport interface StageProviderNote {\n\t/** A provider (or `false`) backs the kind: no dev service for it. */\n\taccounted: boolean;\n\t/** What creates a missing key of it. */\n\thint?: string;\n}\n\n/** Where a deployed stage's mail and storage come from. */\nexport interface ExternalServices {\n\t/** Keys the stage needs and has not set. Empty when it can deploy. */\n\tmissing: MissingServiceKey[];\n\t/** The buckets the target runs MinIO for. */\n\tminio: string[];\n\t/** The mail constructs the target runs Mailpit for. */\n\tmailpit: string[];\n}\n\n/** One dev service a run uses, and for which constructs. */\nexport interface DevServiceUse {\n\tservice: DevService;\n\tids: string[];\n}\n\n/** A third party's credentials a construct reads: an external API's, or a `Credential`. */\nexport interface CredentialDeclaration {\n\tid: string;\n\tkind: 'external-api' | 'credential';\n\t/** The apps that read it, where known. */\n\tapps?: readonly string[];\n}\n\n/** What a stage-supplied key belongs to. */\nexport type StageKeyKind =\n\t| 'bucket'\n\t| 'email'\n\t| 'file-server'\n\t| 'external-api'\n\t| 'credential'\n\t/** The server a compose stage's stack runs on: `GKM_SERVER_IPV4`. */\n\t| 'server';\n\n/**\n * One key only the stage's secrets can hold — nothing derives it — whether\n * or not it is set.\n */\nexport interface StageKey {\n\tkey: string;\n\t/** The construct that reads it. */\n\tid: string;\n\tkind: StageKeyKind;\n\t/** What it is, for the line that names it. */\n\twhat: string;\n\t/** A line after `what`, for what else there is to know about it. */\n\tnote?: string;\n\t/** A placeholder value to show in the `gkm secrets:set` line. */\n\texample: string;\n\t/** The dev service that would stand in for it, where one can. */\n\tservice?: DevService;\n\t/** What creates it, where a provider backs it on the stage. */\n\thint?: string;\n\t/** A file server's bucket. */\n\tof?: string;\n\t/** The apps that read it, where known. */\n\tapps?: readonly string[];\n}\n\nexport interface StageKeysInput {\n\t/** Whether the stage is the local one, which derives its mail and storage. */\n\tlocal: boolean;\n\t/** Every mail and storage construct something on the stage reads. */\n\tservices?: readonly ServiceDeclaration[];\n\t/** Every third party's credentials something on the stage reads. */\n\tcredentials?: readonly CredentialDeclaration[];\n\t/** The stage's base domain, for the examples. */\n\tdomain?: string;\n\t/** What the stage's providers say — see {@link StageProviderNotes}. */\n\tproviders?: StageProviderNotes;\n\t/**\n\t * The stage serves a domain from a server of its own — a compose stage —\n\t * so its secrets hold the server's address, `GKM_SERVER_IPV4`.\n\t */\n\tserver?: boolean;\n}\n\n/**\n * Every key a stage must be given rather than derive — the one list both a\n * deploy's checks and `gkm secrets:add` read, so what a deploy refuses and\n * what the builder offers cannot drift.\n *\n * - Deployed, mail is its URL and its sending address, a bucket its URL, and\n * a file server its public URL. Locally all of it is Mailpit and MinIO.\n * - On every stage, a third party's credentials: nobody but the third party\n * can issue them.\n *\n * Never a derived value: a database URL, a generated secret, the seed.\n */\nexport function requiredStageKeys(input: StageKeysInput): StageKey[] {\n\tconst domain = input.domain ?? 'example.com';\n\tconst keys: StageKey[] = [];\n\tconst add = (entry: StageKey) => {\n\t\tif (!keys.some((k) => k.key === entry.key)) keys.push(entry);\n\t};\n\tconst byId = <T extends { id: string }>(list: readonly T[] | undefined) =>\n\t\t[...(list ?? [])].sort((a, b) => a.id.localeCompare(b.id));\n\tconst apps = (d: { apps?: readonly string[] }) =>\n\t\td.apps?.length ? { apps: [...d.apps].sort() } : {};\n\n\tif (!input.local) {\n\t\tconst services = byId(input.services);\n\t\t// A kind a provider backs on the stage has no dev service, and a key of\n\t\t// it names what creates it.\n\t\tconst backing = (\n\t\t\tnote: StageProviderNote | undefined,\n\t\t\tservice: DevService,\n\t\t) =>\n\t\t\tnote?.accounted ? (note.hint ? { hint: note.hint } : {}) : { service };\n\t\tconst storage = backing(input.providers?.objects, 'minio');\n\t\tconst mail = backing(input.providers?.email, 'mailpit');\n\t\tfor (const d of services.filter((d) => d.kind === 'email')) {\n\t\t\tadd({\n\t\t\t\tkey: providedKeyFor(d.id, 'email', 'url'),\n\t\t\t\tid: d.id,\n\t\t\t\tkind: 'email',\n\t\t\t\twhat: `where '${d.id}' sends mail — any SMTP server`,\n\t\t\t\texample: `smtp://user:password@smtp.${domain}:587`,\n\t\t\t\t...mail,\n\t\t\t\t...apps(d),\n\t\t\t});\n\t\t\tadd({\n\t\t\t\tkey: providedKeyFor(d.id, 'email', 'from'),\n\t\t\t\tid: d.id,\n\t\t\t\tkind: 'email',\n\t\t\t\twhat: `the address '${d.id}' sends from, on a domain the mail server has verified`,\n\t\t\t\texample: `noreply@${domain}`,\n\t\t\t\t...mail,\n\t\t\t\t...apps(d),\n\t\t\t});\n\t\t}\n\t\tfor (const d of services.filter((d) => d.kind === 'objects')) {\n\t\t\tadd({\n\t\t\t\tkey: providedKeyFor(d.id, 'objects', 'connectionString'),\n\t\t\t\tid: d.id,\n\t\t\t\tkind: 'bucket',\n\t\t\t\twhat: `the bucket '${d.id}' — S3, R2, or any S3-compatible store (add &endpoint=… for one that is not S3)`,\n\t\t\t\tnote: `credentials are optional: a key for this bucket alone in the URL (s3://KEY:SECRET@${appKey(d.id)}?…) wins; without one, the shared AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY or a role signs`,\n\t\t\t\texample: `s3://${appKey(d.id)}?region=eu-west-1`,\n\t\t\t\t...storage,\n\t\t\t\t...apps(d),\n\t\t\t});\n\t\t}\n\t\tfor (const d of services.filter((d) => d.kind === 'file-server')) {\n\t\t\tadd({\n\t\t\t\tkey: providedKeyFor(d.id, 'file-server', 'url'),\n\t\t\t\tid: d.id,\n\t\t\t\tkind: 'file-server',\n\t\t\t\twhat: `the public address '${d.id}' serves its bucket on — a CDN or the bucket's own domain`,\n\t\t\t\texample: `https://${fileServerLabel(d.id)}.${domain}`,\n\t\t\t\t...storage,\n\t\t\t\t...(d.of ? { of: d.of } : {}),\n\t\t\t\t...apps(d),\n\t\t\t});\n\t\t}\n\t}\n\n\tif (!input.local && input.server) {\n\t\tadd({\n\t\t\tkey: SERVER_IPV4_KEY,\n\t\t\tid: 'server',\n\t\t\tkind: 'server',\n\t\t\twhat: \"the public IPv4 address of the server the stage's stack runs on — its hosts' DNS records point at it, and every deploy checks they do\",\n\t\t\tnote: `${SERVER_IPV6_KEY} adds its IPv6 address (AAAA records); neither is ever handed to an app`,\n\t\t\texample: '203.0.113.10',\n\t\t});\n\t}\n\n\tfor (const d of byId(input.credentials)) {\n\t\tadd({\n\t\t\tkey: providedKeyFor(d.id, d.kind, 'credentials'),\n\t\t\tid: d.id,\n\t\t\tkind: d.kind,\n\t\t\twhat:\n\t\t\t\td.kind === 'external-api'\n\t\t\t\t\t? `the credentials '${d.id}' was issued for this stage, as its schema describes them`\n\t\t\t\t\t: `the credential '${d.id}', as its schema describes it`,\n\t\t\texample: '{\"apiKey\":\"…\"}',\n\t\t\t...apps(d),\n\t\t});\n\t}\n\n\treturn keys;\n}\n\n/**\n * Whether only the stage's secrets can supply `key` to a construct of `kind`\n * — what nothing on the stage derives.\n *\n * A third party's credentials, always. Deployed, also each generated secret\n * and keyring: the stage generated each one once, and every run reads the\n * same value back.\n */\nexport function suppliedOnly(\n\tkind: string,\n\tid: string,\n\tkey: string,\n\tlocal: boolean,\n): boolean {\n\tif (kind === 'credential') return true;\n\tif (kind === 'external-api')\n\t\treturn key === providedKeyFor(id, 'external-api', 'credentials');\n\tif (local) return false;\n\treturn kind === 'secret' || kind === 'encryption';\n}\n\n/**\n * Where a deployed stage's mail and storage come from, and what it lacks.\n *\n * - Mail is external once its URL is set, and then needs its sending\n * address too. Unset, it is Mailpit where allowed — the address derived\n * unless set — and missing otherwise.\n * - A bucket is external once its URL is set; its credentials, in the URL or\n * the shared pair, are optional. Unset, it is MinIO where allowed, and\n * missing otherwise.\n * - A file server's URL is derived where its bucket is MinIO, unless set;\n * over an external bucket the stage must set it.\n *\n * The keys themselves are {@link requiredStageKeys}'s.\n */\nexport function externalServices(\n\tinput: ExternalServicesInput,\n): ExternalServices {\n\tconst { supplied, allow } = input;\n\tconst has = (key: string) => supplied[key] !== undefined;\n\n\tconst required = requiredStageKeys({\n\t\tlocal: false,\n\t\tservices: input.declarations,\n\t\t...(input.domain ? { domain: input.domain } : {}),\n\t\t...(input.providers ? { providers: input.providers } : {}),\n\t});\n\n\t// A dev service stands in for each construct the stage does not account\n\t// for: no key in its secrets, and no provider backing its kind.\n\tconst standIn = (k: StageKey) =>\n\t\tallow && k.service !== undefined && !has(k.key);\n\tconst mailpit = required\n\t\t.filter(\n\t\t\t(k) =>\n\t\t\t\tk.kind === 'email' && k.key === providedKeyFor(k.id, 'email', 'url'),\n\t\t)\n\t\t.filter(standIn)\n\t\t.map((k) => k.id);\n\tconst minio = required\n\t\t.filter((k) => k.kind === 'bucket')\n\t\t.filter(standIn)\n\t\t.map((k) => k.id);\n\n\tconst covered = (k: StageKey) =>\n\t\t(k.kind === 'email' && mailpit.includes(k.id)) ||\n\t\t(k.kind === 'bucket' && minio.includes(k.id)) ||\n\t\t(k.kind === 'file-server' && k.of !== undefined && minio.includes(k.of));\n\n\tconst missing = required\n\t\t.filter((k) => !has(k.key) && !covered(k))\n\t\t.map(\n\t\t\t({\n\t\t\t\tkey,\n\t\t\t\tid,\n\t\t\t\twhat,\n\t\t\t\tnote,\n\t\t\t\texample,\n\t\t\t\tservice,\n\t\t\t\tapps,\n\t\t\t\thint,\n\t\t\t}): MissingServiceKey => ({\n\t\t\t\tkey,\n\t\t\t\tid,\n\t\t\t\twhat,\n\t\t\t\t...(note ? { note } : {}),\n\t\t\t\texample,\n\t\t\t\t...(service ? { service } : {}),\n\t\t\t\t...(apps ? { apps } : {}),\n\t\t\t\t...(hint ? { hint } : {}),\n\t\t\t}),\n\t\t);\n\n\treturn { missing, minio, mailpit };\n}\n\n/** The dev services a run uses, one entry per service it runs. */\nexport function devServicesUsed(services: ExternalServices): DevServiceUse[] {\n\tconst used: DevServiceUse[] = [];\n\tif (services.mailpit.length > 0) {\n\t\tused.push({ service: 'mailpit', ids: services.mailpit });\n\t}\n\tif (services.minio.length > 0) {\n\t\tused.push({ service: 'minio', ids: services.minio });\n\t}\n\treturn used;\n}\n\n/** The line a run prints for each dev service a deployed stage uses. */\nexport function devServiceWarning(stage: string, use: DevServiceUse): string {\n\tconst what =\n\t\tuse.service === 'mailpit'\n\t\t\t? `Mailpit is catching mail for ${use.ids.join(', ')}. It delivers NO mail: nobody receives a sign-in link, a receipt or a reset`\n\t\t\t: `MinIO is storing ${use.ids.join(', ')}. Every object is on one container's disk, with no replication and no backup`;\n\treturn (\n\t\t`⚠️ DEV SERVICE ON A DEPLOYED STAGE (${stage}): ${what}. It is not ` +\n\t\t`production-grade — set the stage's own keys in its secrets for that.`\n\t);\n}\n\n/**\n * Report each dev service a run uses: a loud line, and a `dev-service.used`\n * event a host can act on.\n */\nexport function reportDevServices(\n\tctx: {\n\t\tstage: string;\n\t\tlogger: { warn(message: string): void };\n\t\temit(event: {\n\t\t\ttype: 'dev-service.used';\n\t\t\tservice: DevService;\n\t\t\tstage: string;\n\t\t\tconstructs: string[];\n\t\t}): void;\n\t},\n\tuses: readonly DevServiceUse[],\n): void {\n\tfor (const use of uses) {\n\t\tctx.logger.warn(`\\n${devServiceWarning(ctx.stage, use)}`);\n\t\tctx.emit({\n\t\t\ttype: 'dev-service.used',\n\t\t\tservice: use.service,\n\t\t\tstage: ctx.stage,\n\t\t\tconstructs: use.ids,\n\t\t});\n\t}\n}\n","/**\n * Providers: what creates the thing a construct is backed by, on a stage.\n *\n * The manifest says a bucket exists (`ObjectStorage`); `deploy.<kind>.<stage>`\n * says what backs it there. A stage that names a provider has gkm *create*\n * the backing resource — when it holds the account's provisioning\n * credentials — and write the connection value into the stage's secrets,\n * where every deploy reads it as if it had been set by hand. A stage that\n * names none is `external`: the value is yours to set, as it always was.\n *\n * | Part | What it is |\n * | ------------------------ | ------------------------------------------------------- |\n * | provisioning credentials | What creates the resource. Never given to an app. |\n * | `ensure()` | Idempotent find-or-create. Records in state. Never deletes. |\n * | runtime credentials | The keys it writes into the stage's secrets. |\n * | `verify()` | The cheap check every deploy runs. |\n *\n * The key under `deploy` is the manifest kind — `objects`, which\n * `ObjectStorage` and `FileServer` produce, `inbox`, `email` — so a kind\n * such as `deploy.cache` slots in beside them with providers of its own.\n */\n\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport type { DeployIdentity } from '../deploy/identity.js';\nimport type { ResourceRecord } from '../deploy/StateStore.js';\nimport type { BoundSubscriber } from '../reconcile/discover.js';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\n\n/** The manifest kinds a stage can name a provider for. */\nexport const PROVIDER_KINDS = ['objects', 'inbox', 'email'] as const;\n\nexport type ProviderKind = (typeof PROVIDER_KINDS)[number];\n\n/** A provider's own entry: `{ provider: 's3', … }`. */\nexport interface ProviderConfig {\n\tprovider: string;\n}\n\n/**\n * One stage's entry under `deploy.<kind>`:\n *\n * - `'external'` — the default: the stage's secrets hold the key, set by you.\n * - `{ provider, … }` — that provider creates the resource and writes the key.\n * - `false` — the stage has none of this kind; a construct of it is refused.\n */\nexport type StageProviderEntry<C extends ProviderConfig = ProviderConfig> =\n\t| 'external'\n\t| C\n\t| false;\n\n/** One change `ensure()` makes, or — in a dry run — would make. */\nexport interface ProvisionAction {\n\t/** The construct it is for. */\n\tconstruct: string;\n\t/** What it acts on: `bucket acme-shop-prod-uploads`. */\n\tresource: string;\n\t/** What it does: `create`, `set CORS (2 origins)`. */\n\tchange: string;\n}\n\n/** The stage's provisioning record, as `ensure()` reads and writes it. */\nexport interface ProvisionState {\n\t/** A resource recorded by an earlier run. */\n\trecord(key: string): ResourceRecord | undefined;\n\t/** About to be created — written before the call that creates it. */\n\tpending(entry: StateEntry): Promise<void>;\n\t/** Exists, as `id`. */\n\tready(entry: StateEntry, id: string): Promise<void>;\n\t/** When the stage was last deployed, for a rotation to know it was. */\n\treadonly lastDeployedAt?: string;\n}\n\nexport interface StateEntry {\n\t/** `<type>:<name>`, unique within the stage. */\n\tkey: string;\n\ttype: string;\n\tdata?: Record<string, unknown>;\n}\n\n/** What `ensure()` is handed. */\nexport interface EnsureContext<C extends ProviderConfig, K> {\n\tworkspace: NormalizedWorkspace;\n\tmanifest: ConstructManifest;\n\t/**\n\t * Each Worker's subscribers, from discovery — by export and the key its\n\t * deliveries come from. What a provider subscribes on a worker's behalf.\n\t */\n\tsubscribers?: Readonly<Record<string, readonly BoundSubscriber[]>>;\n\tstage: string;\n\tidentity: DeployIdentity;\n\tconfig: C;\n\t/** The provisioning credentials {@link ResourceProvider.credentials} found. */\n\tcredential: K;\n\t/** The stage's secrets as they are now, by key. */\n\tsecrets: Readonly<Record<string, string>>;\n\tstate: ProvisionState;\n\tdryRun: boolean;\n\t/** `--rotate-keys`: issue each runtime key a successor. */\n\trotateKeys: boolean;\n\t/** `--retire-old-keys`: delete a rotated-out key without waiting for a deploy. */\n\tretireOldKeys: boolean;\n\t/**\n\t * Runs `apply` and records `action` — or, in a dry run, only records it.\n\t * Every write to the provider's account goes through here.\n\t */\n\tchange(action: ProvisionAction, apply: () => Promise<void>): Promise<void>;\n\t/**\n\t * Writes keys into the stage's secrets now — not at the end of the run, so\n\t * a secret the account shows only once is kept the moment it exists. A dry\n\t * run writes nothing.\n\t */\n\twriteSecrets(values: Record<string, string>): Promise<void>;\n\t/**\n\t * Writes DNS records through the stage's DNS providers (`dns`), as the\n\t * deploy's own DNS step does — what a certificate's validation record and\n\t * a CDN's name, a domain's inbound mail (MX) need. A dry run prints them\n\t * and writes nothing.\n\t */\n\twriteDns(records: readonly ProviderDnsRecord[]): Promise<ProviderDnsResult>;\n\tlog(line: string): void;\n}\n\n/** One record a provider asks the stage's DNS for. */\nexport type ProviderDnsRecord =\n\t| {\n\t\t\t/** The full name: `_abc.files.example.com`. */\n\t\t\thost: string;\n\t\t\ttype: 'CNAME';\n\t\t\tvalue: string;\n\t }\n\t| {\n\t\t\t/** The full name: `example.com`, `*.example.com`. */\n\t\t\thost: string;\n\t\t\ttype: 'MX';\n\t\t\t/** The mail server: `inbound-smtp.eu-west-1.amazonaws.com`. */\n\t\t\tvalue: string;\n\t\t\t/** Lower is preferred: `10`. */\n\t\t\tpriority: number;\n\t };\n\n/** What writing a provider's records came to. */\nexport interface ProviderDnsResult {\n\t/**\n\t * Hosts no DNS provider wrote — under no domain in `dns`, or a `manual`\n\t * one — printed for the person to create.\n\t */\n\tmanual: string[];\n}\n\n/** What `verify()` is handed. */\nexport interface VerifyContext<C extends ProviderConfig> {\n\tworkspace: NormalizedWorkspace;\n\tmanifest: ConstructManifest;\n\tstage: string;\n\tconfig: C;\n\t/** The stage's secrets, by key. */\n\tsecrets: Readonly<Record<string, string>>;\n\t/**\n\t * What the stage's state records, by key — how a provider knows a key it\n\t * checks was issued moments ago. Absent when nothing was read.\n\t */\n\tresources?: Readonly<Record<string, ResourceRecord>>;\n\t/** Progress worth printing: waiting on something. */\n\tlog?: (line: string) => void;\n}\n\n/** Where a provider's provisioning credentials are looked for. */\nexport interface CredentialLookup {\n\tstage: string;\n\t/** `--profile`, when given. */\n\tprofile?: string;\n\tenv: NodeJS.ProcessEnv;\n\t/** The CLI's home, for stored logins. */\n\thome?: string;\n}\n\n/**\n * A provider. `C` is its config entry, `K` its provisioning credential.\n *\n * Built-ins are registered in `providers/registry.ts`, the way a deploy\n * target's built-ins are.\n */\nexport interface ResourceProvider<\n\tC extends ProviderConfig = ProviderConfig,\n\tK = unknown,\n> {\n\treadonly kind: ProviderKind;\n\t/** What `provider:` names it. */\n\treadonly name: string;\n\t/**\n\t * Its config entry checked: returns it, or throws a named error saying\n\t * what is wrong — what the workspace schema runs.\n\t */\n\tcheck(stage: string, config: ProviderConfig): C;\n\t/** How its provisioning credentials are supplied, for messages. */\n\treadonly provisioning: {\n\t\t/** The environment variables it reads. */\n\t\tenv: readonly string[];\n\t\t/** A `gkm login --provider` name, where it has one. */\n\t\tlogin?: string;\n\t\t/** One line saying how to supply them. */\n\t\tdescribe: string;\n\t};\n\t/** Its provisioning credentials, or `undefined` when there are none. */\n\tcredentials(lookup: CredentialLookup): Promise<K | undefined>;\n\t/** The keys it writes into the stage's secrets for these constructs. */\n\truntimeKeys(manifest: ConstructManifest): string[];\n\tensure(ctx: EnsureContext<C, K>): Promise<void>;\n\tverify(ctx: VerifyContext<C>): Promise<void>;\n}\n","/**\n * What a deploy's checks read off `deploy.<kind>.<stage>`, without loading a\n * provider: which kinds the stage accounts for, what creates a missing key,\n * and a kind the stage has none of.\n */\n\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport type { StageProviderNotes } from '../deploy/devServices.js';\nimport { GkmError } from '../errors';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\nimport { provisioningOf, stageProvider } from './config.js';\nimport { PROVIDER_KINDS, type ProviderKind } from './types.js';\n\n/** The constructs of a kind: `objects` is every bucket. */\nexport function constructsOf(manifest: ConstructManifest, kind: ProviderKind) {\n\treturn Object.entries(manifest)\n\t\t.filter(([, d]) => d.kind === kind)\n\t\t.map(([id]) => id)\n\t\t.sort();\n}\n\n/** A stage that names `false` for a kind, and declares constructs of it. */\nexport class StageProviderDisabled extends GkmError {\n\tconstructor(\n\t\treadonly kind: ProviderKind,\n\t\treadonly stage: string,\n\t\treadonly ids: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`deploy.${kind}.${stage} is false — the stage has no ${kind} — and ` +\n\t\t\t\t`${ids.join(', ')} ${ids.length === 1 ? 'is' : 'are'} declared. ` +\n\t\t\t\t`Name what backs ${ids.length === 1 ? 'it' : 'them'} on '${stage}' ` +\n\t\t\t\t`(deploy.${kind}.${stage}: 'external', or a provider), or remove ` +\n\t\t\t\t`the ${ids.length === 1 ? 'construct' : 'constructs'}.`,\n\t\t);\n\t\tthis.name = 'StageProviderDisabled';\n\t}\n}\n\n/** The command a stage's providers are run with: every deploy runs them. */\nexport function provisionCommand(stage: string): string {\n\treturn `gkm deploy --stage ${stage}`;\n}\n\n/**\n * The line a stage missing a key a provider would write is given: what\n * creates it, and with which credentials. Undefined when no provider backs\n * the kind on the stage.\n */\nexport function provisionHint(\n\tworkspace: Pick<NormalizedWorkspace, 'deploy' | 'stages'>,\n\tkind: ProviderKind,\n\tstage: string,\n): string | undefined {\n\tconst choice = stageProvider(workspace as never, kind, stage);\n\tif (choice.mode !== 'provider') return undefined;\n\tconst provisioning = provisioningOf(kind, choice.name);\n\tif (!provisioning) return undefined;\n\treturn (\n\t\t`deploy.${kind}.${stage} is ${choice.name}: the deploy ` +\n\t\t`(${provisionCommand(stage)}) creates it and writes this key, with ` +\n\t\t`${provisioning.describe}` +\n\t\t(provisioning.login\n\t\t\t? `, or gkm login --provider ${provisioning.login}`\n\t\t\t: '')\n\t);\n}\n\n/**\n * What a deploy's checks read off the stage's providers: whether each kind is\n * accounted for — a provider, or `false` — so no dev service stands in for\n * it, and what creates a missing key of it.\n */\nexport function stageProviderNotes(\n\tworkspace: Pick<NormalizedWorkspace, 'deploy' | 'stages'>,\n\tstage: string,\n): StageProviderNotes {\n\tconst notes: StageProviderNotes = {};\n\tfor (const kind of ['objects', 'email'] as const) {\n\t\tif (stageProvider(workspace as never, kind, stage).mode === 'external') {\n\t\t\tcontinue;\n\t\t}\n\t\tconst hint = provisionHint(workspace, kind, stage);\n\t\tnotes[kind] = { accounted: true, ...(hint ? { hint } : {}) };\n\t}\n\treturn notes;\n}\n\n/**\n * A kind the stage set to `false`, declared anyway — refused before anything\n * else is checked. Pure: what a stack is composed from.\n *\n * @throws {StageProviderDisabled}\n */\nexport function assertStageProvidersEnabled(\n\tworkspace: Pick<NormalizedWorkspace, 'deploy' | 'stages'>,\n\tmanifest: ConstructManifest,\n\tstage: string,\n): void {\n\tfor (const kind of PROVIDER_KINDS) {\n\t\tconst ids = constructsOf(manifest, kind);\n\t\tif (ids.length === 0) continue;\n\t\tif (stageProvider(workspace as never, kind, stage).mode === 'none') {\n\t\t\tthrow new StageProviderDisabled(kind, stage, ids);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAa,eAAe,CAAC,SAAS,SAAS;;;;;;;AAU/C,MAAa,mBAAmB,CAC/B,qBACA,uBACD;;AAGA,IAAa,8BAAb,cAAiD,SAAS;CACpC;CAArB,YAAY,QAAyB;EACpC,MACC,6DAA6D,OAAO,+FAGrE;EALoB,KAAA,SAAA;EAMpB,KAAK,OAAO;CACb;AACD;;;;;;AAOA,IAAa,+BAAb,cAAkD,SAAS;CACrC;CAArB,YAAY,OAAwB;EACnC,MACC,sDAAsD,MAAM,wNAI7D;EANoB,KAAA,QAAA;EAOpB,KAAK,OAAO;CACb;AACD;;;;;;;;;AAUA,SAAgB,sBAAsB,MAA+B;CACpE,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACrC,MAAM,MAAM,KAAK;EACjB,IAA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WAAW,IAAI,cAAc,aAAa,EACvD;EAVS,KAAA,OAAA;EACA,KAAA,QAAA;EACA,KAAA,MAAA;EAST,KAAK,OAAO;CACb;AACD;;AAGA,SAAgB,iBAAiB,OAAuB;CACvD,OAAO,sBAAsB;AAC9B;;;;;;AAOA,SAAgB,cACf,WACA,MACA,OACqB;CACrB,MAAM,SAAS,cAAc,WAAoB,MAAM,KAAK;CAC5D,IAAI,OAAO,SAAS,YAAY,OAAO,KAAA;CACvC,MAAM,eAAe,eAAe,MAAM,OAAO,IAAI;CACrD,IAAI,CAAC,cAAc,OAAO,KAAA;CAC1B,OACC,UAAU,KAAK,GAAG,MAAM,MAAM,OAAO,KAAK,gBACtC,iBAAiB,KAAK,EAAE,yCACzB,aAAa,cACf,aAAa,QACX,6BAA6B,aAAa,UAC1C;AAEL;;;;;;AAOA,SAAgB,mBACf,WACA,OACqB;CACrB,MAAM,QAA4B,CAAC;CACnC,KAAK,MAAM,QAAQ,CAAC,WAAW,OAAO,GAAY;EACjD,IAAI,cAAc,WAAoB,MAAM,KAAK,CAAC,CAAC,SAAS,YAC3D;EAED,MAAM,OAAO,cAAc,WAAW,MAAM,KAAK;EACjD,MAAM,QAAQ;GAAE,WAAW;GAAM,GAAI,OAAO,EAAE,KAAK,IAAI,CAAC;EAAG;CAC5D;CACA,OAAO;AACR;;;;;;;AAQA,SAAgB,4BACf,WACA,UACA,OACO;CACP,KAAK,MAAM,QAAQ,gBAAgB;EAClC,MAAM,MAAM,aAAa,UAAU,IAAI;EACvC,IAAI,IAAI,WAAW,GAAG;EACtB,IAAI,cAAc,WAAoB,MAAM,KAAK,CAAC,CAAC,SAAS,QAC3D,MAAM,IAAI,sBAAsB,MAAM,OAAO,GAAG;CAElD;AACD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"notes-rTfi6rfN.cjs","names":["GkmError","providedKeyFor","appKey","appEnvKeys","publicEnvFor","workerEnvKeys","fileServerLabel","SERVER_IPV4_KEY","SERVER_IPV6_KEY","GkmError","stageProvider","provisioningOf"],"sources":["../src/deploy/devServices.ts","../src/providers/types.ts","../src/providers/notes.ts"],"sourcesContent":["/**\n * Mail and object storage on a deployed stage: real ones, or — only when\n * someone asked — the dev services the local stage runs.\n *\n * Locally a declared `Email` is Mailpit and a declared bucket is MinIO, and\n * nobody has to configure either. Deployed, the same two containers would be\n * a stage that silently delivers no mail and keeps its files on one\n * container's disk. So a deployed stage on a server target takes both from\n * its secrets — the mail server's URL and sending address, and each bucket's\n * URL — and a stage missing any of them fails before anything is built,\n * provisioned or written, naming every key at once.\n *\n * A bucket's credentials are not checked: they are optional, and come from\n * either of two places. The bucket's URL may carry a key of its own\n * (`s3://KEY:SECRET@uploads`), which wins; otherwise the S3 client's default\n * chain applies — the stage's shared `AWS_ACCESS_KEY_ID`/\n * `AWS_SECRET_ACCESS_KEY` when it set them, or a role.\n *\n * `--allow-dev-services` is the way out for a stage that is not production —\n * a preview, a demo: every construct the stage does not account for gets the\n * dev service the local stage runs for it — a bucket MinIO, mail Mailpit —\n * and the target derives the keys from it. What the stage does account for\n * still wins: a key set in its secrets, or a provider (`deploy.objects`)\n * that backs the kind. Every run that uses one says so, loudly.\n *\n * Pure: what each target runs is decided here from declarations and the\n * stage's values, and the targets do the running.\n */\n\nimport {\n\ttype ConstructManifest,\n\tprovidedKeyFor,\n\tpublicEnvFor,\n} from '@geekmidas/manifest';\nimport { SERVER_IPV4_KEY, SERVER_IPV6_KEY } from '../compose/dnsConfig.js';\nimport { GkmError } from '../errors';\nimport { appEnvKeys, workerEnvKeys } from '../reconcile/apps.js';\nimport { appKey } from '../workspace/derive.js';\nimport { fileServerLabel } from '../workspace/fileServerLabel.js';\n\n/**\n * The dev services a deployed stage can run — one per kind that has one on\n * every server target: a bucket's MinIO and mail's Mailpit. A cache or a\n * database is not here because a server stage runs its own anyway.\n */\nexport const DEV_SERVICES = ['minio', 'mailpit'] as const;\n\nexport type DevService = (typeof DEV_SERVICES)[number];\n\n/**\n * The S3 client's shared key pair. Optional: a bucket whose URL carries its own\n * key (`s3://KEY:SECRET@bucket`) signs with that, and one without signs with\n * this pair when the stage set it, or with whatever else the SDK's default\n * chain finds — a role.\n */\nexport const STORAGE_KEY_PAIR = [\n\t'AWS_ACCESS_KEY_ID',\n\t'AWS_SECRET_ACCESS_KEY',\n] as const;\n\n/** Dev services asked of a target that runs no containers. */\nexport class DevServicesNeedServerTarget extends GkmError {\n\tconstructor(readonly target: string) {\n\t\tsuper(\n\t\t\t`--allow-dev-services applies to server targets only, and '${target}' ` +\n\t\t\t\t`deploys to AWS, where a bucket is S3 and mail is the stage's own. ` +\n\t\t\t\t'Drop --allow-dev-services.',\n\t\t);\n\t\tthis.name = 'DevServicesNeedServerTarget';\n\t}\n}\n\n/**\n * `--allow-dev-services` given a value — the list it used to take. It is a\n * switch now: every construct the stage does not account for gets its dev\n * service.\n */\nexport class AllowDevServicesTakesNoValue extends GkmError {\n\tconstructor(readonly value: string) {\n\t\tsuper(\n\t\t\t`--allow-dev-services takes no value (it was given '${value}'). It runs ` +\n\t\t\t\t'the dev service for every bucket and mail the stage does not account ' +\n\t\t\t\t'for — no key in its secrets, no provider in deploy.<kind>.<stage> — so ' +\n\t\t\t\t'there is nothing to list. Pass --allow-dev-services on its own.',\n\t\t);\n\t\tthis.name = 'AllowDevServicesTakesNoValue';\n\t}\n}\n\n/**\n * Refuses `--allow-dev-services <value>` and `--allow-dev-services=<value>` on\n * a command line, with the reason, before the parser calls the value an\n * excess argument. `gkm deploy` and `gkm compose` take no positional\n * argument, so whatever follows the flag and is not a flag was meant for it.\n *\n * @throws {AllowDevServicesTakesNoValue}\n */\nexport function assertDevServicesFlag(argv: readonly string[]): void {\n\tfor (let i = 0; i < argv.length; i++) {\n\t\tconst arg = argv[i]!;\n\t\tif (arg.startsWith('--allow-dev-services=')) {\n\t\t\tthrow new AllowDevServicesTakesNoValue(arg.slice(arg.indexOf('=') + 1));\n\t\t}\n\t\tconst next = argv[i + 1];\n\t\tif (arg === '--allow-dev-services' && next && !next.startsWith('-')) {\n\t\t\tthrow new AllowDevServicesTakesNoValue(next);\n\t\t}\n\t}\n}\n\n/** One key a deployed stage needs and its secrets do not hold. */\nexport interface MissingServiceKey {\n\tkey: string;\n\t/** The construct that reads it. */\n\tid: string;\n\t/** What it is, for the line that names it. */\n\twhat: string;\n\t/** A line after `what`, for what else there is to know about it. */\n\tnote?: string;\n\t/** A placeholder value to show in the `gkm secrets:set` line. */\n\texample: string;\n\t/** The dev service that would stand in for it, unless the stage accounts for it. */\n\tservice?: DevService;\n\t/** The apps that read it, where known. */\n\tapps?: readonly string[];\n\t/** What creates it, where a provider backs it on the stage. */\n\thint?: string;\n}\n\n/**\n * A deployed stage with mail or object storage that its secrets do not\n * configure — every missing key, across every app, at once.\n */\nexport class ExternalServicesNotConfigured extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly missing: readonly MissingServiceKey[],\n\t) {\n\t\tconst standIns = missing.some((m) => m.service !== undefined);\n\t\tconst lines = missing.map((m) => {\n\t\t\tconst by = m.apps?.length ? `, read by ${m.apps.join(', ')}` : '';\n\t\t\treturn (\n\t\t\t\t` gkm secrets:set ${m.key} '${m.example}' --stage ${stage}\\n` +\n\t\t\t\t` ${m.what}${by}` +\n\t\t\t\t(m.note ? `\\n ${m.note}` : '') +\n\t\t\t\t(m.hint ? `\\n ${m.hint}` : '')\n\t\t\t);\n\t\t});\n\t\tsuper(\n\t\t\t`The stage '${stage}' is deployed, and a deployed stage's mail and ` +\n\t\t\t\t`object storage are real services: gkm runs no Mailpit or MinIO for ` +\n\t\t\t\t`it. Set ${missing.length === 1 ? 'this key' : `these ${missing.length} keys`} in the stage's secrets:\\n\\n` +\n\t\t\t\t`${lines.join('\\n')}\\n\\n` +\n\t\t\t\t(standIns\n\t\t\t\t\t? `For a stage that is not production — a preview, a demo — the ` +\n\t\t\t\t\t\t`dev services can run instead, with --allow-dev-services. ` +\n\t\t\t\t\t\t`Mailpit delivers no mail, and MinIO keeps every object on one ` +\n\t\t\t\t\t\t`container's disk.\\n\\n`\n\t\t\t\t\t: '') +\n\t\t\t\t`Or run: gkm secrets:add --stage ${stage}`,\n\t\t);\n\t\tthis.name = 'ExternalServicesNotConfigured';\n\t}\n}\n\n/** A declaration that is mail or object storage. */\nexport interface ServiceDeclaration {\n\tid: string;\n\tkind: 'email' | 'objects' | 'file-server';\n\t/** A file server's bucket. */\n\tof?: string;\n\t/** The apps that read it, where known. */\n\tapps?: readonly string[];\n}\n\n/** The kinds a deployed stage takes from its secrets, or a dev service. */\nconst SERVICE_KINDS: Readonly<Record<string, ServiceDeclaration['kind']>> = {\n\temail: 'email',\n\tobjects: 'objects',\n\t'file-server': 'file-server',\n};\n\nexport interface StageServiceDeclarationsInput {\n\tmanifest: ConstructManifest;\n}\n\n/**\n * Every mail and storage construct a manifest declares, each with the apps\n * and workers that read it — a process's environment, a site's build args. A\n * file server's reader reads its bucket too.\n *\n * The one list a deploy's readiness check refuses a stage by, every server\n * target decides its dev services from, and `gkm secrets:add` offers — so\n * none of them can disagree.\n */\nexport function stageServiceDeclarations(\n\tinput: StageServiceDeclarationsInput,\n): ServiceDeclaration[] {\n\tconst { manifest } = input;\n\n\t// The construct each key belongs to.\n\tconst owners = new Map<string, string>();\n\tfor (const [id, declaration] of Object.entries(manifest)) {\n\t\tif (!SERVICE_KINDS[declaration.kind]) continue;\n\t\towners.set(\n\t\t\tprovidedKeyFor(\n\t\t\t\tid,\n\t\t\t\tdeclaration.kind,\n\t\t\t\tdeclaration.kind === 'objects' ? 'connectionString' : 'url',\n\t\t\t),\n\t\t\tid,\n\t\t);\n\t\tif (declaration.kind === 'email')\n\t\t\towners.set(providedKeyFor(id, declaration.kind, 'from'), id);\n\t}\n\n\t// Who reads which construct.\n\tconst readers = new Map<string, Set<string>>();\n\tconst read = (process: string, keys: Iterable<string>) => {\n\t\tfor (const key of keys) {\n\t\t\tconst id = owners.get(key);\n\t\t\tif (!id) continue;\n\t\t\tconst declaration = manifest[id];\n\t\t\tconst of =\n\t\t\t\tdeclaration?.kind === 'file-server' ? declaration.of : undefined;\n\t\t\tfor (const owner of of ? [id, of] : [id]) {\n\t\t\t\tconst set = readers.get(owner) ?? new Set<string>();\n\t\t\t\tset.add(process);\n\t\t\t\treaders.set(owner, set);\n\t\t\t}\n\t\t}\n\t};\n\tfor (const [id, declaration] of Object.entries(manifest)) {\n\t\tconst name = appKey(id);\n\t\tif (\n\t\t\tdeclaration.kind === 'rest-api' ||\n\t\t\tdeclaration.kind === 'websocket-api' ||\n\t\t\tdeclaration.kind === 'site' ||\n\t\t\tdeclaration.kind === 'mobile-app'\n\t\t) {\n\t\t\tread(name, appEnvKeys(manifest, name) ?? []);\n\t\t}\n\t\t// A site's build args, by the keys they rename.\n\t\tif (declaration.kind === 'site') {\n\t\t\tread(name, Object.values(publicEnvFor(declaration, manifest)));\n\t\t}\n\t\tif (declaration.kind === 'worker') {\n\t\t\tread(name, workerEnvKeys(manifest, id) ?? []);\n\t\t}\n\t}\n\n\treturn Object.entries(manifest).flatMap(\n\t\t([id, declaration]): ServiceDeclaration[] => {\n\t\t\tconst kind = SERVICE_KINDS[declaration.kind];\n\t\t\tif (!kind) return [];\n\t\t\tconst apps = [...(readers.get(id) ?? [])].sort();\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid,\n\t\t\t\t\tkind,\n\t\t\t\t\t...(declaration.kind === 'file-server' && declaration.of\n\t\t\t\t\t\t? { of: declaration.of }\n\t\t\t\t\t\t: {}),\n\t\t\t\t\t...(apps.length ? { apps } : {}),\n\t\t\t\t},\n\t\t\t];\n\t\t},\n\t);\n}\n\nexport interface ExternalServicesInput {\n\tstage: string;\n\t/** Every mail and storage construct something on the stage reads. */\n\tdeclarations: readonly ServiceDeclaration[];\n\t/** The stage's values by key — what `gkm secrets:set` stored. */\n\tsupplied: Readonly<Record<string, string>>;\n\t/**\n\t * `--allow-dev-services`: every construct the stage does not account for\n\t * gets its dev service.\n\t */\n\tallow: boolean;\n\t/** The stage's base domain, for the examples. */\n\tdomain?: string;\n\t/**\n\t * What the stage's providers say, by kind: a kind one backs is accounted\n\t * for, so no dev service stands in for it, and a missing key of it names\n\t * what creates it.\n\t */\n\tproviders?: StageProviderNotes;\n}\n\n/** The stage's providers, as a deploy's checks read them. */\nexport interface StageProviderNotes {\n\tobjects?: StageProviderNote;\n\temail?: StageProviderNote;\n}\n\n/** What the stage's provider says of one kind. */\nexport interface StageProviderNote {\n\t/** A provider (or `false`) backs the kind: no dev service for it. */\n\taccounted: boolean;\n\t/** What creates a missing key of it. */\n\thint?: string;\n}\n\n/** Where a deployed stage's mail and storage come from. */\nexport interface ExternalServices {\n\t/** Keys the stage needs and has not set. Empty when it can deploy. */\n\tmissing: MissingServiceKey[];\n\t/** The buckets the target runs MinIO for. */\n\tminio: string[];\n\t/** The mail constructs the target runs Mailpit for. */\n\tmailpit: string[];\n}\n\n/** One dev service a run uses, and for which constructs. */\nexport interface DevServiceUse {\n\tservice: DevService;\n\tids: string[];\n}\n\n/** A third party's credentials a construct reads: an external API's, or a `Credential`. */\nexport interface CredentialDeclaration {\n\tid: string;\n\tkind: 'external-api' | 'credential';\n\t/** The apps that read it, where known. */\n\tapps?: readonly string[];\n}\n\n/** What a stage-supplied key belongs to. */\nexport type StageKeyKind =\n\t| 'bucket'\n\t| 'email'\n\t| 'file-server'\n\t| 'external-api'\n\t| 'credential'\n\t/** The server a compose stage's stack runs on: `GKM_SERVER_IPV4`. */\n\t| 'server';\n\n/**\n * One key only the stage's secrets can hold — nothing derives it — whether\n * or not it is set.\n */\nexport interface StageKey {\n\tkey: string;\n\t/** The construct that reads it. */\n\tid: string;\n\tkind: StageKeyKind;\n\t/** What it is, for the line that names it. */\n\twhat: string;\n\t/** A line after `what`, for what else there is to know about it. */\n\tnote?: string;\n\t/** A placeholder value to show in the `gkm secrets:set` line. */\n\texample: string;\n\t/** The dev service that would stand in for it, where one can. */\n\tservice?: DevService;\n\t/** What creates it, where a provider backs it on the stage. */\n\thint?: string;\n\t/** A file server's bucket. */\n\tof?: string;\n\t/** The apps that read it, where known. */\n\tapps?: readonly string[];\n}\n\nexport interface StageKeysInput {\n\t/** Whether the stage is the local one, which derives its mail and storage. */\n\tlocal: boolean;\n\t/** Every mail and storage construct something on the stage reads. */\n\tservices?: readonly ServiceDeclaration[];\n\t/** Every third party's credentials something on the stage reads. */\n\tcredentials?: readonly CredentialDeclaration[];\n\t/** The stage's base domain, for the examples. */\n\tdomain?: string;\n\t/** What the stage's providers say — see {@link StageProviderNotes}. */\n\tproviders?: StageProviderNotes;\n\t/**\n\t * The stage serves a domain from a server of its own — a compose stage —\n\t * so its secrets hold the server's address, `GKM_SERVER_IPV4`.\n\t */\n\tserver?: boolean;\n}\n\n/**\n * Every key a stage must be given rather than derive — the one list both a\n * deploy's checks and `gkm secrets:add` read, so what a deploy refuses and\n * what the builder offers cannot drift.\n *\n * - Deployed, mail is its URL and its sending address, a bucket its URL, and\n * a file server its public URL. Locally all of it is Mailpit and MinIO.\n * - On every stage, a third party's credentials: nobody but the third party\n * can issue them.\n *\n * Never a derived value: a database URL, a generated secret, the seed.\n */\nexport function requiredStageKeys(input: StageKeysInput): StageKey[] {\n\tconst domain = input.domain ?? 'example.com';\n\tconst keys: StageKey[] = [];\n\tconst add = (entry: StageKey) => {\n\t\tif (!keys.some((k) => k.key === entry.key)) keys.push(entry);\n\t};\n\tconst byId = <T extends { id: string }>(list: readonly T[] | undefined) =>\n\t\t[...(list ?? [])].sort((a, b) => a.id.localeCompare(b.id));\n\tconst apps = (d: { apps?: readonly string[] }) =>\n\t\td.apps?.length ? { apps: [...d.apps].sort() } : {};\n\n\tif (!input.local) {\n\t\tconst services = byId(input.services);\n\t\t// A kind a provider backs on the stage has no dev service, and a key of\n\t\t// it names what creates it.\n\t\tconst backing = (\n\t\t\tnote: StageProviderNote | undefined,\n\t\t\tservice: DevService,\n\t\t) =>\n\t\t\tnote?.accounted ? (note.hint ? { hint: note.hint } : {}) : { service };\n\t\tconst storage = backing(input.providers?.objects, 'minio');\n\t\tconst mail = backing(input.providers?.email, 'mailpit');\n\t\tfor (const d of services.filter((d) => d.kind === 'email')) {\n\t\t\tadd({\n\t\t\t\tkey: providedKeyFor(d.id, 'email', 'url'),\n\t\t\t\tid: d.id,\n\t\t\t\tkind: 'email',\n\t\t\t\twhat: `where '${d.id}' sends mail — any SMTP server`,\n\t\t\t\texample: `smtp://user:password@smtp.${domain}:587`,\n\t\t\t\t...mail,\n\t\t\t\t...apps(d),\n\t\t\t});\n\t\t\tadd({\n\t\t\t\tkey: providedKeyFor(d.id, 'email', 'from'),\n\t\t\t\tid: d.id,\n\t\t\t\tkind: 'email',\n\t\t\t\twhat: `the address '${d.id}' sends from, on a domain the mail server has verified`,\n\t\t\t\texample: `noreply@${domain}`,\n\t\t\t\t...mail,\n\t\t\t\t...apps(d),\n\t\t\t});\n\t\t}\n\t\tfor (const d of services.filter((d) => d.kind === 'objects')) {\n\t\t\tadd({\n\t\t\t\tkey: providedKeyFor(d.id, 'objects', 'connectionString'),\n\t\t\t\tid: d.id,\n\t\t\t\tkind: 'bucket',\n\t\t\t\twhat: `the bucket '${d.id}' — S3, R2, or any S3-compatible store (add &endpoint=… for one that is not S3)`,\n\t\t\t\tnote: `credentials are optional: a key for this bucket alone in the URL (s3://KEY:SECRET@${appKey(d.id)}?…) wins; without one, the shared AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY or a role signs`,\n\t\t\t\texample: `s3://${appKey(d.id)}?region=eu-west-1`,\n\t\t\t\t...storage,\n\t\t\t\t...apps(d),\n\t\t\t});\n\t\t}\n\t\tfor (const d of services.filter((d) => d.kind === 'file-server')) {\n\t\t\tadd({\n\t\t\t\tkey: providedKeyFor(d.id, 'file-server', 'url'),\n\t\t\t\tid: d.id,\n\t\t\t\tkind: 'file-server',\n\t\t\t\twhat: `the public address '${d.id}' serves its bucket on — a CDN or the bucket's own domain`,\n\t\t\t\texample: `https://${fileServerLabel(d.id)}.${domain}`,\n\t\t\t\t...storage,\n\t\t\t\t...(d.of ? { of: d.of } : {}),\n\t\t\t\t...apps(d),\n\t\t\t});\n\t\t}\n\t}\n\n\tif (!input.local && input.server) {\n\t\tadd({\n\t\t\tkey: SERVER_IPV4_KEY,\n\t\t\tid: 'server',\n\t\t\tkind: 'server',\n\t\t\twhat: \"the public IPv4 address of the server the stage's stack runs on — its hosts' DNS records point at it, and every deploy checks they do\",\n\t\t\tnote: `${SERVER_IPV6_KEY} adds its IPv6 address (AAAA records); neither is ever handed to an app`,\n\t\t\texample: '203.0.113.10',\n\t\t});\n\t}\n\n\tfor (const d of byId(input.credentials)) {\n\t\tadd({\n\t\t\tkey: providedKeyFor(d.id, d.kind, 'credentials'),\n\t\t\tid: d.id,\n\t\t\tkind: d.kind,\n\t\t\twhat:\n\t\t\t\td.kind === 'external-api'\n\t\t\t\t\t? `the credentials '${d.id}' was issued for this stage, as its schema describes them`\n\t\t\t\t\t: `the credential '${d.id}', as its schema describes it`,\n\t\t\texample: '{\"apiKey\":\"…\"}',\n\t\t\t...apps(d),\n\t\t});\n\t}\n\n\treturn keys;\n}\n\n/**\n * Whether only the stage's secrets can supply `key` to a construct of `kind`\n * — what nothing on the stage derives.\n *\n * A third party's credentials, always. Deployed, also each generated secret\n * and keyring: the stage generated each one once, and every run reads the\n * same value back.\n */\nexport function suppliedOnly(\n\tkind: string,\n\tid: string,\n\tkey: string,\n\tlocal: boolean,\n): boolean {\n\tif (kind === 'credential') return true;\n\tif (kind === 'external-api')\n\t\treturn key === providedKeyFor(id, 'external-api', 'credentials');\n\tif (local) return false;\n\treturn kind === 'secret' || kind === 'encryption';\n}\n\n/**\n * Where a deployed stage's mail and storage come from, and what it lacks.\n *\n * - Mail is external once its URL is set, and then needs its sending\n * address too. Unset, it is Mailpit where allowed — the address derived\n * unless set — and missing otherwise.\n * - A bucket is external once its URL is set; its credentials, in the URL or\n * the shared pair, are optional. Unset, it is MinIO where allowed, and\n * missing otherwise.\n * - A file server's URL is derived where its bucket is MinIO, unless set;\n * over an external bucket the stage must set it.\n *\n * The keys themselves are {@link requiredStageKeys}'s.\n */\nexport function externalServices(\n\tinput: ExternalServicesInput,\n): ExternalServices {\n\tconst { supplied, allow } = input;\n\tconst has = (key: string) => supplied[key] !== undefined;\n\n\tconst required = requiredStageKeys({\n\t\tlocal: false,\n\t\tservices: input.declarations,\n\t\t...(input.domain ? { domain: input.domain } : {}),\n\t\t...(input.providers ? { providers: input.providers } : {}),\n\t});\n\n\t// A dev service stands in for each construct the stage does not account\n\t// for: no key in its secrets, and no provider backing its kind.\n\tconst standIn = (k: StageKey) =>\n\t\tallow && k.service !== undefined && !has(k.key);\n\tconst mailpit = required\n\t\t.filter(\n\t\t\t(k) =>\n\t\t\t\tk.kind === 'email' && k.key === providedKeyFor(k.id, 'email', 'url'),\n\t\t)\n\t\t.filter(standIn)\n\t\t.map((k) => k.id);\n\tconst minio = required\n\t\t.filter((k) => k.kind === 'bucket')\n\t\t.filter(standIn)\n\t\t.map((k) => k.id);\n\n\tconst covered = (k: StageKey) =>\n\t\t(k.kind === 'email' && mailpit.includes(k.id)) ||\n\t\t(k.kind === 'bucket' && minio.includes(k.id)) ||\n\t\t(k.kind === 'file-server' && k.of !== undefined && minio.includes(k.of));\n\n\tconst missing = required\n\t\t.filter((k) => !has(k.key) && !covered(k))\n\t\t.map(\n\t\t\t({\n\t\t\t\tkey,\n\t\t\t\tid,\n\t\t\t\twhat,\n\t\t\t\tnote,\n\t\t\t\texample,\n\t\t\t\tservice,\n\t\t\t\tapps,\n\t\t\t\thint,\n\t\t\t}): MissingServiceKey => ({\n\t\t\t\tkey,\n\t\t\t\tid,\n\t\t\t\twhat,\n\t\t\t\t...(note ? { note } : {}),\n\t\t\t\texample,\n\t\t\t\t...(service ? { service } : {}),\n\t\t\t\t...(apps ? { apps } : {}),\n\t\t\t\t...(hint ? { hint } : {}),\n\t\t\t}),\n\t\t);\n\n\treturn { missing, minio, mailpit };\n}\n\n/** The dev services a run uses, one entry per service it runs. */\nexport function devServicesUsed(services: ExternalServices): DevServiceUse[] {\n\tconst used: DevServiceUse[] = [];\n\tif (services.mailpit.length > 0) {\n\t\tused.push({ service: 'mailpit', ids: services.mailpit });\n\t}\n\tif (services.minio.length > 0) {\n\t\tused.push({ service: 'minio', ids: services.minio });\n\t}\n\treturn used;\n}\n\n/** The line a run prints for each dev service a deployed stage uses. */\nexport function devServiceWarning(stage: string, use: DevServiceUse): string {\n\tconst what =\n\t\tuse.service === 'mailpit'\n\t\t\t? `Mailpit is catching mail for ${use.ids.join(', ')}. It delivers NO mail: nobody receives a sign-in link, a receipt or a reset`\n\t\t\t: `MinIO is storing ${use.ids.join(', ')}. Every object is on one container's disk, with no replication and no backup`;\n\treturn (\n\t\t`⚠️ DEV SERVICE ON A DEPLOYED STAGE (${stage}): ${what}. It is not ` +\n\t\t`production-grade — set the stage's own keys in its secrets for that.`\n\t);\n}\n\n/**\n * Report each dev service a run uses: a loud line, and a `dev-service.used`\n * event a host can act on.\n */\nexport function reportDevServices(\n\tctx: {\n\t\tstage: string;\n\t\tlogger: { warn(message: string): void };\n\t\temit(event: {\n\t\t\ttype: 'dev-service.used';\n\t\t\tservice: DevService;\n\t\t\tstage: string;\n\t\t\tconstructs: string[];\n\t\t}): void;\n\t},\n\tuses: readonly DevServiceUse[],\n): void {\n\tfor (const use of uses) {\n\t\tctx.logger.warn(`\\n${devServiceWarning(ctx.stage, use)}`);\n\t\tctx.emit({\n\t\t\ttype: 'dev-service.used',\n\t\t\tservice: use.service,\n\t\t\tstage: ctx.stage,\n\t\t\tconstructs: use.ids,\n\t\t});\n\t}\n}\n","/**\n * Providers: what creates the thing a construct is backed by, on a stage.\n *\n * The manifest says a bucket exists (`ObjectStorage`); `deploy.<kind>.<stage>`\n * says what backs it there. A stage that names a provider has gkm *create*\n * the backing resource — when it holds the account's provisioning\n * credentials — and write the connection value into the stage's secrets,\n * where every deploy reads it as if it had been set by hand. A stage that\n * names none is `external`: the value is yours to set, as it always was.\n *\n * | Part | What it is |\n * | ------------------------ | ------------------------------------------------------- |\n * | provisioning credentials | What creates the resource. Never given to an app. |\n * | `ensure()` | Idempotent find-or-create. Records in state. Never deletes. |\n * | runtime credentials | The keys it writes into the stage's secrets. |\n * | `verify()` | The cheap check every deploy runs. |\n *\n * The key under `deploy` is the manifest kind — `objects`, which\n * `ObjectStorage` and `FileServer` produce, `inbox`, `email` — so a kind\n * such as `deploy.cache` slots in beside them with providers of its own.\n */\n\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport type { DeployIdentity } from '../deploy/identity.js';\nimport type { ResourceRecord } from '../deploy/StateStore.js';\nimport type { BoundSubscriber } from '../reconcile/discover.js';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\n\n/** The manifest kinds a stage can name a provider for. */\nexport const PROVIDER_KINDS = ['objects', 'inbox', 'email'] as const;\n\nexport type ProviderKind = (typeof PROVIDER_KINDS)[number];\n\n/** A provider's own entry: `{ provider: 's3', … }`. */\nexport interface ProviderConfig {\n\tprovider: string;\n}\n\n/**\n * One stage's entry under `deploy.<kind>`:\n *\n * - `'external'` — the default: the stage's secrets hold the key, set by you.\n * - `{ provider, … }` — that provider creates the resource and writes the key.\n * - `false` — the stage has none of this kind; a construct of it is refused.\n */\nexport type StageProviderEntry<C extends ProviderConfig = ProviderConfig> =\n\t| 'external'\n\t| C\n\t| false;\n\n/** One change `ensure()` makes, or — in a dry run — would make. */\nexport interface ProvisionAction {\n\t/** The construct it is for. */\n\tconstruct: string;\n\t/** What it acts on: `bucket acme-shop-prod-uploads`. */\n\tresource: string;\n\t/** What it does: `create`, `set CORS (2 origins)`. */\n\tchange: string;\n}\n\n/** The stage's provisioning record, as `ensure()` reads and writes it. */\nexport interface ProvisionState {\n\t/** A resource recorded by an earlier run. */\n\trecord(key: string): ResourceRecord | undefined;\n\t/** About to be created — written before the call that creates it. */\n\tpending(entry: StateEntry): Promise<void>;\n\t/** Exists, as `id`. */\n\tready(entry: StateEntry, id: string): Promise<void>;\n\t/** When the stage was last deployed, for a rotation to know it was. */\n\treadonly lastDeployedAt?: string;\n}\n\nexport interface StateEntry {\n\t/** `<type>:<name>`, unique within the stage. */\n\tkey: string;\n\ttype: string;\n\tdata?: Record<string, unknown>;\n}\n\n/** What `ensure()` is handed. */\nexport interface EnsureContext<C extends ProviderConfig, K> {\n\tworkspace: NormalizedWorkspace;\n\tmanifest: ConstructManifest;\n\t/**\n\t * Each Worker's subscribers, from discovery — by export and the key its\n\t * deliveries come from. What a provider subscribes on a worker's behalf.\n\t */\n\tsubscribers?: Readonly<Record<string, readonly BoundSubscriber[]>>;\n\tstage: string;\n\tidentity: DeployIdentity;\n\tconfig: C;\n\t/** The provisioning credentials {@link ResourceProvider.credentials} found. */\n\tcredential: K;\n\t/** The stage's secrets as they are now, by key. */\n\tsecrets: Readonly<Record<string, string>>;\n\tstate: ProvisionState;\n\tdryRun: boolean;\n\t/** `--rotate-keys`: issue each runtime key a successor. */\n\trotateKeys: boolean;\n\t/** `--retire-old-keys`: delete a rotated-out key without waiting for a deploy. */\n\tretireOldKeys: boolean;\n\t/**\n\t * Runs `apply` and records `action` — or, in a dry run, only records it.\n\t * Every write to the provider's account goes through here.\n\t */\n\tchange(action: ProvisionAction, apply: () => Promise<void>): Promise<void>;\n\t/**\n\t * Writes keys into the stage's secrets now — not at the end of the run, so\n\t * a secret the account shows only once is kept the moment it exists. A dry\n\t * run writes nothing.\n\t */\n\twriteSecrets(values: Record<string, string>): Promise<void>;\n\t/**\n\t * Writes DNS records through the stage's DNS providers (`dns`), as the\n\t * deploy's own DNS step does — what a certificate's validation record and\n\t * a CDN's name, a domain's inbound mail (MX) need. A dry run prints them\n\t * and writes nothing.\n\t */\n\twriteDns(records: readonly ProviderDnsRecord[]): Promise<ProviderDnsResult>;\n\tlog(line: string): void;\n}\n\n/** One record a provider asks the stage's DNS for. */\nexport type ProviderDnsRecord =\n\t| {\n\t\t\t/** The full name: `_abc.files.example.com`. */\n\t\t\thost: string;\n\t\t\ttype: 'CNAME';\n\t\t\tvalue: string;\n\t }\n\t| {\n\t\t\t/** The full name: `example.com`, `*.example.com`. */\n\t\t\thost: string;\n\t\t\ttype: 'MX';\n\t\t\t/** The mail server: `inbound-smtp.eu-west-1.amazonaws.com`. */\n\t\t\tvalue: string;\n\t\t\t/** Lower is preferred: `10`. */\n\t\t\tpriority: number;\n\t };\n\n/** What writing a provider's records came to. */\nexport interface ProviderDnsResult {\n\t/**\n\t * Hosts no DNS provider wrote — under no domain in `dns`, or a `manual`\n\t * one — printed for the person to create.\n\t */\n\tmanual: string[];\n}\n\n/** What `verify()` is handed. */\nexport interface VerifyContext<C extends ProviderConfig> {\n\tworkspace: NormalizedWorkspace;\n\tmanifest: ConstructManifest;\n\tstage: string;\n\tconfig: C;\n\t/** The stage's secrets, by key. */\n\tsecrets: Readonly<Record<string, string>>;\n\t/**\n\t * What the stage's state records, by key — how a provider knows a key it\n\t * checks was issued moments ago. Absent when nothing was read.\n\t */\n\tresources?: Readonly<Record<string, ResourceRecord>>;\n\t/** Progress worth printing: waiting on something. */\n\tlog?: (line: string) => void;\n}\n\n/** Where a provider's provisioning credentials are looked for. */\nexport interface CredentialLookup {\n\tstage: string;\n\t/** `--profile`, when given. */\n\tprofile?: string;\n\tenv: NodeJS.ProcessEnv;\n\t/** The CLI's home, for stored logins. */\n\thome?: string;\n}\n\n/**\n * A provider. `C` is its config entry, `K` its provisioning credential.\n *\n * Built-ins are registered in `providers/registry.ts`, the way a deploy\n * target's built-ins are.\n */\nexport interface ResourceProvider<\n\tC extends ProviderConfig = ProviderConfig,\n\tK = unknown,\n> {\n\treadonly kind: ProviderKind;\n\t/** What `provider:` names it. */\n\treadonly name: string;\n\t/**\n\t * Its config entry checked: returns it, or throws a named error saying\n\t * what is wrong — what the workspace schema runs.\n\t */\n\tcheck(stage: string, config: ProviderConfig): C;\n\t/** How its provisioning credentials are supplied, for messages. */\n\treadonly provisioning: {\n\t\t/** The environment variables it reads. */\n\t\tenv: readonly string[];\n\t\t/** A `gkm login --provider` name, where it has one. */\n\t\tlogin?: string;\n\t\t/** One line saying how to supply them. */\n\t\tdescribe: string;\n\t};\n\t/** Its provisioning credentials, or `undefined` when there are none. */\n\tcredentials(lookup: CredentialLookup): Promise<K | undefined>;\n\t/** The keys it writes into the stage's secrets for these constructs. */\n\truntimeKeys(manifest: ConstructManifest): string[];\n\tensure(ctx: EnsureContext<C, K>): Promise<void>;\n\tverify(ctx: VerifyContext<C>): Promise<void>;\n}\n","/**\n * What a deploy's checks read off `deploy.<kind>.<stage>`, without loading a\n * provider: which kinds the stage accounts for, what creates a missing key,\n * and a kind the stage has none of.\n */\n\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport type { StageProviderNotes } from '../deploy/devServices.js';\nimport { GkmError } from '../errors';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\nimport { provisioningOf, stageProvider } from './config.js';\nimport { PROVIDER_KINDS, type ProviderKind } from './types.js';\n\n/** The constructs of a kind: `objects` is every bucket. */\nexport function constructsOf(manifest: ConstructManifest, kind: ProviderKind) {\n\treturn Object.entries(manifest)\n\t\t.filter(([, d]) => d.kind === kind)\n\t\t.map(([id]) => id)\n\t\t.sort();\n}\n\n/** A stage that names `false` for a kind, and declares constructs of it. */\nexport class StageProviderDisabled extends GkmError {\n\tconstructor(\n\t\treadonly kind: ProviderKind,\n\t\treadonly stage: string,\n\t\treadonly ids: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`deploy.${kind}.${stage} is false — the stage has no ${kind} — and ` +\n\t\t\t\t`${ids.join(', ')} ${ids.length === 1 ? 'is' : 'are'} declared. ` +\n\t\t\t\t`Name what backs ${ids.length === 1 ? 'it' : 'them'} on '${stage}' ` +\n\t\t\t\t`(deploy.${kind}.${stage}: 'external', or a provider), or remove ` +\n\t\t\t\t`the ${ids.length === 1 ? 'construct' : 'constructs'}.`,\n\t\t);\n\t\tthis.name = 'StageProviderDisabled';\n\t}\n}\n\n/** The command a stage's providers are run with: every deploy runs them. */\nexport function provisionCommand(stage: string): string {\n\treturn `gkm deploy --stage ${stage}`;\n}\n\n/**\n * The line a stage missing a key a provider would write is given: what\n * creates it, and with which credentials. Undefined when no provider backs\n * the kind on the stage.\n */\nexport function provisionHint(\n\tworkspace: Pick<NormalizedWorkspace, 'deploy' | 'stages'>,\n\tkind: ProviderKind,\n\tstage: string,\n): string | undefined {\n\tconst choice = stageProvider(workspace as never, kind, stage);\n\tif (choice.mode !== 'provider') return undefined;\n\tconst provisioning = provisioningOf(kind, choice.name);\n\tif (!provisioning) return undefined;\n\treturn (\n\t\t`deploy.${kind}.${stage} is ${choice.name}: the deploy ` +\n\t\t`(${provisionCommand(stage)}) creates it and writes this key, with ` +\n\t\t`${provisioning.describe}` +\n\t\t(provisioning.login\n\t\t\t? `, or gkm login --provider ${provisioning.login}`\n\t\t\t: '')\n\t);\n}\n\n/**\n * What a deploy's checks read off the stage's providers: whether each kind is\n * accounted for — a provider, or `false` — so no dev service stands in for\n * it, and what creates a missing key of it.\n */\nexport function stageProviderNotes(\n\tworkspace: Pick<NormalizedWorkspace, 'deploy' | 'stages'>,\n\tstage: string,\n): StageProviderNotes {\n\tconst notes: StageProviderNotes = {};\n\tfor (const kind of ['objects', 'email'] as const) {\n\t\tif (stageProvider(workspace as never, kind, stage).mode === 'external') {\n\t\t\tcontinue;\n\t\t}\n\t\tconst hint = provisionHint(workspace, kind, stage);\n\t\tnotes[kind] = { accounted: true, ...(hint ? { hint } : {}) };\n\t}\n\treturn notes;\n}\n\n/**\n * A kind the stage set to `false`, declared anyway — refused before anything\n * else is checked. Pure: what a stack is composed from.\n *\n * @throws {StageProviderDisabled}\n */\nexport function assertStageProvidersEnabled(\n\tworkspace: Pick<NormalizedWorkspace, 'deploy' | 'stages'>,\n\tmanifest: ConstructManifest,\n\tstage: string,\n): void {\n\tfor (const kind of PROVIDER_KINDS) {\n\t\tconst ids = constructsOf(manifest, kind);\n\t\tif (ids.length === 0) continue;\n\t\tif (stageProvider(workspace as never, kind, stage).mode === 'none') {\n\t\t\t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AA;CACvC,MAAM,eAAeC,kBAAAA,eAAe,MAAM,OAAO,IAAI;CACrD,IAAI,CAAC,cAAc,OAAO,KAAA;CAC1B,OACC,UAAU,KAAK,GAAG,MAAM,MAAM,OAAO,KAAK,gBACtC,iBAAiB,KAAK,EAAE,yCACzB,aAAa,cACf,aAAa,QACX,6BAA6B,aAAa,UAC1C;AAEL;;;;;;AAOA,SAAgB,mBACf,WACA,OACqB;CACrB,MAAM,QAA4B,CAAC;CACnC,KAAK,MAAM,QAAQ,CAAC,WAAW,OAAO,GAAY;EACjD,IAAID,kBAAAA,cAAc,WAAoB,MAAM,KAAK,CAAC,CAAC,SAAS,YAC3D;EAED,MAAM,OAAO,cAAc,WAAW,MAAM,KAAK;EACjD,MAAM,QAAQ;GAAE,WAAW;GAAM,GAAI,OAAO,EAAE,KAAK,IAAI,CAAC;EAAG;CAC5D;CACA,OAAO;AACR;;;;;;;AAQA,SAAgB,4BACf,WACA,UACA,OACO;CACP,KAAK,MAAM,QAAQ,gBAAgB;EAClC,MAAM,MAAM,aAAa,UAAU,IAAI;EACvC,IAAI,IAAI,WAAW,GAAG;EACtB,IAAIA,kBAAAA,cAAc,WAAoB,MAAM,KAAK,CAAC,CAAC,SAAS,QAC3D,MAAM,IAAI,sBAAsB,MAAM,OAAO,GAAG;CAElD;AACD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snsSubscriptions-CXRa_bwG.mjs","names":["dnsLookup"],"sources":["../src/providers/aws.ts","../src/compose/dns.ts","../src/deploy/snsSubscriptions.ts"],"sourcesContent":["/**\n * The AWS account a provider provisions in — the stage's, found the way the\n * SSM and Secrets Manager stores find it.\n *\n * 1. `--profile`, resolved on its own: exported keys left over from another\n * account never win over a profile someone named.\n * 2. `AWS_PROFILE`, else `AWS_ACCESS_KEY_ID`/`AWS_SECRET_ACCESS_KEY` — the\n * deploy's own `aws` credential kind (`storedCredentials`).\n * 3. The SDK's default chain: `~/.aws` default profile, SSO, a role. In CI,\n * whatever `aws-actions/configure-aws-credentials` exported.\n *\n * None of them: the provider has no provisioning credentials, and the stage\n * is treated as `external`.\n */\n\nimport {\n\ttype AwsCredential,\n\tstoredCredentials,\n} from '../deploy/credentials.js';\nimport type { CredentialLookup } from './types.js';\n\n/** An AWS credential, or the default chain the SDK resolves itself. */\nexport type AwsProvisioning =\n\t| AwsCredential\n\t| {\n\t\t\tchain: true;\n\t\t\tregion?: string;\n\t };\n\nexport async function awsProvisioningCredentials(\n\tlookup: CredentialLookup,\n): Promise<AwsProvisioning | undefined> {\n\tconst region = lookup.env.AWS_REGION ?? lookup.env.AWS_DEFAULT_REGION;\n\tconst where = region ? { region } : {};\n\tif (lookup.profile) return { profile: lookup.profile, ...where };\n\n\tconst stored = await storedCredentials({\n\t\tenv: lookup.env,\n\t\t...(lookup.home ? { home: lookup.home } : {}),\n\t}).get({ kind: 'aws', stage: lookup.stage });\n\tif (stored) return stored;\n\n\ttry {\n\t\tconst { fromNodeProviderChain } = await import(\n\t\t\t'@aws-sdk/credential-providers'\n\t\t);\n\t\tawait fromNodeProviderChain({ timeout: 1000, maxRetries: 0 })();\n\t\treturn { chain: true, ...where };\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * An S3-compatible endpoint the environment points the SDK at — the AWS\n * emulator in tests. The SDK reads it itself; it is read here too, because\n * an emulator takes path-style requests, and a key written for one has to\n * say where it is.\n */\nexport function awsEndpoint(\n\tenv: NodeJS.ProcessEnv,\n\tservice: 'S3' | 'IAM' | 'CLOUDFRONT' | 'ACM' | 'SNS' | 'SQS' | 'STS' | 'SES',\n): string | undefined {\n\treturn env[`AWS_ENDPOINT_URL_${service}`] ?? env.AWS_ENDPOINT_URL;\n}\n\n/** An SDK client's config for a provisioning credential. */\nexport async function awsClientConfig(\n\tcredential: AwsProvisioning,\n\tregion: string,\n): Promise<{\n\tregion: string;\n\tcredentials?:\n\t\t| ReturnType<typeof import('@aws-sdk/credential-providers').fromIni>\n\t\t| { accessKeyId: string; secretAccessKey: string; sessionToken?: string };\n}> {\n\tif ('profile' in credential) {\n\t\tconst { fromIni } = await import('@aws-sdk/credential-providers');\n\t\treturn { region, credentials: fromIni({ profile: credential.profile }) };\n\t}\n\tif ('accessKeyId' in credential) {\n\t\treturn {\n\t\t\tregion,\n\t\t\tcredentials: {\n\t\t\t\taccessKeyId: credential.accessKeyId,\n\t\t\t\tsecretAccessKey: credential.secretAccessKey,\n\t\t\t\t...(credential.sessionToken\n\t\t\t\t\t? { sessionToken: credential.sessionToken }\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t};\n\t}\n\treturn { region };\n}\n","/**\n * A compose stage's DNS: the records its public hosts need, and the check that\n * they resolve to its server before a certificate is asked for.\n *\n * - **The server** (`serverAddress`): the stage's own secrets hold its public\n * addresses — `GKM_SERVER_IPV4`, and `GKM_SERVER_IPV6` where it has one.\n * Reserved for gkm: never handed to an app.\n * - **The plan** (`planStackDns`, pure): every public host the stack serves —\n * its apex, each app, each file server, the public log UI — pointed at the\n * server. An A record per host (and an AAAA with an IPv6 address), or, where\n * the domain's `dns` entry says `records: { mode: 'cname', target }`, one A\n * record for the target and a CNAME to it for every other host but the\n * apex, which DNS forbids a CNAME at.\n * - **Applying it** (`applyStackDns`): through the domain's provider in `dns`,\n * a record set at a time. A record with the right value is left alone; one\n * with another value is replaced and the change printed. A `manual` domain\n * is printed and nothing else. A dry run reads, prints and writes nothing.\n * - **The check** (`checkStackDns`): each host resolved with the system\n * resolver. One that is not the server stops the deploy with\n * {@link HostNotPointingAtServer}, before Caddy or Traefik ask Let's Encrypt\n * for a certificate it cannot get — and use up the rate limit trying.\n * - **What gkm wrote before** (`diffRecordedDns`, pure): the plan against the\n * records the stage's state says gkm wrote — added, kept, and stale: a\n * host the stage no longer serves, after a domain or an app changed.\n * - **The prune** (`pruneStackDns`): each stale record deleted through its\n * domain's provider, if it still holds the value gkm wrote. One someone\n * pointed elsewhere is left alone; one no provider can delete is printed.\n * - **The step** (`stageDns`): all of it, as every deploy runs it — the plan applied through each provider,\n * what was written read back from the provider, the stale records pruned,\n * and only the hosts no provider wrote resolved publicly. A brand-new name\n * is never looked up before its record exists, so no resolver caches it as\n * missing.\n */\n\nimport { lookup as dnsLookup } from 'node:dns/promises';\nimport { isIPv4, isIPv6 } from 'node:net';\nimport type {\n\tCredentialProvider,\n\tGoDaddyCredential,\n\tHostingerCredential,\n} from '../deploy/credentials';\nimport type { DnsResourceRecord } from '../deploy/dnsResources';\nimport {\n\tcreateDnsProvider,\n\ttype DnsProvider,\n\ttype DnsRecord,\n\tDnsRecordsUnreadable,\n\ttype DnsConfig as SchemaDnsConfig,\n} from '../target/dokploy/dns/DnsProvider';\nimport type { GoDaddyProviderOptions } from '../target/dokploy/dns/GoDaddyProvider';\nimport {\n\textractSubdomain,\n\tfindRootDomain,\n\tnormalizeDnsConfig,\n} from '../target/dokploy/dns/index';\nimport type {\n\tDnsProvider as DnsProviderConfig,\n\tWorkspaceDnsConfig,\n} from '../workspace/types';\nimport {\n\tcnameTarget,\n\ttype DnsRecordsMode,\n\tisReservedStageKey,\n\tSERVER_IPV4_KEY,\n\tSERVER_IPV6_KEY,\n} from './dnsConfig';\n\nexport { isReservedStageKey, SERVER_IPV4_KEY, SERVER_IPV6_KEY };\n\nimport { GkmError } from '../errors';\nimport type { ComposeStack } from './stack';\n\n/** A deployed stage's server: what its hosts' records point at. */\nexport interface ServerAddress {\n\tipv4: string;\n\tipv6?: string;\n}\n\n/** The line that says how to set the server's address. */\nexport function serverAddressHint(stage: string): string {\n\treturn `gkm secrets:set ${SERVER_IPV4_KEY} '<ip>' --stage ${stage}`;\n}\n\n/** A server address in the stage's secrets that is not an address. */\nexport class ServerAddressInvalid extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly key: string,\n\t\treadonly value: string,\n\t) {\n\t\tconst ipv4 = key === SERVER_IPV4_KEY;\n\t\tsuper(\n\t\t\t`${key} in the '${stage}' stage's secrets is ${JSON.stringify(value)}, ` +\n\t\t\t\t`which is not an ${ipv4 ? 'IPv4 address (like 203.0.113.10)' : 'IPv6 address (like 2001:db8::10)'}. ` +\n\t\t\t\t`Set the server's public address: gkm secrets:set ${key} '<ip>' --stage ${stage}.`,\n\t\t);\n\t\tthis.name = 'ServerAddressInvalid';\n\t}\n}\n\n/**\n * A compose stage that serves real domains with no server address: its hosts\n * cannot be pointed or checked, and a certificate would be asked for blind.\n */\nexport class ServerAddressMissing extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly domain: string,\n\t) {\n\t\tsuper(\n\t\t\t`The '${stage}' stage serves ${domain} and its secrets hold no ` +\n\t\t\t\t`${SERVER_IPV4_KEY} — the public address of the server its stack runs ` +\n\t\t\t\t\"on, which its hosts' DNS records point at and every deploy checks \" +\n\t\t\t\t`before asking for certificates. Set it: ${serverAddressHint(stage)} ` +\n\t\t\t\t`(and ${SERVER_IPV6_KEY} for an IPv6 address).`,\n\t\t);\n\t\tthis.name = 'ServerAddressMissing';\n\t}\n}\n\n/**\n * The server's address from the stage's secrets, checked — `undefined` when\n * `GKM_SERVER_IPV4` is not set.\n *\n * @throws {ServerAddressInvalid} for a value that is not an address\n */\nexport function serverAddress(\n\tstage: string,\n\tcustom: Readonly<Record<string, string>> | undefined,\n): ServerAddress | undefined {\n\tconst ipv4 = custom?.[SERVER_IPV4_KEY]?.trim();\n\tconst ipv6 = custom?.[SERVER_IPV6_KEY]?.trim();\n\tif (ipv6 && !isIPv6(ipv6)) {\n\t\tthrow new ServerAddressInvalid(stage, SERVER_IPV6_KEY, ipv6);\n\t}\n\tif (!ipv4) return undefined;\n\tif (!isIPv4(ipv4))\n\t\tthrow new ServerAddressInvalid(stage, SERVER_IPV4_KEY, ipv4);\n\treturn { ipv4, ...(ipv6 ? { ipv6 } : {}) };\n}\n\n/**\n * A name that resolves to this machine by definition — `localhost` and every\n * `*.localhost` — and is in nobody's DNS.\n */\nexport function isLocalHost(host: string): boolean {\n\tconst name = host.toLowerCase().replace(/\\.$/, '');\n\treturn name === 'localhost' || name.endsWith('.localhost');\n}\n\n/**\n * The server's address, required where the stage serves real domains — not\n * `*.localhost` ones, which point at this machine already.\n *\n * @throws {ServerAddressMissing} when the stage has a domain and no address\n * @throws {ServerAddressInvalid} for a value that is not an address\n */\nexport function requiredServerAddress(\n\tstage: string,\n\tdomain: string | undefined,\n\tcustom: Readonly<Record<string, string>> | undefined,\n): ServerAddress | undefined {\n\tconst server = serverAddress(stage, custom);\n\tif (!server && domain && !isLocalHost(domain)) {\n\t\tthrow new ServerAddressMissing(stage, domain);\n\t}\n\treturn server;\n}\n\n/**\n * The record types gkm writes: A, AAAA and CNAME for the stack's hosts, and\n * the CNAME and MX records a provider asks for (`writeProviderDns`).\n */\nexport type StackRecordType = 'A' | 'AAAA' | 'CNAME' | 'MX';\n\n/** The types that point a name somewhere — a name holds a CNAME or the others. */\nconst ADDRESS_TYPES: readonly StackRecordType[] = ['A', 'AAAA', 'CNAME'];\n\n/** One record a stack's host needs. */\nexport interface PlannedDnsRecord {\n\t/** The full name: `api.example.com`. */\n\thost: string;\n\t/** The root domain in `dns` it is under. */\n\tdomain: string;\n\t/** Relative to the domain, as providers take it: `api`, `@`. */\n\tname: string;\n\ttype: StackRecordType;\n\t/**\n\t * As a zone file writes it — an MX record's is `<priority> <host>`\n\t * (`mxValue`).\n\t */\n\tvalue: string;\n\tttl: number;\n}\n\n/** One `dns` domain's share of the plan. */\nexport interface DomainDnsPlan {\n\tdomain: string;\n\t/** `godaddy`, `route53`, `manual`, … — `custom` for an object. */\n\tprovider: string;\n\tconfig: DnsProviderConfig;\n\trecords: PlannedDnsRecord[];\n}\n\nexport interface StackDnsPlan {\n\tstage: string;\n\tserver: ServerAddress;\n\tdomains: DomainDnsPlan[];\n\t/** Hosts under no `dns` domain: theirs to point by hand. */\n\tuncovered: string[];\n}\n\n/** Every public host the stack serves, once each, sorted. */\nexport function stackHosts(stack: Pick<ComposeStack, 'routes'>): string[] {\n\treturn [...new Set(stack.routes.map((route) => route.host))].sort();\n}\n\n/** The TTL a domain's records are written with. */\nexport function recordTtl(config: DnsProviderConfig): number {\n\tconst ttl = 'ttl' in config ? config.ttl : undefined;\n\tif (ttl) return ttl;\n\treturn config.provider === 'godaddy' ? 600 : 300;\n}\n\nfunction providerName(config: DnsProviderConfig): string {\n\treturn typeof config.provider === 'string' ? config.provider : 'custom';\n}\n\nexport interface PlanStackDnsInput {\n\tstage: string;\n\thosts: readonly string[];\n\tserver: ServerAddress;\n\tdns: WorkspaceDnsConfig | undefined;\n\t/**\n\t * The stage's wildcard site's host, `*.<domain>` — the one wildcard\n\t * record gkm writes, because its tenants are created by the running app\n\t * and no deploy could write a record for each.\n\t */\n\twildcard?: string;\n}\n\n/**\n * A wildcard host that is not the stage's wildcard site's: gkm writes one\n * record per public host, so a stage on another server — or a name someone\n * else points elsewhere — is never caught by a record it did not ask for.\n * Only `*.<domain>` for a site declared `subdomain: '*'` is written, and it\n * covers no name that has a record of its own.\n */\nexport class DnsWildcardRefused extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly host: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${stage}' would point ${host} at its server, and gkm never writes a ` +\n\t\t\t\t'wildcard record: each public host gets its own. Give the app a ' +\n\t\t\t\t'subdomain of its own instead.',\n\t\t);\n\t\tthis.name = 'DnsWildcardRefused';\n\t}\n}\n\n/** The records a stage's hosts need — pure. */\nexport function planStackDns(input: PlanStackDnsInput): StackDnsPlan {\n\tconst { stage, server } = input;\n\tconst dns = input.dns ? normalizeDnsConfig(input.dns) : {};\n\tconst records = new Map<string, PlannedDnsRecord>();\n\tconst uncovered: string[] = [];\n\n\tconst add = (\n\t\thost: string,\n\t\tdomain: string,\n\t\ttype: StackRecordType,\n\t\tvalue: string,\n\t) => {\n\t\tconst name = extractSubdomain(host, domain);\n\t\trecords.set(`${domain} ${name} ${type}`, {\n\t\t\thost,\n\t\t\tdomain,\n\t\t\tname,\n\t\t\ttype,\n\t\t\tvalue,\n\t\t\tttl: recordTtl(dns[domain]!),\n\t\t});\n\t};\n\tconst pointAt = (host: string, domain: string) => {\n\t\tadd(host, domain, 'A', server.ipv4);\n\t\tif (server.ipv6) add(host, domain, 'AAAA', server.ipv6);\n\t};\n\n\tfor (const raw of input.hosts) {\n\t\tconst host = raw.toLowerCase();\n\t\tif (host.includes('*') && host !== input.wildcard?.toLowerCase()) {\n\t\t\tthrow new DnsWildcardRefused(stage, host);\n\t\t}\n\t\tconst domain = findRootDomain(host, dns);\n\t\tif (!domain) {\n\t\t\tuncovered.push(host);\n\t\t\tcontinue;\n\t\t}\n\t\t// A target under the domain itself — the schema refuses one that is\n\t\t// not — gets the A record every other host's CNAME points at.\n\t\tconst target = cnameTarget(\n\t\t\t(dns[domain] as { records?: DnsRecordsMode }).records,\n\t\t\tstage,\n\t\t);\n\t\tif (target) pointAt(target, domain);\n\t\t// The apex can hold no CNAME — it has the zone's SOA and NS — so it\n\t\t// is always an A record.\n\t\tif (target && host !== domain && host !== target) {\n\t\t\tadd(host, domain, 'CNAME', target);\n\t\t} else {\n\t\t\tpointAt(host, domain);\n\t\t}\n\t}\n\n\tconst domains = new Map<string, DomainDnsPlan>();\n\tfor (const record of [...records.values()].sort(\n\t\t(a, b) =>\n\t\t\ta.domain.localeCompare(b.domain) ||\n\t\t\ta.name.localeCompare(b.name) ||\n\t\t\ta.type.localeCompare(b.type),\n\t)) {\n\t\tconst config = dns[record.domain]!;\n\t\tconst plan = domains.get(record.domain) ?? {\n\t\t\tdomain: record.domain,\n\t\t\tprovider: providerName(config),\n\t\t\tconfig,\n\t\t\trecords: [],\n\t\t};\n\t\tplan.records.push(record);\n\t\tdomains.set(record.domain, plan);\n\t}\n\n\treturn {\n\t\tstage,\n\t\tserver,\n\t\tdomains: [...domains.values()],\n\t\tuncovered: uncovered.sort(),\n\t};\n}\n\n/** One change applying a plan makes — or, in a dry run, would. */\nexport interface DnsChange {\n\tdomain: string;\n\tname: string;\n\ttype: StackRecordType;\n\t/**\n\t * `write`: the provider's key cannot read records, so the record is\n\t * written without knowing what is there — idempotent, and not diffed.\n\t */\n\taction: 'create' | 'update' | 'delete' | 'unchanged' | 'write' | 'manual';\n\t/** The value it is set to — absent for a delete. */\n\tvalue?: string;\n\t/** What it was, for an update or a delete. */\n\tprevious?: string;\n\tttl?: number;\n}\n\nexport interface ApplyStackDnsOptions {\n\tdryRun?: boolean;\n\tlog?: (line: string) => void;\n\t/** Where the GoDaddy provider reads its key: the environment and the CLI's home. */\n\tcredentials?: GoDaddyProviderOptions;\n\t/** The Hostinger token, when the caller already has it. */\n\thostinger?: HostingerCredential;\n\t/** The provider for a domain — `createDnsProvider` by default. */\n\tproviderFor?: (config: DnsProviderConfig) => Promise<DnsProvider | null>;\n\t/**\n\t * Read every record written back from its provider, and throw\n\t * {@link DnsRecordsNotConfirmed} for one that does not hold its value.\n\t */\n\tconfirm?: boolean;\n}\n\n/** What applying a plan did, and what of it the providers confirmed. */\nexport interface StackDnsApplied {\n\t/** Every change, the unchanged included; a dry run makes none of them. */\n\tchanges: DnsChange[];\n\t/**\n\t * Hosts whose every record the provider holds with its value — read\n\t * before the run (unchanged) or after it wrote them (`confirm`).\n\t */\n\tconfirmed: string[];\n\t/**\n\t * Hosts no provider vouches for: a `manual` domain's, those under no\n\t * domain in `dns`, and those of a key that can write and not read.\n\t */\n\tunconfirmed: string[];\n}\n\n/** One record a provider did not hold with its value after it was written. */\nexport interface UnconfirmedRecord {\n\thost: string;\n\ttype: StackRecordType;\n\texpected: string;\n\t/** What the provider read back — empty when the record is not there. */\n\tfound: string[];\n}\n\n/** Records a provider accepted and then did not read back with their value. */\nexport class DnsRecordsNotConfirmed extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly domain: string,\n\t\treadonly provider: string,\n\t\treadonly records: readonly UnconfirmedRecord[],\n\t) {\n\t\tconst lines = records.map(\n\t\t\t(r) =>\n\t\t\t\t` - ${r.host} ${r.type}: ${r.found.length > 0 ? r.found.join(', ') : 'nothing'}, expected ${r.expected}`,\n\t\t);\n\t\tsuper(\n\t\t\t`${provider} accepted '${stage}''s records for ${domain}, and reading them ` +\n\t\t\t\t`back does not show them:\\n${lines.join('\\n')}\\n` +\n\t\t\t\t\"Deploy again; if it persists, check the records in the provider's \" +\n\t\t\t\t'console — another tool may be writing the same names.',\n\t\t);\n\t\tthis.name = 'DnsRecordsNotConfirmed';\n\t}\n}\n\n/** `api.example.com A 203.0.113.10 (TTL 600)` */\nfunction describe(record: PlannedDnsRecord): string {\n\treturn `${record.host.padEnd(32)} ${record.type.padEnd(5)} ${record.value} (TTL ${record.ttl})`;\n}\n\nfunction printManual(\n\tplan: DomainDnsPlan,\n\tlog: (line: string) => void,\n\twhy: string,\n): DnsChange[] {\n\tlog(` ${plan.domain}: ${why} — create these records at its DNS host:`);\n\tfor (const record of plan.records) log(` ${describe(record)}`);\n\treturn plan.records.map((r) => ({\n\t\tdomain: r.domain,\n\t\tname: r.name,\n\t\ttype: r.type,\n\t\taction: 'manual',\n\t\tvalue: r.value,\n\t\tttl: r.ttl,\n\t}));\n}\n\n/**\n * The existing records of every planned name: A, AAAA and CNAME where one of\n * them is planned — what the name points at, and what a change of mode\n * deletes — and MX where an MX is. No other type is read.\n */\nasync function existingRecords(\n\tprovider: DnsProvider,\n\tplan: DomainDnsPlan,\n): Promise<DnsRecord[]> {\n\tconst wanted = new Map<string, { name: string; type: StackRecordType }>();\n\tfor (const record of plan.records) {\n\t\tconst types = ADDRESS_TYPES.includes(record.type)\n\t\t\t? ADDRESS_TYPES\n\t\t\t: [record.type];\n\t\tfor (const type of types) {\n\t\t\twanted.set(`${record.name} ${type}`, { name: record.name, type });\n\t\t}\n\t}\n\treturn readRecords(provider, plan.domain, [...wanted.values()]);\n}\n\n/** Exactly these names and types, as the provider holds them. */\nasync function readRecords(\n\tprovider: DnsProvider,\n\tdomain: string,\n\twanted: readonly { name: string; type: StackRecordType }[],\n): Promise<DnsRecord[]> {\n\tif (provider.readRecords) return provider.readRecords(domain, wanted);\n\tconst all = await provider.getRecords(domain);\n\treturn all.filter((r) =>\n\t\twanted.some((w) => w.name === r.name && w.type === r.type),\n\t);\n}\n\n/** The provider for a domain's config: `providerFor`, or the real one. */\nfunction providerResolver(\n\toptions: Pick<\n\t\tApplyStackDnsOptions,\n\t\t'providerFor' | 'credentials' | 'hostinger'\n\t>,\n): (config: DnsProviderConfig) => Promise<DnsProvider | null> {\n\treturn (\n\t\toptions.providerFor ??\n\t\t((config: DnsProviderConfig) =>\n\t\t\tcreateDnsProvider({\n\t\t\t\tconfig: config as SchemaDnsConfig,\n\t\t\t\t...(options.credentials ? { godaddy: options.credentials } : {}),\n\t\t\t\t...(options.hostinger ? { hostinger: options.hostinger } : {}),\n\t\t\t}))\n\t);\n}\n\n/** Two values compared as DNS does: case, a trailing dot and spacing aside. */\nconst same = (a: string, b: string) => {\n\tconst normalize = (value: string) =>\n\t\tvalue.trim().replace(/\\.$/, '').replace(/\\s+/g, ' ').toLowerCase();\n\treturn normalize(a) === normalize(b);\n};\n\n/**\n * What each domain's records need, compared with what is there: creates,\n * updates, and the deletes a change of mode needs — a name moving from an A\n * record to a CNAME, or back, cannot hold both. Nothing else is deleted: an\n * MX planned at a name deletes nothing, and a CNAME or A planned at a name\n * never deletes its MX.\n */\nexport function diffDomainDns(\n\tplan: DomainDnsPlan,\n\texisting: readonly DnsRecord[],\n): DnsChange[] {\n\tconst changes: DnsChange[] = [];\n\tconst find = (name: string, type: string) =>\n\t\texisting.find((r) => r.name === name && r.type === type);\n\n\tconst planned = new Map<string, Set<StackRecordType>>();\n\tfor (const record of plan.records) {\n\t\tconst types = planned.get(record.name) ?? new Set();\n\t\ttypes.add(record.type);\n\t\tplanned.set(record.name, types);\n\t}\n\n\t// The deletes first: a CNAME where an A record goes, A and AAAA where a\n\t// CNAME goes.\n\tfor (const [name, types] of planned) {\n\t\tconst conflicting: StackRecordType[] = types.has('CNAME')\n\t\t\t? ['A', 'AAAA']\n\t\t\t: types.has('A') || types.has('AAAA')\n\t\t\t\t? ['CNAME']\n\t\t\t\t: [];\n\t\tfor (const type of conflicting) {\n\t\t\tconst found = find(name, type);\n\t\t\tif (!found || found.values.length === 0) continue;\n\t\t\tchanges.push({\n\t\t\t\tdomain: plan.domain,\n\t\t\t\tname,\n\t\t\t\ttype,\n\t\t\t\taction: 'delete',\n\t\t\t\tprevious: found.values.join(', '),\n\t\t\t});\n\t\t}\n\t}\n\n\tfor (const record of plan.records) {\n\t\tconst found = find(record.name, record.type);\n\t\tconst base = {\n\t\t\tdomain: plan.domain,\n\t\t\tname: record.name,\n\t\t\ttype: record.type,\n\t\t\tvalue: record.value,\n\t\t\tttl: record.ttl,\n\t\t};\n\t\tif (!found || found.values.length === 0) {\n\t\t\tchanges.push({ ...base, action: 'create' });\n\t\t} else if (\n\t\t\tfound.values.length === 1 &&\n\t\t\tsame(found.values[0]!, record.value)\n\t\t) {\n\t\t\tchanges.push({ ...base, action: 'unchanged' });\n\t\t} else {\n\t\t\tchanges.push({\n\t\t\t\t...base,\n\t\t\t\taction: 'update',\n\t\t\t\tprevious: found.values.join(', '),\n\t\t\t});\n\t\t}\n\t}\n\treturn changes;\n}\n\n/** A host's full name from a domain and a relative name. */\nfunction fullName(domain: string, name: string): string {\n\treturn name === '@' ? domain : `${name}.${domain}`;\n}\n\nfunction printChange(\n\tchange: DnsChange,\n\tdryRun: boolean,\n\tlog: (line: string) => void,\n) {\n\tconst host = fullName(change.domain, change.name).padEnd(32);\n\tconst type = change.type.padEnd(5);\n\tconst would = dryRun ? 'would ' : '';\n\tswitch (change.action) {\n\t\tcase 'unchanged':\n\t\t\tlog(\n\t\t\t\t` ✓ ${host} ${type} ${change.value} (TTL ${change.ttl}) — up to date`,\n\t\t\t);\n\t\t\tbreak;\n\t\tcase 'create':\n\t\t\tlog(\n\t\t\t\t` + ${host} ${type} ${change.value} (TTL ${change.ttl}) — ${would}create`,\n\t\t\t);\n\t\t\tbreak;\n\t\tcase 'update':\n\t\t\tlog(\n\t\t\t\t` ~ ${host} ${type} ${change.previous} → ${change.value} (TTL ${change.ttl}) — ${would}update`,\n\t\t\t);\n\t\t\tbreak;\n\t\tcase 'write':\n\t\t\tlog(\n\t\t\t\tdryRun\n\t\t\t\t\t? ` ? ${host} ${type} ${change.value} (TTL ${change.ttl}) — would write; current value unknown (key cannot read DNS)`\n\t\t\t\t\t: ` ! ${host} ${type} ${change.value} (TTL ${change.ttl}) — written (not diffed)`,\n\t\t\t);\n\t\t\tbreak;\n\t\tcase 'delete':\n\t\t\tlog(\n\t\t\t\t` - ${host} ${type} ${change.previous} — ${would}delete (a name cannot hold a CNAME and an A record)`,\n\t\t\t);\n\t\t\tbreak;\n\t}\n}\n\n/**\n * Each domain's records, through its provider. Returns every change, the\n * unchanged included; a dry run makes none of them.\n */\nexport async function applyStackDns(\n\tplan: StackDnsPlan,\n\toptions: ApplyStackDnsOptions = {},\n): Promise<DnsChange[]> {\n\treturn (await settleStackDns(plan, options)).changes;\n}\n\n/**\n * Each domain's records, through its provider — and, with `confirm`, what was\n * written read back from it. A record already holding its value is neither\n * written nor read again.\n *\n * @throws {DnsRecordsNotConfirmed} when a written record does not read back\n */\nexport async function settleStackDns(\n\tplan: StackDnsPlan,\n\toptions: ApplyStackDnsOptions = {},\n): Promise<StackDnsApplied> {\n\tconst dryRun = options.dryRun === true;\n\tconst log = options.log ?? ((line: string) => console.log(line));\n\tconst providerFor = providerResolver(options);\n\n\tconst changes: DnsChange[] = [];\n\tconst confirmed = new Set<string>();\n\tconst unconfirmed = new Set<string>();\n\tconst hostsOf = (domain: DomainDnsPlan) =>\n\t\tnew Set(domain.records.map((r) => r.host));\n\tfor (const host of plan.uncovered) {\n\t\tlog(\n\t\t\t` ⚠ ${host} is under no domain in dns — point it at ${plan.server.ipv4} yourself`,\n\t\t);\n\t}\n\n\tfor (const domain of plan.domains) {\n\t\tif (domain.provider === 'manual') {\n\t\t\tchanges.push(...printManual(domain, log, 'manual'));\n\t\t\tfor (const host of hostsOf(domain)) unconfirmed.add(host);\n\t\t\tcontinue;\n\t\t}\n\t\tconst provider = await providerFor(domain.config);\n\t\tif (!provider) {\n\t\t\tchanges.push(...printManual(domain, log, 'manual'));\n\t\t\tfor (const host of hostsOf(domain)) unconfirmed.add(host);\n\t\t\tcontinue;\n\t\t}\n\n\t\tlog(` ${domain.domain} (${provider.name})${dryRun ? ' — dry run' : ''}`);\n\t\tlet existing: DnsRecord[];\n\t\tlet diff: DnsChange[];\n\t\tlet unreadable = false;\n\t\ttry {\n\t\t\texisting = await existingRecords(provider, domain);\n\t\t\tdiff = diffDomainDns(domain, existing);\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof DnsRecordsUnreadable)) throw error;\n\t\t\tlog(\n\t\t\t\t` ℹ The ${provider.name} key cannot read ${domain.domain}'s DNS records, so changes cannot be diffed: every record is written (idempotent).`,\n\t\t\t);\n\t\t\tunreadable = true;\n\t\t\texisting = [];\n\t\t\tdiff = domain.records.map((r) => ({\n\t\t\t\tdomain: r.domain,\n\t\t\t\tname: r.name,\n\t\t\t\ttype: r.type,\n\t\t\t\taction: 'write' as const,\n\t\t\t\tvalue: r.value,\n\t\t\t\tttl: r.ttl,\n\t\t\t}));\n\t\t}\n\t\tfor (const change of diff) printChange(change, dryRun, log);\n\n\t\t// An AAAA nobody planned, at a name that points here: IPv6 clients —\n\t\t// Let's Encrypt among them — would go somewhere else.\n\t\tif (!plan.server.ipv6) {\n\t\t\tfor (const name of new Set(domain.records.map((r) => r.name))) {\n\t\t\t\tconst aaaa = existing.find((r) => r.name === name && r.type === 'AAAA');\n\t\t\t\tconst planned = domain.records.find(\n\t\t\t\t\t(r) => r.name === name && r.type === 'A',\n\t\t\t\t);\n\t\t\t\tif (aaaa && planned && aaaa.values.length > 0) {\n\t\t\t\t\tlog(\n\t\t\t\t\t\t` ⚠ ${fullName(domain.domain, name)} also has AAAA ${aaaa.values.join(', ')}: ` +\n\t\t\t\t\t\t\t`set ${SERVER_IPV6_KEY} in the '${plan.stage}' stage's secrets to the server's IPv6 address, ` +\n\t\t\t\t\t\t\t'or remove that record, or IPv6 clients go elsewhere',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tchanges.push(...diff);\n\n\t\t// A host every one of whose records was already right is confirmed by\n\t\t// the read that found it so; one with a write is confirmed by reading\n\t\t// it back — or, with a key that cannot read, by nobody.\n\t\tconst written = new Set(\n\t\t\tdiff\n\t\t\t\t.filter((c) => c.action !== 'unchanged')\n\t\t\t\t.map((c) => fullName(c.domain, c.name)),\n\t\t);\n\t\tfor (const host of hostsOf(domain)) {\n\t\t\t// A dry run writes nothing, so nothing it would write is resolved:\n\t\t\t// a name looked up before its record exists is cached as missing.\n\t\t\tif (unreadable) {\n\t\t\t\tif (!dryRun) unconfirmed.add(host);\n\t\t\t} else if (!written.has(host)) confirmed.add(host);\n\t\t}\n\t\tif (dryRun) continue;\n\n\t\tconst deletes = diff.filter((c) => c.action === 'delete');\n\t\tif (deletes.length > 0) {\n\t\t\tawait provider.deleteRecords(\n\t\t\t\tdomain.domain,\n\t\t\t\tdeletes.map((c) => ({ name: c.name, type: c.type })),\n\t\t\t);\n\t\t}\n\t\tconst writes = diff.filter(\n\t\t\t(c) =>\n\t\t\t\tc.action === 'create' || c.action === 'update' || c.action === 'write',\n\t\t);\n\t\tif (writes.length > 0) {\n\t\t\tawait provider.upsertRecords(\n\t\t\t\tdomain.domain,\n\t\t\t\twrites.map((c) => ({\n\t\t\t\t\tname: c.name,\n\t\t\t\t\ttype: c.type,\n\t\t\t\t\tvalue: c.value!,\n\t\t\t\t\tttl: c.ttl!,\n\t\t\t\t})),\n\t\t\t);\n\t\t}\n\n\t\tif (!options.confirm || unreadable || written.size === 0) continue;\n\t\tconst rewritten = {\n\t\t\t...domain,\n\t\t\trecords: domain.records.filter((r) => written.has(r.host)),\n\t\t};\n\t\tconst after = await existingRecords(provider, rewritten);\n\t\tconst missing: UnconfirmedRecord[] = [];\n\t\tfor (const record of rewritten.records) {\n\t\t\tconst found = after.find(\n\t\t\t\t(r) => r.name === record.name && r.type === record.type,\n\t\t\t);\n\t\t\tconst values = found?.values ?? [];\n\t\t\tif (values.length !== 1 || !same(values[0]!, record.value)) {\n\t\t\t\tmissing.push({\n\t\t\t\t\thost: record.host,\n\t\t\t\t\ttype: record.type,\n\t\t\t\t\texpected: record.value,\n\t\t\t\t\tfound: values,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tif (missing.length > 0) {\n\t\t\tthrow new DnsRecordsNotConfirmed(\n\t\t\t\tplan.stage,\n\t\t\t\tdomain.domain,\n\t\t\t\tprovider.name,\n\t\t\t\tmissing,\n\t\t\t);\n\t\t}\n\t\tfor (const host of written) confirmed.add(host);\n\t\tlog(\n\t\t\t` ✓ ${written.size} host${written.size === 1 ? '' : 's'} read back from ${provider.name}`,\n\t\t);\n\t}\n\tfor (const host of plan.uncovered) unconfirmed.add(host);\n\treturn {\n\t\tchanges,\n\t\tconfirmed: [...confirmed].sort(),\n\t\tunconfirmed: [...unconfirmed].filter((h) => !confirmed.has(h)).sort(),\n\t};\n}\n\n// ============================================================================\n// What gkm wrote before: the diff and the prune\n// ============================================================================\n\n/** A record gkm wrote for the stage, as its state keeps it. */\nexport type RecordedDnsRecord = DnsResourceRecord & { fqdn: string };\n\n/** The plan against the records the stage's state says gkm wrote. */\nexport interface RecordedDnsDiff {\n\t/** Planned, and never written by gkm for the stage. */\n\tadded: PlannedDnsRecord[];\n\t/** Planned, and written by gkm before — at this value or another. */\n\tkept: PlannedDnsRecord[];\n\t/** Written by gkm before, and no longer planned. */\n\tstale: RecordedDnsRecord[];\n}\n\n/** `api.example.com A` — a record's identity, whatever its value. */\nconst recordKey = (fqdn: string, type: string) =>\n\t`${fqdn.trim().replace(/\\.$/, '').toLowerCase()} ${type.toUpperCase()}`;\n\n/**\n * The plan against the records gkm wrote for the stage — pure. A record is\n * its full name and its type: one the plan has at another value is kept (the\n * apply updates it), and one whose name or type the plan no longer has is\n * stale — a host the stage stopped serving when its domain or an app changed,\n * or an AAAA once its server has no IPv6 address.\n */\nexport function diffRecordedDns(\n\tplan: StackDnsPlan,\n\trecorded: readonly RecordedDnsRecord[],\n): RecordedDnsDiff {\n\tconst planned = plan.domains.flatMap((domain) => domain.records);\n\tconst wanted = new Set(planned.map((r) => recordKey(r.host, r.type)));\n\tconst written = new Set(recorded.map((r) => recordKey(r.fqdn, r.type)));\n\treturn {\n\t\tadded: planned.filter((r) => !written.has(recordKey(r.host, r.type))),\n\t\tkept: planned.filter((r) => written.has(recordKey(r.host, r.type))),\n\t\tstale: recorded.filter((r) => !wanted.has(recordKey(r.fqdn, r.type))),\n\t};\n}\n\n/** What the prune did with one stale record — or, in a dry run, would. */\nexport interface PrunedDnsRecord {\n\trecord: RecordedDnsRecord;\n\t/**\n\t * - `delete`: it still held the value gkm wrote, and is deleted\n\t * - `gone`: the provider no longer has it\n\t * - `changed`: it was pointed elsewhere since, and is left as it is\n\t * - `manual`: no provider gkm can use deletes it — printed for a person\n\t *\n\t * Each is forgotten from the stage's state: none is gkm's any more.\n\t */\n\taction: 'delete' | 'gone' | 'changed' | 'manual';\n\t/** What the provider holds, for `changed`. */\n\tfound?: string[];\n}\n\nexport interface PruneStackDnsOptions\n\textends Pick<\n\t\tApplyStackDnsOptions,\n\t\t'dryRun' | 'log' | 'credentials' | 'hostinger' | 'providerFor'\n\t> {\n\tstage: string;\n\tdns: WorkspaceDnsConfig | undefined;\n}\n\n/**\n * Each stale record deleted through its domain's provider — only where the\n * provider still holds exactly the value gkm wrote, so a name someone has\n * since pointed elsewhere is never taken from them. Where no provider can\n * read and delete it — a `manual` domain, one gone from `dns`, a key that\n * can only write — it is printed for a person to remove. A dry run reads\n * and prints, and deletes nothing.\n */\nexport async function pruneStackDns(\n\tstale: readonly RecordedDnsRecord[],\n\toptions: PruneStackDnsOptions,\n): Promise<PrunedDnsRecord[]> {\n\tif (stale.length === 0) return [];\n\tconst dryRun = options.dryRun === true;\n\tconst log = options.log ?? ((line: string) => console.log(line));\n\tconst providerFor = providerResolver(options);\n\tconst dns = options.dns ? normalizeDnsConfig(options.dns) : {};\n\n\tconst byDomain = new Map<string, RecordedDnsRecord[]>();\n\tfor (const record of stale) {\n\t\tbyDomain.set(record.domain, [\n\t\t\t...(byDomain.get(record.domain) ?? []),\n\t\t\trecord,\n\t\t]);\n\t}\n\n\tlog(` No longer served by '${options.stage}':`);\n\tconst pruned: PrunedDnsRecord[] = [];\n\tconst byHand = (\n\t\tdomain: string,\n\t\trecords: RecordedDnsRecord[],\n\t\twhy: string,\n\t) => {\n\t\tlog(` ${domain}: ${why} — remove these records at its DNS host:`);\n\t\tfor (const record of records) {\n\t\t\tlog(\n\t\t\t\t` ${record.fqdn.padEnd(32)} ${record.type.padEnd(5)} ${record.value}`,\n\t\t\t);\n\t\t\tpruned.push({ record, action: 'manual' });\n\t\t}\n\t};\n\n\tfor (const [domain, records] of byDomain) {\n\t\tconst config = dns[domain];\n\t\tif (!config) {\n\t\t\tbyHand(domain, records, 'no longer in dns');\n\t\t\tcontinue;\n\t\t}\n\t\tconst provider =\n\t\t\tproviderName(config) === 'manual' ? null : await providerFor(config);\n\t\tif (!provider) {\n\t\t\tbyHand(domain, records, 'manual');\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet existing: DnsRecord[];\n\t\ttry {\n\t\t\texisting = await readRecords(\n\t\t\t\tprovider,\n\t\t\t\tdomain,\n\t\t\t\trecords.map((r) => ({ name: r.name, type: r.type as StackRecordType })),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof DnsRecordsUnreadable)) throw error;\n\t\t\tbyHand(\n\t\t\t\tdomain,\n\t\t\t\trecords,\n\t\t\t\t`the ${provider.name} key cannot read its records, so none is deleted unchecked`,\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst would = dryRun ? 'would ' : '';\n\t\tconst deletes: PrunedDnsRecord[] = [];\n\t\tfor (const record of records) {\n\t\t\tconst host = record.fqdn.padEnd(32);\n\t\t\tconst type = record.type.padEnd(5);\n\t\t\tconst found =\n\t\t\t\texisting.find((r) => r.name === record.name && r.type === record.type)\n\t\t\t\t\t?.values ?? [];\n\t\t\tif (found.length === 0) {\n\t\t\t\tlog(` · ${host} ${type} already gone`);\n\t\t\t\tpruned.push({ record, action: 'gone' });\n\t\t\t} else if (found.length === 1 && same(found[0]!, record.value)) {\n\t\t\t\tlog(` - ${host} ${type} ${record.value} — ${would}delete`);\n\t\t\t\tdeletes.push({ record, action: 'delete' });\n\t\t\t} else {\n\t\t\t\tlog(\n\t\t\t\t\t` ⚠ ${host} ${type} ${found.join(', ')} — pointed elsewhere since gkm wrote ${record.value}; left as it is`,\n\t\t\t\t);\n\t\t\t\tpruned.push({ record, action: 'changed', found });\n\t\t\t}\n\t\t}\n\t\tif (!dryRun && deletes.length > 0) {\n\t\t\tawait provider.deleteRecords(\n\t\t\t\tdomain,\n\t\t\t\tdeletes.map(({ record }) => ({\n\t\t\t\t\tname: record.name,\n\t\t\t\t\ttype: record.type as StackRecordType,\n\t\t\t\t})),\n\t\t\t);\n\t\t}\n\t\tpruned.push(...deletes);\n\t}\n\treturn pruned;\n}\n\n// ============================================================================\n// The check\n// ============================================================================\n\n/** Resolves a host to every address it has — `dns.promises.lookup`, `all`. */\nexport type HostLookup = (host: string) => Promise<string[]>;\n\n/** The system resolver: what the server's own clients would be told. */\nexport const systemLookup: HostLookup = async (host) => {\n\tconst found = await dnsLookup(host, { all: true });\n\treturn found.map((a) => a.address);\n};\n\n/** One host that does not resolve to the server. */\nexport interface MisdirectedHost {\n\thost: string;\n\t/** What it resolves to — empty when it does not resolve. */\n\tresolved: string[];\n\t/** Why it did not resolve, when it did not. */\n\terror?: string;\n}\n\n/** Hosts that do not resolve to the stage's server. */\nexport class HostNotPointingAtServer extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly hosts: readonly MisdirectedHost[],\n\t\treadonly expected: { ipv4: string; ipv6?: string },\n\t\t/** The records to create, where `dns` covers none of them. */\n\t\treadonly fix: string,\n\t) {\n\t\tconst want = expected.ipv6\n\t\t\t? `${expected.ipv4} (and ${expected.ipv6})`\n\t\t\t: expected.ipv4;\n\t\tconst lines = hosts.map(\n\t\t\t(h) =>\n\t\t\t\t` - ${h.host} → ${h.resolved.length > 0 ? h.resolved.join(', ') : `nothing${h.error ? ` (${h.error})` : ''}`}, expected ${want}`,\n\t\t);\n\t\tsuper(\n\t\t\t`${hosts.length === 1 ? 'A host' : `${hosts.length} hosts`} of '${stage}' ` +\n\t\t\t\t`do${hosts.length === 1 ? 'es' : ''} not resolve to its server, so a ` +\n\t\t\t\t`certificate for ${hosts.length === 1 ? 'it' : 'them'} cannot be issued:\\n` +\n\t\t\t\t`${lines.join('\\n')}\\n${fix}\\n` +\n\t\t\t\t'Records can take a few minutes to propagate. With a CDN or proxy in ' +\n\t\t\t\t'front of the server, pass --skip-dns.',\n\t\t);\n\t\tthis.name = 'HostNotPointingAtServer';\n\t}\n}\n\nexport interface CheckStackDnsInput {\n\tstage: string;\n\thosts: readonly string[];\n\tserver: ServerAddress;\n\tdns: WorkspaceDnsConfig | undefined;\n\tlookup?: HostLookup;\n}\n\n/**\n * The name a wildcard record is resolved through: one label no app takes,\n * which only the `*` record answers.\n */\nexport const WILDCARD_PROBE = 'gkm-wildcard-check';\n\n/**\n * Every host resolved: each must resolve to the server's IPv4 address and to\n * nothing but the server's addresses.\n *\n * @throws {HostNotPointingAtServer} naming every host that does not\n */\nexport async function checkStackDns(\n\tinput: CheckStackDnsInput,\n): Promise<string[]> {\n\tconst lookup = input.lookup ?? systemLookup;\n\tconst { server } = input;\n\tconst ours = new Set(\n\t\t[server.ipv4, server.ipv6].filter(Boolean).map((a) => a!.toLowerCase()),\n\t);\n\tconst bad: MisdirectedHost[] = [];\n\tconst ok: string[] = [];\n\tfor (const host of input.hosts) {\n\t\tlet resolved: string[];\n\t\tconst asked = host.startsWith('*.')\n\t\t\t? `${WILDCARD_PROBE}.${host.slice(2)}`\n\t\t\t: host;\n\t\ttry {\n\t\t\tresolved = [...new Set(await lookup(asked))];\n\t\t} catch (error) {\n\t\t\tconst code =\n\t\t\t\terror && typeof error === 'object' && 'code' in error\n\t\t\t\t\t? String((error as { code: unknown }).code)\n\t\t\t\t\t: error instanceof Error\n\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t: String(error);\n\t\t\tbad.push({ host, resolved: [], error: code });\n\t\t\tcontinue;\n\t\t}\n\t\tconst pointsHere =\n\t\t\tresolved.some((a) => a.toLowerCase() === server.ipv4.toLowerCase()) &&\n\t\t\tresolved.every((a) => ours.has(a.toLowerCase()));\n\t\tif (pointsHere) ok.push(host);\n\t\telse bad.push({ host, resolved });\n\t}\n\n\tif (bad.length > 0) {\n\t\tthrow new HostNotPointingAtServer(\n\t\t\tinput.stage,\n\t\t\tbad,\n\t\t\t{ ipv4: server.ipv4, ...(server.ipv6 ? { ipv6: server.ipv6 } : {}) },\n\t\t\tdnsFix(input, bad),\n\t\t);\n\t}\n\treturn ok;\n}\n\n/** How to fix it: the deploy, or the records to create by hand. */\nfunction dnsFix(input: CheckStackDnsInput, bad: readonly MisdirectedHost[]) {\n\tconst hosts = bad.map((h) => h.host);\n\tlet plan: StackDnsPlan;\n\ttry {\n\t\tplan = planStackDns({\n\t\t\tstage: input.stage,\n\t\t\thosts,\n\t\t\tserver: input.server,\n\t\t\tdns: input.dns,\n\t\t});\n\t} catch {\n\t\tplan = {\n\t\t\tstage: input.stage,\n\t\t\tserver: input.server,\n\t\t\tdomains: [],\n\t\t\tuncovered: hosts,\n\t\t};\n\t}\n\tconst automatic = plan.domains.filter((d) => d.provider !== 'manual');\n\tconst byHand = [\n\t\t...plan.domains\n\t\t\t.filter((d) => d.provider === 'manual')\n\t\t\t.flatMap((d) => d.records.map(describe)),\n\t\t...plan.uncovered.flatMap((host) => [\n\t\t\t`${host.padEnd(32)} A ${input.server.ipv4}`,\n\t\t\t...(input.server.ipv6\n\t\t\t\t? [`${host.padEnd(32)} AAAA ${input.server.ipv6}`]\n\t\t\t\t: []),\n\t\t]),\n\t];\n\tconst lines: string[] = [];\n\tif (automatic.length > 0) {\n\t\tlines.push(\n\t\t\t`Fix: gkm deploy --stage ${input.stage} writes the records for ${automatic.map((d) => d.domain).join(', ')} through their provider (--dry-run shows them first).`,\n\t\t);\n\t}\n\tif (byHand.length > 0) {\n\t\tlines.push(\n\t\t\t`${automatic.length > 0 ? 'And create' : 'Fix: create'} these records at the DNS host:`,\n\t\t\t...byHand.map((line) => ` ${line}`),\n\t\t);\n\t}\n\treturn lines.join('\\n');\n}\n\n// ============================================================================\n// The step: plan, apply, confirm, check\n// ============================================================================\n\n/** The environment variable each token-authenticated provider reads. */\nexport const DNS_TOKEN_KEYS = {\n\tgodaddy: 'GODADDY_API_TOKEN',\n\thostinger: 'HOSTINGER_API_TOKEN',\n} as const;\n\n/** A provider whose credential is a token gkm reads. */\nexport type TokenDnsProvider = keyof typeof DNS_TOKEN_KEYS;\n\n/** The tokens a stage's records are written with. */\nexport interface DnsCredentials {\n\tgodaddy?: GoDaddyCredential;\n\thostinger?: HostingerCredential;\n}\n\n/**\n * A domain whose records the deploy writes, and no token to write them with.\n * Raised before anything is built, started or written.\n */\nexport class DnsCredentialMissing extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly domain: string,\n\t\treadonly provider: TokenDnsProvider,\n\t\t/** The variable the token is read from: `GODADDY_API_TOKEN`. */\n\t\treadonly key: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${stage}''s hosts are under ${domain}, whose DNS is ${provider}'s, and ` +\n\t\t\t\t`the deploy writes their records — but ${key} is not set. In CI, add ` +\n\t\t\t\t`${key} as a secret on the '${stage}' GitHub environment and pass it ` +\n\t\t\t\t`to the step that writes the records: env: { ${key}: \\${{ secrets.${key} }} }. ` +\n\t\t\t\t`On this machine, export ${key} or run gkm login --provider ${provider}. ` +\n\t\t\t\t'With a CDN or proxy in front of the server, pass --skip-dns.',\n\t\t);\n\t\tthis.name = 'DnsCredentialMissing';\n\t}\n}\n\n/** One `dns` domain and its provider's config. */\nexport interface DnsDomain {\n\tdomain: string;\n\tconfig: DnsProviderConfig;\n}\n\n/**\n * The `dns` domain a stage's own domain (`domains.<stage>`) is under — where\n * its hosts' records go — or none.\n */\nexport function stageDnsDomains(\n\tstage: string,\n\tdomains: Readonly<Record<string, string>> | undefined,\n\tdns: WorkspaceDnsConfig | undefined,\n): DnsDomain[] {\n\tconst own = domains?.[stage];\n\tif (!own || !dns || isLocalHost(own)) return [];\n\tconst normalized = normalizeDnsConfig(dns);\n\tconst root = findRootDomain(own.toLowerCase(), normalized);\n\treturn root ? [{ domain: root, config: normalized[root]! }] : [];\n}\n\n/**\n * Each token the domains' providers need, from `credentials` — `manual`,\n * Route53 (the AWS SDK's own chain) and a provider object need none.\n *\n * @throws {DnsCredentialMissing} naming the first domain with no token\n */\nexport async function dnsCredentials(\n\tstage: string,\n\tdomains: readonly DnsDomain[],\n\tcredentials: CredentialProvider,\n): Promise<DnsCredentials> {\n\tconst found: DnsCredentials = {};\n\tfor (const { domain, config } of domains) {\n\t\tconst provider = config.provider;\n\t\tif (provider !== 'godaddy' && provider !== 'hostinger') continue;\n\t\tif (found[provider]) continue;\n\t\tconst token = await credentials.get({ kind: provider });\n\t\tif (!token?.token) {\n\t\t\tthrow new DnsCredentialMissing(\n\t\t\t\tstage,\n\t\t\t\tdomain,\n\t\t\t\tprovider,\n\t\t\t\tDNS_TOKEN_KEYS[provider],\n\t\t\t);\n\t\t}\n\t\tfound[provider] = token;\n\t}\n\treturn found;\n}\n\nexport interface StageDnsInput {\n\tstage: string;\n\t/** The stage's public hosts, read off its stack. */\n\thosts: readonly string[];\n\tserver: ServerAddress;\n\tdns: WorkspaceDnsConfig | undefined;\n\t/** Where the providers' tokens come from. */\n\tcredentials: CredentialProvider;\n\tdryRun?: boolean;\n\tlog?: (line: string) => void;\n\t/** Resolves the hosts no provider confirmed — the system resolver by default. */\n\tlookup?: HostLookup;\n\t/** The provider for a domain — `createDnsProvider` by default. */\n\tproviderFor?: (config: DnsProviderConfig) => Promise<DnsProvider | null>;\n\t/** GoDaddy's API, for tests: its base URL and how a 429 is waited out. */\n\tgodaddy?: Pick<GoDaddyProviderOptions, 'baseUrl' | 'sleep' | 'maxAttempts'>;\n\t/** The records the stage's state says gkm wrote: the stale ones are pruned. */\n\trecorded?: readonly RecordedDnsRecord[];\n\t/** The stage's wildcard site's `*.<domain>`, the one wildcard written. */\n\twildcard?: string;\n}\n\nexport interface StageDnsResult {\n\tplan: StackDnsPlan;\n\tchanges: DnsChange[];\n\t/** Hosts whose records their provider holds with the server's address. */\n\tconfirmed: string[];\n\t/** Hosts the system resolver found pointing at the server. */\n\tresolved: string[];\n\t/** The plan against the records gkm wrote for the stage before. */\n\trecorded: RecordedDnsDiff;\n\t/**\n\t * The stale records pruned, through the providers this step used — called\n\t * once the stack serves its new hosts, so a run that stops short leaves\n\t * the old ones answering. In a dry run it reads and prints.\n\t */\n\tprune: () => Promise<PrunedDnsRecord[]>;\n}\n\n/**\n * A stage's DNS, as every deploy runs it: the\n * stage's own hosts planned, written through each domain's provider where\n * they differ, and read back from it — and each record gkm wrote for a host\n * the stage no longer serves found, for `prune` to delete. Only A, AAAA and CNAME records of those\n * names are touched; nothing is a wildcard but a wildcard site's\n * `*.<domain>`, and no other name is read,\n * written or deleted. What no provider confirms — a `manual` domain, a host\n * under no domain in `dns`, a key that cannot read — is resolved publicly.\n * A dry run prints the plan and writes nothing.\n *\n * @throws {DnsCredentialMissing} before anything is read or written\n * @throws {DnsRecordsNotConfirmed} when a written record does not read back\n * @throws {HostNotPointingAtServer} when a resolved host is not the server\n */\nexport async function stageDns(input: StageDnsInput): Promise<StageDnsResult> {\n\tconst { stage, server } = input;\n\tconst log = input.log ?? ((line: string) => console.log(line));\n\tconst plan = planStackDns({\n\t\tstage,\n\t\thosts: input.hosts,\n\t\tserver,\n\t\tdns: input.dns,\n\t\t...(input.wildcard ? { wildcard: input.wildcard } : {}),\n\t});\n\tconst recorded = diffRecordedDns(plan, input.recorded ?? []);\n\t// A stale record's domain needs its provider's token too — the stage's\n\t// old domain, after it moved to another.\n\tconst dns = input.dns ? normalizeDnsConfig(input.dns) : {};\n\tconst staleDomains = [...new Set(recorded.stale.map((r) => r.domain))]\n\t\t.filter(\n\t\t\t(domain) => dns[domain] && !plan.domains.some((d) => d.domain === domain),\n\t\t)\n\t\t.map((domain) => ({ domain, config: dns[domain]! }));\n\tconst tokens = await dnsCredentials(\n\t\tstage,\n\t\t[\n\t\t\t...plan.domains.map(({ domain, config }) => ({ domain, config })),\n\t\t\t...staleDomains,\n\t\t],\n\t\tinput.credentials,\n\t);\n\tconst providers = {\n\t\tlog,\n\t\tcredentials: {\n\t\t\t...(input.godaddy ?? {}),\n\t\t\t...(tokens.godaddy ? { credential: tokens.godaddy } : {}),\n\t\t\tlog,\n\t\t},\n\t\t...(tokens.hostinger ? { hostinger: tokens.hostinger } : {}),\n\t\t...(input.providerFor ? { providerFor: input.providerFor } : {}),\n\t};\n\t// No `dns` at all: nothing to write, and every host is the person's to\n\t// point — checked, without a line per host saying so.\n\tconst applied: StackDnsApplied = !input.dns\n\t\t? { changes: [], confirmed: [], unconfirmed: [...plan.uncovered] }\n\t\t: await settleStackDns(plan, {\n\t\t\t\t...(input.dryRun ? { dryRun: true } : { confirm: true }),\n\t\t\t\t...providers,\n\t\t\t});\n\n\t// A record the apply already deleted — a change of mode — is not pruned.\n\tconst deleted = new Set(\n\t\tapplied.changes\n\t\t\t.filter((c) => c.action === 'delete')\n\t\t\t.map((c) => recordKey(fullName(c.domain, c.name), c.type)),\n\t);\n\tconst stale = recorded.stale.filter(\n\t\t(r) => !deleted.has(recordKey(r.fqdn, r.type)),\n\t);\n\tconst prune = () =>\n\t\tpruneStackDns(stale, {\n\t\t\tstage,\n\t\t\tdns: input.dns,\n\t\t\t...(input.dryRun ? { dryRun: true } : {}),\n\t\t\t...providers,\n\t\t});\n\n\tlet resolved: string[] = [];\n\tif (applied.unconfirmed.length > 0) {\n\t\tresolved = await checkStackDns({\n\t\t\tstage,\n\t\t\thosts: applied.unconfirmed,\n\t\t\tserver,\n\t\t\tdns: input.dns,\n\t\t\t...(input.lookup ? { lookup: input.lookup } : {}),\n\t\t});\n\t}\n\treturn {\n\t\tplan,\n\t\tchanges: applied.changes,\n\t\tconfirmed: applied.confirmed,\n\t\tresolved,\n\t\trecorded,\n\t\tprune,\n\t};\n}\n","/**\n * The SNS subscriptions a deploy makes for the subscribers it pushes to, and\n * keeps: what both owners of them share.\n *\n * Against SNS itself a worker never subscribes — its credentials can only\n * confirm — so the deploy subscribes each pushed subscriber's route, records\n * the ARN in the stage's state, and hands the worker those ARNs as\n * `GKM_SNS_SUBSCRIPTIONS`. Two places make them: the `s3` provider, for a\n * bucket's subscribers (it created the topic), and the compose target, for a\n * topic whose connection string the stage set by hand. Both record them the\n * same way, so one confirmation pass and one read serve both.\n */\n\nimport type {\n\tHttpSubscriptionSpec,\n\tSNSConnection,\n} from '@geekmidas/events/sns';\nimport { GkmError } from '../errors';\nimport {\n\ttype AwsProvisioning,\n\tawsClientConfig,\n\tawsEndpoint,\n\tawsProvisioningCredentials,\n} from '../providers/aws.js';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\nimport type { ResourceInput, ResourceRecord } from './StateStore.js';\n\n/** The type every recorded subscription has in the stage's state. */\nexport const SUBSCRIPTION_TYPE = 'sns-subscription';\n\n/** The state key a subscriber's SNS subscription is recorded under. */\nexport const subscriptionKey = (worker: string, name: string) =>\n\t`${SUBSCRIPTION_TYPE}:${worker}/${name}`;\n\n/** One subscription, as the deploy made it. */\nexport interface RecordedSubscription {\n\tworker: string;\n\t/** The subscriber's export. */\n\tname: string;\n\ttopicArn: string;\n\tendpoint: string;\n\tdeadLetterQueueArn?: string;\n\t/** The `type` filter of a topic subscriber; absent for a bucket's. */\n\tevents?: readonly string[];\n\t/**\n\t * The stage secret whose connection string the subscription was made\n\t * with — a topic set by hand, whose credentials are its own. Absent for a\n\t * bucket's, made with the deploy's provisioning credentials.\n\t */\n\tconnectionKey?: string;\n\t/** SNS still waits for the worker to confirm it. */\n\tpending: boolean;\n}\n\n/** What a recorded subscription is written to the stage's state as. */\nexport function subscriptionResource(\n\tsubscription: RecordedSubscription,\n\tarn: string,\n): ResourceInput {\n\tconst { name, ...data } = subscription;\n\treturn {\n\t\tkey: subscriptionKey(subscription.worker, name),\n\t\ttype: SUBSCRIPTION_TYPE,\n\t\tid: arn,\n\t\tstatus: 'ready',\n\t\tdata: { ...data, ...(data.events ? { events: [...data.events] } : {}) },\n\t};\n}\n\n/** The subscription a record holds, as an endpoint to reconcile. */\nfunction specOf(record: ResourceRecord): HttpSubscriptionSpec {\n\tconst events = record.data?.events;\n\treturn {\n\t\tname: record.key.split('/').pop()!,\n\t\tendpoint: String(record.data?.endpoint),\n\t\t...(record.data?.deadLetterQueueArn\n\t\t\t? { deadLetterQueueArn: String(record.data.deadLetterQueueArn) }\n\t\t\t: {}),\n\t\t...(Array.isArray(events) ? { events: events.map(String) } : {}),\n\t};\n}\n\n/**\n * The subscriptions the deploy recorded, by worker and export — what each\n * worker is handed as `GKM_SNS_SUBSCRIPTIONS`.\n */\nexport function recordedPushSubscriptions(\n\tresources: Readonly<Record<string, ResourceRecord>> | undefined,\n): Record<string, Record<string, string>> {\n\tconst byWorker: Record<string, Record<string, string>> = {};\n\tfor (const record of Object.values(resources ?? {})) {\n\t\tif (record.type !== SUBSCRIPTION_TYPE || !record.id) continue;\n\t\tconst [worker, name] = record.key\n\t\t\t.slice(`${SUBSCRIPTION_TYPE}:`.length)\n\t\t\t.split('/');\n\t\tif (!worker || !name) continue;\n\t\tbyWorker[worker] = { ...byWorker[worker], [name]: record.id };\n\t}\n\treturn byWorker;\n}\n\n/** A topic connection string the deploy cannot sign with. */\nexport class TopicSubscriptionUnsigned extends GkmError {\n\tconstructor(readonly connectionKey: string) {\n\t\tsuper(\n\t\t\t`'${connectionKey}' carries no keys, and the deploy found no AWS ` +\n\t\t\t\t`credentials of its own to subscribe the worker's routes with. Put ` +\n\t\t\t\t`accessKeyId and secretAccessKey in it — keys allowed ` +\n\t\t\t\t`sns:Subscribe, sns:ListSubscriptionsByTopic, ` +\n\t\t\t\t`sns:GetSubscriptionAttributes, sns:SetSubscriptionAttributes and ` +\n\t\t\t\t`sns:Unsubscribe on the topic — or sign in with \\`gkm login\\`.`,\n\t\t);\n\t\tthis.name = 'TopicSubscriptionUnsigned';\n\t}\n}\n\n/**\n * A connection to the topic a stage's connection string names, signed with\n * its own keys — or, carrying none, the deploy's.\n *\n * The emulator the environment points the SDK at stands in for SNS, as it\n * does for every provider: a string with no `endpoint` is SNS itself.\n *\n * @throws {TopicSubscriptionUnsigned} with no keys from either\n */\nexport async function topicConnection(input: {\n\tconnectionKey: string;\n\tconnectionString: string;\n\tstage: string;\n\tenv: NodeJS.ProcessEnv;\n\thome?: string;\n}): Promise<SNSConnection> {\n\tconst { SNSConnection, snsUrl } = await import('@geekmidas/events/sns');\n\tconst { topicArn, region, endpoint } = snsUrl.parse(input.connectionString);\n\tconst params = new URL(input.connectionString).searchParams;\n\tconst accessKeyId = params.get('accessKeyId');\n\tconst secretAccessKey = params.get('secretAccessKey');\n\t// The topic's own region, read off its ARN where the string names none.\n\tconst where = region ?? topicArn.split(':')[3];\n\n\tlet credentials: SNSConnectionCredentials | undefined;\n\tif (accessKeyId && secretAccessKey) {\n\t\tconst sessionToken = params.get('sessionToken');\n\t\tcredentials = {\n\t\t\taccessKeyId,\n\t\t\tsecretAccessKey,\n\t\t\t...(sessionToken ? { sessionToken } : {}),\n\t\t};\n\t} else {\n\t\tconst provisioning = await awsProvisioningCredentials({\n\t\t\tstage: input.stage,\n\t\t\tenv: input.env,\n\t\t\t...(input.home ? { home: input.home } : {}),\n\t\t});\n\t\tif (!provisioning) throw new TopicSubscriptionUnsigned(input.connectionKey);\n\t\tcredentials = (await awsClientConfig(provisioning, where ?? 'us-east-1'))\n\t\t\t.credentials;\n\t}\n\n\tconst override = endpoint ?? awsEndpoint(input.env, 'SNS');\n\treturn new SNSConnection({\n\t\ttopicArn,\n\t\t...(where ? { region: where } : {}),\n\t\t...(override ? { endpoint: override } : {}),\n\t\t...(credentials ? { credentials } : {}),\n\t});\n}\n\ntype SNSConnectionCredentials = NonNullable<\n\tConstructorParameters<typeof SNSConnection>[0]['credentials']\n>;\n\n/** A subscription still waiting to be confirmed once its worker is up. */\nexport class PushSubscriptionsUnconfirmed extends GkmError {\n\tconstructor(readonly endpoints: readonly string[]) {\n\t\tsuper(\n\t\t\t`SNS still waits for ${endpoints.join(', ')} to confirm ${endpoints.length === 1 ? 'its subscription' : 'their subscriptions'}, ` +\n\t\t\t\t`so nothing is pushed there yet. Check the worker's logs for the ` +\n\t\t\t\t`confirmation it refused, and that its host answers from the internet; ` +\n\t\t\t\t`the next deploy sends the confirmation again.`,\n\t\t);\n\t\tthis.name = 'PushSubscriptionsUnconfirmed';\n\t}\n}\n\n/**\n * Once the workers are up: every subscription recorded as pending is\n * subscribed again — SNS resends its confirmation to a worker now there to\n * answer it — and waited on until confirmed.\n *\n * The first deploy needs it: the subscription is made before the worker\n * starts, so SNS's first confirmation finds nobody.\n *\n * A bucket's subscriptions are reached with the deploy's provisioning\n * credentials; a hand-set topic's with the connection string they were made\n * with, read from the stage's secrets.\n *\n * @returns what is still pending when the wait ran out — none, normally.\n */\nexport async function confirmPendingSubscriptions(input: {\n\tworkspace: NormalizedWorkspace;\n\tstage: string;\n\tresources: Readonly<Record<string, ResourceRecord>> | undefined;\n\t/** The stage's secrets — a hand-set topic's connection string. */\n\tsecrets?: Readonly<Record<string, string>>;\n\tenv?: NodeJS.ProcessEnv;\n\thome?: string;\n\t/** How long to wait for confirmations, in milliseconds. */\n\ttimeoutMs?: number;\n\trecord?: (record: ResourceRecord) => Promise<void>;\n\tlog?: (line: string) => void;\n}): Promise<string[]> {\n\tconst env = input.env ?? process.env;\n\tconst records = Object.values(input.resources ?? {}).filter(\n\t\t(r) => r.type === SUBSCRIPTION_TYPE && r.id,\n\t);\n\tif (!records.some((r) => r.data?.pending === true)) return [];\n\n\tconst { SNSConnection, reconcileHttpSubscriptions } = await import(\n\t\t'@geekmidas/events/sns'\n\t);\n\tconst { GetSubscriptionAttributesCommand } = await import(\n\t\t'@aws-sdk/client-sns'\n\t);\n\tconst endpoint = awsEndpoint(env, 'SNS');\n\tlet provisioning: AwsProvisioning | undefined | null = null;\n\n\t// Every subscription to the same topic on the same host, not only the\n\t// pending ones: the reconcile removes what it is not handed.\n\tconst groups = new Map<string, ResourceRecord[]>();\n\tfor (const record of records) {\n\t\tconst host = new URL(String(record.data?.endpoint)).host;\n\t\tconst group = `${record.data?.topicArn}|${host}`;\n\t\tgroups.set(group, [...(groups.get(group) ?? []), record]);\n\t}\n\n\tconst left: string[] = [];\n\tfor (const [group, members] of groups) {\n\t\tconst pending = members.filter((r) => r.data?.pending === true);\n\t\tif (pending.length === 0) continue;\n\t\tconst [topicArn, host] = group.split('|') as [string, string];\n\t\tconst unreachable = () =>\n\t\t\tleft.push(...pending.map((r) => String(r.data?.endpoint)));\n\n\t\tlet connection: SNSConnection;\n\t\tconst connectionKey = members[0]!.data?.connectionKey;\n\t\tif (typeof connectionKey === 'string') {\n\t\t\tconst connectionString = input.secrets?.[connectionKey];\n\t\t\tif (!connectionString?.startsWith('sns:')) {\n\t\t\t\tunreachable();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconnection = await topicConnection({\n\t\t\t\tconnectionKey,\n\t\t\t\tconnectionString,\n\t\t\t\tstage: input.stage,\n\t\t\t\tenv,\n\t\t\t\t...(input.home ? { home: input.home } : {}),\n\t\t\t});\n\t\t} else {\n\t\t\tif (provisioning === null) {\n\t\t\t\tprovisioning = await awsProvisioningCredentials({\n\t\t\t\t\tstage: input.stage,\n\t\t\t\t\tenv,\n\t\t\t\t\t...(input.home ? { home: input.home } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (!provisioning) {\n\t\t\t\tunreachable();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The topic's own region, read off its ARN: a bucket may be elsewhere.\n\t\t\tconst region = topicArn.split(':')[3]!;\n\t\t\tconst { credentials } = await awsClientConfig(provisioning, region);\n\t\t\tconnection = new SNSConnection({\n\t\t\t\ttopicArn,\n\t\t\t\tregion,\n\t\t\t\t...(endpoint ? { endpoint } : {}),\n\t\t\t\t...(credentials ? { credentials } : {}),\n\t\t\t});\n\t\t}\n\n\t\tawait reconcileHttpSubscriptions(connection, {\n\t\t\tendpoints: members.map(specOf),\n\t\t\townedHost: host,\n\t\t});\n\n\t\tconst deadline = Date.now() + (input.timeoutMs ?? 60_000);\n\t\tfor (const record of pending) {\n\t\t\tlet confirmed = false;\n\t\t\twhile (!confirmed) {\n\t\t\t\tconst { Attributes = {} } = await connection.snsClient.send(\n\t\t\t\t\tnew GetSubscriptionAttributesCommand({\n\t\t\t\t\t\tSubscriptionArn: record.id!,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tconfirmed = Attributes.PendingConfirmation !== 'true';\n\t\t\t\tif (confirmed || Date.now() > deadline) break;\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, 1000));\n\t\t\t}\n\t\t\tif (confirmed) {\n\t\t\t\tinput.log?.(` ✓ ${record.data?.endpoint} confirmed its subscription`);\n\t\t\t\tawait input.record?.({\n\t\t\t\t\t...record,\n\t\t\t\t\tdata: { ...record.data, pending: false },\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tleft.push(String(record.data?.endpoint));\n\t\t\t}\n\t\t}\n\t\tawait connection.close();\n\t}\n\treturn left;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6BA,eAAsB,2BACrB,QACuC;CACvC,MAAM,SAAS,OAAO,IAAI,cAAc,OAAO,IAAI;CACnD,MAAM,QAAQ,SAAS,EAAE,OAAO,IAAI,CAAC;CACrC,IAAI,OAAO,SAAS,OAAO;EAAE,SAAS,OAAO;EAAS,GAAG;CAAM;CAE/D,MAAM,SAAS,MAAM,kBAAkB;EACtC,KA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