@geekmidas/cli 10.0.0-alpha.186 → 10.0.0-alpha.188
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{LegacyStateStore-BwHw28fJ.mjs → LegacyStateStore-iI2LW48g.mjs} +2 -2
- package/dist/{LegacyStateStore-BwHw28fJ.mjs.map → LegacyStateStore-iI2LW48g.mjs.map} +1 -1
- package/dist/{LegacyStateStore-LpTY3S7z.cjs → LegacyStateStore-kFahq3hz.cjs} +2 -2
- package/dist/{LegacyStateStore-LpTY3S7z.cjs.map → LegacyStateStore-kFahq3hz.cjs.map} +1 -1
- package/dist/{LocalStateStore-DsdNLm0_.mjs → LocalStateStore-CHKz7oSH.mjs} +2 -2
- package/dist/{LocalStateStore-DsdNLm0_.mjs.map → LocalStateStore-CHKz7oSH.mjs.map} +1 -1
- package/dist/{LocalStateStore-Dpn9kBuK.cjs → LocalStateStore-COvGAS9D.cjs} +2 -2
- package/dist/{LocalStateStore-Dpn9kBuK.cjs.map → LocalStateStore-COvGAS9D.cjs.map} +1 -1
- package/dist/{S3StateStore-Bk_EIWLU.cjs → S3StateStore-CWgPnzYs.cjs} +4 -4
- package/dist/{S3StateStore-Bk_EIWLU.cjs.map → S3StateStore-CWgPnzYs.cjs.map} +1 -1
- package/dist/{S3StateStore-BIpCLzpk.mjs → S3StateStore-Dp36QWGq.mjs} +4 -4
- package/dist/{S3StateStore-BIpCLzpk.mjs.map → S3StateStore-Dp36QWGq.mjs.map} +1 -1
- package/dist/{SSMStateStore-PiZxPXeX.mjs → SSMStateStore-BXJaNkAw.mjs} +2 -2
- package/dist/{SSMStateStore-PiZxPXeX.mjs.map → SSMStateStore-BXJaNkAw.mjs.map} +1 -1
- package/dist/{SSMStateStore-A1bgCF1P.cjs → SSMStateStore-Cfk-we0n.cjs} +2 -2
- package/dist/{SSMStateStore-A1bgCF1P.cjs.map → SSMStateStore-Cfk-we0n.cjs.map} +1 -1
- package/dist/{add-sU71e0Lp.cjs → add-BpQvfbl1.cjs} +3 -3
- package/dist/{add-sU71e0Lp.cjs.map → add-BpQvfbl1.cjs.map} +1 -1
- package/dist/{add-BBhzFpQ7.mjs → add-DryeFO6A.mjs} +3 -3
- package/dist/{add-BBhzFpQ7.mjs.map → add-DryeFO6A.mjs.map} +1 -1
- package/dist/{bundler-BM6lq-36.cjs → bundler-8aBbCVsY.cjs} +6 -6
- package/dist/{bundler-BM6lq-36.cjs.map → bundler-8aBbCVsY.cjs.map} +1 -1
- package/dist/{bundler-QKbRwztS.mjs → bundler-CUBfNgPZ.mjs} +6 -6
- package/dist/{bundler-QKbRwztS.mjs.map → bundler-CUBfNgPZ.mjs.map} +1 -1
- package/dist/{cli-VCAfR-se.mjs → cli-Cj4_6-c_.mjs} +4 -4
- package/dist/{cli-VCAfR-se.mjs.map → cli-Cj4_6-c_.mjs.map} +1 -1
- package/dist/{cli-D_iytris.cjs → cli-DZEgeNYA.cjs} +4 -4
- package/dist/{cli-D_iytris.cjs.map → cli-DZEgeNYA.cjs.map} +1 -1
- package/dist/{compose-D3zc8QN1.cjs → compose-B50nt3WV.cjs} +5 -5
- package/dist/{compose-D3zc8QN1.cjs.map → compose-B50nt3WV.cjs.map} +1 -1
- package/dist/{compose-CX2BF3LG.mjs → compose-C_vg6GOx.mjs} +5 -5
- package/dist/{compose-CX2BF3LG.mjs.map → compose-C_vg6GOx.mjs.map} +1 -1
- package/dist/{config-CTrfNKYd.d.mts → config-DpqIrrRJ.d.mts} +12 -3
- package/dist/config-DpqIrrRJ.d.mts.map +1 -0
- package/dist/{config-D9g_nYIu.d.cts → config-KFyPSS0R.d.cts} +12 -3
- package/dist/config-KFyPSS0R.d.cts.map +1 -0
- package/dist/config.cjs +15 -10
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +15 -10
- package/dist/config.mjs.map +1 -1
- package/dist/{credentials-BMdpNO8R.mjs → credentials-B3lji5Yq.mjs} +6 -5
- package/dist/credentials-B3lji5Yq.mjs.map +1 -0
- package/dist/{credentials-BQ1khM28.cjs → credentials-BIP-iRPn.cjs} +3 -3
- package/dist/{credentials-BQ1khM28.cjs.map → credentials-BIP-iRPn.cjs.map} +1 -1
- package/dist/{credentials-Ci8nKFw4.mjs → credentials-CcEXccxO.mjs} +3 -3
- package/dist/{credentials-Ci8nKFw4.mjs.map → credentials-CcEXccxO.mjs.map} +1 -1
- package/dist/{credentials-C3uaZ80e.cjs → credentials-muaDESyw.cjs} +5 -4
- package/dist/credentials-muaDESyw.cjs.map +1 -0
- package/dist/{dbTunnel-DqtSAdQK.mjs → dbTunnel-BXmuGU8b.mjs} +5 -5
- package/dist/{dbTunnel-DqtSAdQK.mjs.map → dbTunnel-BXmuGU8b.mjs.map} +1 -1
- package/dist/{dbTunnel-D000s0YK.cjs → dbTunnel-BfStDMkg.cjs} +5 -5
- package/dist/{dbTunnel-D000s0YK.cjs.map → dbTunnel-BfStDMkg.cjs.map} +1 -1
- package/dist/deploy/public.cjs +9 -9
- package/dist/deploy/public.d.cts +1 -1
- package/dist/deploy/public.d.mts +1 -1
- package/dist/deploy/public.mjs +9 -9
- package/dist/{deploy-DwtM6VSz.mjs → deploy-BKWc0NFs.mjs} +9 -9
- package/dist/{deploy-DwtM6VSz.mjs.map → deploy-BKWc0NFs.mjs.map} +1 -1
- package/dist/{deploy-DRH6q_2r.cjs → deploy-SRe6K6f2.cjs} +9 -9
- package/dist/{deploy-DRH6q_2r.cjs.map → deploy-SRe6K6f2.cjs.map} +1 -1
- package/dist/{destroy-ChTJ_oUq.cjs → destroy-cDWGXdvz.cjs} +7 -7
- package/dist/{destroy-ChTJ_oUq.cjs.map → destroy-cDWGXdvz.cjs.map} +1 -1
- package/dist/{destroy-C6QwLj3b.mjs → destroy-igN-bUYa.mjs} +7 -7
- package/dist/{destroy-C6QwLj3b.mjs.map → destroy-igN-bUYa.mjs.map} +1 -1
- package/dist/{dokploy-jeO7mz1R.cjs → dokploy-BSDyt4OK.cjs} +2 -2
- package/dist/{dokploy-jeO7mz1R.cjs.map → dokploy-BSDyt4OK.cjs.map} +1 -1
- package/dist/{dokploy-Dm8-eHtx.mjs → dokploy-DlgTAdSK.mjs} +2 -2
- package/dist/{dokploy-Dm8-eHtx.mjs.map → dokploy-DlgTAdSK.mjs.map} +1 -1
- package/dist/{eas-BAitvB5R.cjs → eas-2DGYQ0Qf.cjs} +2 -2
- package/dist/{eas-BAitvB5R.cjs.map → eas-2DGYQ0Qf.cjs.map} +1 -1
- package/dist/{eas-CXYo8hos.mjs → eas-DMg91c_V.mjs} +2 -2
- package/dist/{eas-CXYo8hos.mjs.map → eas-DMg91c_V.mjs.map} +1 -1
- package/dist/{encryption-B7IlQ6VO.mjs → encryption-4tw7AQve.mjs} +2 -2
- package/dist/{encryption-B7IlQ6VO.mjs.map → encryption-4tw7AQve.mjs.map} +1 -1
- package/dist/{encryption-OPCsewWc.cjs → encryption-CS5tEnE1.cjs} +2 -2
- package/dist/{encryption-OPCsewWc.cjs.map → encryption-CS5tEnE1.cjs.map} +1 -1
- package/dist/{engine-a6K99WIl.mjs → engine-4nWsBOM9.mjs} +6 -6
- package/dist/{engine-a6K99WIl.mjs.map → engine-4nWsBOM9.mjs.map} +1 -1
- package/dist/{engine-BSnhQLaB.cjs → engine-DBuoGHhE.cjs} +6 -6
- package/dist/{engine-BSnhQLaB.cjs.map → engine-DBuoGHhE.cjs.map} +1 -1
- package/dist/{github-D4hThtnt.mjs → github-CBexMKt6.mjs} +6 -6
- package/dist/{github-D4hThtnt.mjs.map → github-CBexMKt6.mjs.map} +1 -1
- package/dist/{github-C3gUSbLn.cjs → github-DVmVvYif.cjs} +6 -6
- package/dist/{github-C3gUSbLn.cjs.map → github-DVmVvYif.cjs.map} +1 -1
- package/dist/{googlePlay-C5Q7Zov3.cjs → googlePlay-C3Bn_DCj.cjs} +4 -4
- package/dist/{googlePlay-C5Q7Zov3.cjs.map → googlePlay-C3Bn_DCj.cjs.map} +1 -1
- package/dist/{googlePlay-DIS9PeFB.mjs → googlePlay-jTL8R6Q8.mjs} +4 -4
- package/dist/{googlePlay-DIS9PeFB.mjs.map → googlePlay-jTL8R6Q8.mjs.map} +1 -1
- package/dist/index.cjs +60 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +60 -60
- package/dist/index.mjs.map +1 -1
- package/dist/{local-CMA_7b0_.mjs → local-BejxzczT.mjs} +2 -2
- package/dist/{local-CMA_7b0_.mjs.map → local-BejxzczT.mjs.map} +1 -1
- package/dist/{local-B5R1WWEO.cjs → local-PWkIhiU0.cjs} +2 -2
- package/dist/{local-B5R1WWEO.cjs.map → local-PWkIhiU0.cjs.map} +1 -1
- package/dist/{migrate-BhnCtwMX.mjs → migrate-Bl8oaz7u.mjs} +2 -2
- package/dist/{migrate-BhnCtwMX.mjs.map → migrate-Bl8oaz7u.mjs.map} +1 -1
- package/dist/{migrate-B0041tRF.cjs → migrate-ChKFKdH1.cjs} +4 -4
- package/dist/{migrate-B0041tRF.cjs.map → migrate-ChKFKdH1.cjs.map} +1 -1
- package/dist/{migrate-168wMF5m.mjs → migrate-DpnMqHxD.mjs} +4 -4
- package/dist/{migrate-168wMF5m.mjs.map → migrate-DpnMqHxD.mjs.map} +1 -1
- package/dist/{migrate-BZxh_zU5.cjs → migrate-Dxcfcm3A.cjs} +2 -2
- package/dist/{migrate-BZxh_zU5.cjs.map → migrate-Dxcfcm3A.cjs.map} +1 -1
- package/dist/{projectBucket-hF0-tlq9.mjs → projectBucket-BeCDyZQX.mjs} +2 -2
- package/dist/{projectBucket-hF0-tlq9.mjs.map → projectBucket-BeCDyZQX.mjs.map} +1 -1
- package/dist/{projectBucket-DEBaYEbi.cjs → projectBucket-D4AqCGVr.cjs} +2 -2
- package/dist/{projectBucket-DEBaYEbi.cjs.map → projectBucket-D4AqCGVr.cjs.map} +1 -1
- package/dist/{publish-_lVOoWCy.mjs → publish-CXqI2-U3.mjs} +2 -2
- package/dist/{publish-_lVOoWCy.mjs.map → publish-CXqI2-U3.mjs.map} +1 -1
- package/dist/{publish-B-ffSuAX.cjs → publish-e2lsR2Jq.cjs} +2 -2
- package/dist/{publish-B-ffSuAX.cjs.map → publish-e2lsR2Jq.cjs.map} +1 -1
- package/dist/{resolve-UK4b26dm.mjs → resolve-BMmiH24Y.mjs} +4 -4
- package/dist/{resolve-UK4b26dm.mjs.map → resolve-BMmiH24Y.mjs.map} +1 -1
- package/dist/{resolve-Cs38fbaX.cjs → resolve-BgjyMQZy.cjs} +4 -4
- package/dist/{resolve-Cs38fbaX.cjs.map → resolve-BgjyMQZy.cjs.map} +1 -1
- package/dist/{rollback-B0eg3M0J.mjs → rollback-BpJonwn6.mjs} +6 -6
- package/dist/{rollback-B0eg3M0J.mjs.map → rollback-BpJonwn6.mjs.map} +1 -1
- package/dist/{rollback-DByniS9X.cjs → rollback-Cf1JpbwJ.cjs} +6 -6
- package/dist/{rollback-DByniS9X.cjs.map → rollback-Cf1JpbwJ.cjs.map} +1 -1
- package/dist/{s3-B-IJWFJA.mjs → s3-CRShyAj_.mjs} +2 -2
- package/dist/{s3-B-IJWFJA.mjs.map → s3-CRShyAj_.mjs.map} +1 -1
- package/dist/{s3-4rmPI6wv.cjs → s3-P47E4YMA.cjs} +2 -2
- package/dist/{s3-4rmPI6wv.cjs.map → s3-P47E4YMA.cjs.map} +1 -1
- package/dist/{serverSetup-Cok75j21.mjs → serverSetup-gRotzelq.mjs} +6 -6
- package/dist/{serverSetup-Cok75j21.mjs.map → serverSetup-gRotzelq.mjs.map} +1 -1
- package/dist/{serverSetup-EY5vppoS.cjs → serverSetup-rJUXJgY4.cjs} +6 -6
- package/dist/{serverSetup-EY5vppoS.cjs.map → serverSetup-rJUXJgY4.cjs.map} +1 -1
- package/dist/{sniffer-CcLTONfm.cjs → sniffer-BQOt66oy.cjs} +6 -6
- package/dist/{sniffer-CcLTONfm.cjs.map → sniffer-BQOt66oy.cjs.map} +1 -1
- package/dist/{sniffer-DIyYcOXJ.mjs → sniffer-D82SAjc_.mjs} +6 -6
- package/dist/{sniffer-DIyYcOXJ.mjs.map → sniffer-D82SAjc_.mjs.map} +1 -1
- package/dist/{snsSubscriptions-Bore7t-W.cjs → snsSubscriptions-Ci62xcrq.cjs} +2 -2
- package/dist/{snsSubscriptions-Bore7t-W.cjs.map → snsSubscriptions-Ci62xcrq.cjs.map} +1 -1
- package/dist/{snsSubscriptions-CYEVD7ml.mjs → snsSubscriptions-D-1y_R8M.mjs} +2 -2
- package/dist/{snsSubscriptions-CYEVD7ml.mjs.map → snsSubscriptions-D-1y_R8M.mjs.map} +1 -1
- package/dist/{sst-Bsu5O1Lt.cjs → sst-BBNnVnl2.cjs} +5 -5
- package/dist/{sst-Bsu5O1Lt.cjs.map → sst-BBNnVnl2.cjs.map} +1 -1
- package/dist/{sst-DBH707Na.mjs → sst-CbJS1d--.mjs} +5 -5
- package/dist/{sst-DBH707Na.mjs.map → sst-CbJS1d--.mjs.map} +1 -1
- package/dist/{stack-DU2SunuO.mjs → stack-BXyv__ZA.mjs} +41 -19
- package/dist/stack-BXyv__ZA.mjs.map +1 -0
- package/dist/{stack-CwSx-6ea.cjs → stack-DmZPFXyz.cjs} +40 -18
- package/dist/stack-DmZPFXyz.cjs.map +1 -0
- package/dist/{stage-BgD-kKY3.cjs → stage-CvUrBgxq.cjs} +4 -4
- package/dist/{stage-BgD-kKY3.cjs.map → stage-CvUrBgxq.cjs.map} +1 -1
- package/dist/{stage-BGyx0OjL.mjs → stage-xkuXOSsr.mjs} +4 -4
- package/dist/{stage-BGyx0OjL.mjs.map → stage-xkuXOSsr.mjs.map} +1 -1
- package/dist/target/public.cjs +1 -1
- package/dist/target/public.mjs +1 -1
- package/dist/{terminal-GyXHsRAl.cjs → terminal-BFUESry5.cjs} +2 -2
- package/dist/{terminal-GyXHsRAl.cjs.map → terminal-BFUESry5.cjs.map} +1 -1
- package/dist/{terminal-BlJ90AIM.mjs → terminal-iOb1b-eG.mjs} +2 -2
- package/dist/{terminal-BlJ90AIM.mjs.map → terminal-iOb1b-eG.mjs.map} +1 -1
- package/package.json +16 -16
- package/dist/config-CTrfNKYd.d.mts.map +0 -1
- package/dist/config-D9g_nYIu.d.cts.map +0 -1
- package/dist/credentials-BMdpNO8R.mjs.map +0 -1
- package/dist/credentials-C3uaZ80e.cjs.map +0 -1
- package/dist/stack-CwSx-6ea.cjs.map +0 -1
- package/dist/stack-DU2SunuO.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destroy-C6QwLj3b.mjs","names":[],"sources":["../src/providers/s3/destroy.ts","../src/compose/destroy.ts"],"sourcesContent":["/**\n * What `gkm compose --destroy` deletes in the stage's AWS account: each\n * resource a deploy recorded in the stage's state, and only once it is\n * proven gkm's own for this stage.\n *\n * A record alone proves nothing — a deploy records what it found and adopted\n * exactly as what it made (a certificate for the host, a bucket with no\n * tags). So each is checked against what gkm marks its own with: the\n * `gkm:project` and `gkm:stage` tags on a bucket, a user, a certificate, a\n * distribution, a topic or a queue; the stage's own name on an origin access\n * control and a headers policy, which take no tags. What fails the check is\n * left where it is, and said so.\n *\n * Nothing here runs on its own: `planAwsDestroy` reads, and returns a step\n * per resource whose `remove()` the command calls — after the person typed\n * the stage's name — in the order AWS needs: a distribution disabled and\n * gone before its certificate, a user's keys and policies before the user,\n * a bucket emptied before it is deleted.\n */\n\nimport type { ResourceRecord } from '../../deploy/StateStore.js';\nimport { GkmError } from '../../errors.js';\nimport { type AwsProvisioning, awsClientConfig, awsEndpoint } from '../aws.js';\nimport { TAG_PROJECT, TAG_STAGE } from '../iam.js';\nimport { type CdnClients, cdnName, defaultCdnClients } from './cdn.js';\nimport { defaultClients } from './index.js';\nimport { IAM_USER_PATH } from './naming.js';\n\n/** What a destroy step is about, as the person reads it. */\nexport interface AwsDestroyStep {\n\t/** The state record it is kept as: forgotten once it is gone. */\n\tkey: string;\n\tlabel: string;\n\t/** Why it is not deleted. Absent for one that will be. */\n\tleftAlone?: string;\n\t/** Already gone from the account: only its record is forgotten. */\n\tgone?: boolean;\n\t/** Deleted along with its user's step: only its record is forgotten here. */\n\twithUser?: boolean;\n\t/** Deletes it. Absent when it is left alone or already gone. */\n\tremove?: () => Promise<void>;\n}\n\n/** A DNS record a resource here needs, worked out from the resource. */\nexport interface AwsDnsRecord {\n\thost: string;\n\ttype: 'CNAME';\n\tvalue: string;\n}\n\nexport interface AwsDestroyPlan {\n\t/** In the order they are removed. */\n\tsteps: AwsDestroyStep[];\n\t/**\n\t * The records the s3 provider wrote for what it deletes — a CDN's name, a\n\t * certificate's validation — which no state record names.\n\t */\n\tdns: AwsDnsRecord[];\n}\n\nexport interface AwsDestroyInput {\n\tresources: Record<string, ResourceRecord>;\n\t/** `deployIdentity(…).key` — what `gkm:project` holds. */\n\tidentityKey: string;\n\t/** `deployIdentity(…).scope` — what CDN resource names start with. */\n\tscope: string;\n\tstage: string;\n\tcredential: AwsProvisioning;\n\t/** How long a disabled distribution is waited on, and how often asked. */\n\twait?: { timeoutMs: number; intervalMs: number };\n\t/** For tests: where the clients come from. */\n\tclients?: {\n\t\ts3?: typeof defaultClients;\n\t\tcdn?: (credential: AwsProvisioning) => Promise<CdnClients>;\n\t};\n}\n\n/** The record types this plans. Every other is the command's to report. */\nexport const AWS_RESOURCE_TYPES = [\n\t'cloudfront-distribution',\n\t'cloudfront-oac',\n\t'cloudfront-headers',\n\t'acm-certificate',\n\t'sns-subscription',\n\t'sns-topic',\n\t'sqs-queue',\n\t'iam-access-key',\n\t'iam-user',\n\t's3-bucket',\n] as const;\n\n/** A distribution disabled before it is deleted can take this long. */\nconst DISABLE_WAIT = { timeoutMs: 45 * 60_000, intervalMs: 20_000 };\n\n/** A disabled distribution that never finished deploying. */\nexport class DistributionStillDeploying extends GkmError {\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly waitedMs: number,\n\t) {\n\t\tsuper(\n\t\t\t`CloudFront distribution ${id} was disabled, and is still deploying after ` +\n\t\t\t\t`${Math.round(waitedMs / 60_000)} minutes. CloudFront deletes only a ` +\n\t\t\t\t'disabled distribution that has finished deploying. Run the destroy ' +\n\t\t\t\t'again later: everything deleted so far is forgotten, and it carries ' +\n\t\t\t\t'on from here.',\n\t\t);\n\t\tthis.name = 'DistributionStillDeploying';\n\t}\n}\n\n/** What an AWS SDK error is called, whichever field carries it. */\nfunction errorName(error: unknown): string {\n\tconst e = error as { name?: string; Code?: string };\n\treturn e?.Code ?? e?.name ?? '';\n}\n\n/** A read whose \"there is none\" answer is one of `missing`. */\nasync function readOr<T>(\n\tread: () => Promise<T>,\n\tmissing: readonly string[],\n): Promise<T | undefined> {\n\ttry {\n\t\treturn await read();\n\t} catch (error) {\n\t\tif (missing.includes(errorName(error))) return undefined;\n\t\tthrow error;\n\t}\n}\n\nconst sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));\n\n/** Whether a tag list says gkm made it for this project's stage. */\nfunction ours(\n\ttags: readonly { Key?: string; Value?: string }[] | undefined,\n\tinput: Pick<AwsDestroyInput, 'identityKey' | 'stage'>,\n): boolean {\n\tconst of = (key: string) => tags?.find((t) => t.Key === key)?.Value;\n\treturn of(TAG_PROJECT) === input.identityKey && of(TAG_STAGE) === input.stage;\n}\n\nconst NOT_TAGGED =\n\t\"not tagged as this stage's (gkm:project, gkm:stage): gkm found it, it did not make it\";\n\n/** The id after the type in a record's key: `cloudfront-oac:Uploads` → `Uploads`. */\nfunction keyId(record: ResourceRecord): string {\n\treturn record.key.slice(record.key.indexOf(':') + 1);\n}\n\n/** The file server a CDN record is for: `cloudfront-headers:Uploads:cors` → `Uploads`. */\nfunction serverOf(record: ResourceRecord): string {\n\treturn keyId(record).split(':')[0] ?? '';\n}\n\n/**\n * Each AWS resource the stage's state records, checked, in the order it is\n * deleted — and the DNS records the deleted ones were given.\n */\nexport async function planAwsDestroy(\n\tinput: AwsDestroyInput,\n): Promise<AwsDestroyPlan> {\n\tconst steps: AwsDestroyStep[] = [];\n\tconst dns: AwsDnsRecord[] = [];\n\tconst records = Object.values(input.resources);\n\tconst of = (type: string) => records.filter((r) => r.type === type);\n\tconst wait = input.wait ?? DISABLE_WAIT;\n\n\tconst cdnRecords = [\n\t\t...of('cloudfront-distribution'),\n\t\t...of('cloudfront-oac'),\n\t\t...of('cloudfront-headers'),\n\t\t...of('acm-certificate'),\n\t];\n\tif (cdnRecords.length > 0) {\n\t\tconst cdn = await (input.clients?.cdn ?? defaultCdnClients)(\n\t\t\tinput.credential,\n\t\t);\n\t\t// A distribution left alone keeps what it uses: deleting its origin\n\t\t// access control, a headers policy or its certificate would break it.\n\t\tconst kept = new Map<string, string>();\n\t\tfor (const record of of('cloudfront-distribution')) {\n\t\t\tconst step = await distributionStep(cdn, record, input, wait, dns);\n\t\t\tif (step.leftAlone) kept.set(serverOf(record), step.label);\n\t\t\tsteps.push(step);\n\t\t}\n\t\tconst usedBy = async (\n\t\t\trecord: ResourceRecord,\n\t\t\tstep: () => Promise<AwsDestroyStep>,\n\t\t): Promise<AwsDestroyStep> => {\n\t\t\tconst holder = kept.get(serverOf(record));\n\t\t\tif (!holder) return step();\n\t\t\tconst label = (await step()).label;\n\t\t\treturn {\n\t\t\t\tkey: record.key,\n\t\t\t\tlabel,\n\t\t\t\tleftAlone: `used by ${holder}, which is left alone`,\n\t\t\t};\n\t\t};\n\t\tfor (const record of of('cloudfront-oac')) {\n\t\t\tsteps.push(\n\t\t\t\tawait usedBy(record, () => originAccessControlStep(cdn, record, input)),\n\t\t\t);\n\t\t}\n\t\tfor (const record of of('cloudfront-headers')) {\n\t\t\tsteps.push(\n\t\t\t\tawait usedBy(record, () => headersPolicyStep(cdn, record, input)),\n\t\t\t);\n\t\t}\n\t\tfor (const record of of('acm-certificate')) {\n\t\t\t// Its validation record goes only with the certificate itself.\n\t\t\tconst found: AwsDnsRecord[] = [];\n\t\t\tconst step = await usedBy(record, () =>\n\t\t\t\tcertificateStep(cdn, record, input, found),\n\t\t\t);\n\t\t\tif (!step.leftAlone) dns.push(...found);\n\t\t\tsteps.push(step);\n\t\t}\n\t}\n\n\tconst eventRecords = [\n\t\t...of('sns-subscription'),\n\t\t...of('sns-topic'),\n\t\t...of('sqs-queue'),\n\t];\n\tif (eventRecords.length > 0) {\n\t\tconst events = await eventClients(input.credential, records);\n\t\tfor (const record of of('sns-subscription')) {\n\t\t\tsteps.push(subscriptionStep(events, record));\n\t\t}\n\t\tfor (const record of of('sns-topic')) {\n\t\t\tsteps.push(await topicStep(events, record, input));\n\t\t}\n\t\tfor (const record of of('sqs-queue')) {\n\t\t\tsteps.push(await queueStep(events, record, input));\n\t\t}\n\t}\n\n\tconst users = of('iam-user');\n\tconst keys = of('iam-access-key');\n\tconst buckets = of('s3-bucket');\n\tif (users.length + keys.length + buckets.length > 0) {\n\t\tconst global = await (input.clients?.s3 ?? defaultClients)(\n\t\t\tinput.credential,\n\t\t\tregionOf(buckets[0]) ?? 'us-east-1',\n\t\t);\n\t\tconst userSteps = new Map<string, AwsDestroyStep>();\n\t\tfor (const record of users) {\n\t\t\tconst step = await userStep(global, record, input);\n\t\t\tuserSteps.set(record.id ?? '', step);\n\t\t\tsteps.push(step);\n\t\t}\n\t\t// A key goes with its user, and is checked through it.\n\t\tfor (const record of keys) {\n\t\t\tconst user = (record.data as { user?: string } | undefined)?.user;\n\t\t\tconst owner = user ? userSteps.get(user) : undefined;\n\t\t\tsteps.push({\n\t\t\t\tkey: record.key,\n\t\t\t\tlabel: `IAM access key ${record.id ?? ''} of ${user ?? 'an unknown user'}`,\n\t\t\t\t...(owner?.leftAlone\n\t\t\t\t\t? { leftAlone: `its user is left alone: ${owner.leftAlone}` }\n\t\t\t\t\t: owner\n\t\t\t\t\t\t? { withUser: true }\n\t\t\t\t\t\t: { leftAlone: 'its user is not one this stage recorded' }),\n\t\t\t});\n\t\t}\n\t\tfor (const record of buckets) {\n\t\t\tconst region = regionOf(record) ?? global.region;\n\t\t\tconst clients =\n\t\t\t\tregion === global.region\n\t\t\t\t\t? global\n\t\t\t\t\t: await (input.clients?.s3 ?? defaultClients)(\n\t\t\t\t\t\t\tinput.credential,\n\t\t\t\t\t\t\tregion,\n\t\t\t\t\t\t);\n\t\t\tsteps.push(await bucketStep(clients, record, input));\n\t\t}\n\t}\n\n\treturn { steps, dns };\n}\n\nfunction regionOf(record: ResourceRecord | undefined): string | undefined {\n\treturn (record?.data as { region?: string } | undefined)?.region;\n}\n\n// ---------------------------------------------------------------------------\n// CloudFront and ACM\n// ---------------------------------------------------------------------------\n\nasync function distributionStep(\n\t{ CF, cloudfront }: CdnClients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n\twait: { timeoutMs: number; intervalMs: number },\n\tdns: AwsDnsRecord[],\n): Promise<AwsDestroyStep> {\n\tconst id = record.id ?? '';\n\tconst found = await readOr(\n\t\t() => cloudfront.send(new CF.GetDistributionCommand({ Id: id })),\n\t\t['NoSuchDistribution'],\n\t);\n\tconst distribution = found?.Distribution;\n\tconst aliases = distribution?.DistributionConfig?.Aliases?.Items ?? [];\n\tconst label = `CloudFront distribution ${id}${aliases.length ? ` (${aliases.join(', ')})` : ''}`;\n\tif (!distribution) return { key: record.key, label, gone: true };\n\n\t// Its tags, or the comment gkm writes on every distribution it makes —\n\t// `gkm <project> <stage> <file server>`, which nothing else writes.\n\tconst tags = await cloudfront.send(\n\t\tnew CF.ListTagsForResourceCommand({ Resource: distribution.ARN }),\n\t);\n\tconst comment = `gkm ${input.identityKey} ${input.stage} ${serverOf(record)}`;\n\tconst marked =\n\t\tdistribution.DistributionConfig?.Comment === comment.slice(0, 128);\n\tif (!ours(tags.Tags?.Items, input) && !marked) {\n\t\treturn {\n\t\t\tkey: record.key,\n\t\t\tlabel,\n\t\t\tleftAlone: `${NOT_TAGGED}, and its comment is not \"${comment}\"`,\n\t\t};\n\t}\n\tfor (const host of aliases) {\n\t\tdns.push({ host, type: 'CNAME', value: distribution.DomainName ?? '' });\n\t}\n\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tlet current = await cloudfront.send(\n\t\t\t\tnew CF.GetDistributionConfigCommand({ Id: id }),\n\t\t\t);\n\t\t\tif (current.DistributionConfig?.Enabled) {\n\t\t\t\tawait cloudfront.send(\n\t\t\t\t\tnew CF.UpdateDistributionCommand({\n\t\t\t\t\t\tId: id,\n\t\t\t\t\t\tIfMatch: current.ETag,\n\t\t\t\t\t\tDistributionConfig: {\n\t\t\t\t\t\t\t...current.DistributionConfig,\n\t\t\t\t\t\t\tEnabled: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst started = Date.now();\n\t\t\tfor (;;) {\n\t\t\t\tconst state = await cloudfront.send(\n\t\t\t\t\tnew CF.GetDistributionCommand({ Id: id }),\n\t\t\t\t);\n\t\t\t\tif (state.Distribution?.Status === 'Deployed') break;\n\t\t\t\tif (Date.now() - started > wait.timeoutMs) {\n\t\t\t\t\tthrow new DistributionStillDeploying(id, Date.now() - started);\n\t\t\t\t}\n\t\t\t\tawait sleep(wait.intervalMs);\n\t\t\t}\n\t\t\tcurrent = await cloudfront.send(\n\t\t\t\tnew CF.GetDistributionConfigCommand({ Id: id }),\n\t\t\t);\n\t\t\tawait cloudfront.send(\n\t\t\t\tnew CF.DeleteDistributionCommand({ Id: id, IfMatch: current.ETag }),\n\t\t\t);\n\t\t},\n\t};\n}\n\nasync function originAccessControlStep(\n\t{ CF, cloudfront }: CdnClients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n): Promise<AwsDestroyStep> {\n\tconst id = record.id ?? '';\n\tconst expected = cdnName(input.scope, input.stage, keyId(record));\n\tconst label = `CloudFront origin access control ${expected}`;\n\tconst found = await readOr(\n\t\t() => cloudfront.send(new CF.GetOriginAccessControlCommand({ Id: id })),\n\t\t['NoSuchOriginAccessControl'],\n\t);\n\tif (!found) return { key: record.key, label, gone: true };\n\tconst name = found.OriginAccessControl?.OriginAccessControlConfig?.Name;\n\tif (name !== expected) {\n\t\treturn {\n\t\t\tkey: record.key,\n\t\t\tlabel,\n\t\t\tleftAlone: `named ${name}, not this stage's ${expected}`,\n\t\t};\n\t}\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tconst { ETag } = await cloudfront.send(\n\t\t\t\tnew CF.GetOriginAccessControlCommand({ Id: id }),\n\t\t\t);\n\t\t\tawait cloudfront.send(\n\t\t\t\tnew CF.DeleteOriginAccessControlCommand({ Id: id, IfMatch: ETag }),\n\t\t\t);\n\t\t},\n\t};\n}\n\nasync function headersPolicyStep(\n\t{ CF, cloudfront }: CdnClients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n): Promise<AwsDestroyStep> {\n\tconst id = record.id ?? '';\n\t// `cloudfront-headers:<server>:<kind>`\n\tconst [server = '', kind = ''] = keyId(record).split(':');\n\tconst expected = `${cdnName(input.scope, input.stage, server)}-${kind}`;\n\tconst label = `CloudFront response headers policy ${expected}`;\n\tconst found = await readOr(\n\t\t() =>\n\t\t\tcloudfront.send(new CF.GetResponseHeadersPolicyConfigCommand({ Id: id })),\n\t\t['NoSuchResponseHeadersPolicy'],\n\t);\n\tif (!found) return { key: record.key, label, gone: true };\n\tconst name = found.ResponseHeadersPolicyConfig?.Name;\n\tif (name !== expected) {\n\t\treturn {\n\t\t\tkey: record.key,\n\t\t\tlabel,\n\t\t\tleftAlone: `named ${name}, not this stage's ${expected}`,\n\t\t};\n\t}\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tconst { ETag } = await cloudfront.send(\n\t\t\t\tnew CF.GetResponseHeadersPolicyConfigCommand({ Id: id }),\n\t\t\t);\n\t\t\tawait cloudfront.send(\n\t\t\t\tnew CF.DeleteResponseHeadersPolicyCommand({ Id: id, IfMatch: ETag }),\n\t\t\t);\n\t\t},\n\t};\n}\n\nasync function certificateStep(\n\t{ ACM, acm }: CdnClients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n\tdns: AwsDnsRecord[],\n): Promise<AwsDestroyStep> {\n\tconst arn = record.id ?? '';\n\tconst host = (record.data as { host?: string } | undefined)?.host ?? arn;\n\tconst label = `ACM certificate ${host} (us-east-1)`;\n\tconst found = await readOr(\n\t\t() => acm.send(new ACM.DescribeCertificateCommand({ CertificateArn: arn })),\n\t\t['ResourceNotFoundException'],\n\t);\n\tif (!found?.Certificate) return { key: record.key, label, gone: true };\n\tconst tags = await acm.send(\n\t\tnew ACM.ListTagsForCertificateCommand({ CertificateArn: arn }),\n\t);\n\tif (!ours(tags.Tags, input)) {\n\t\treturn { key: record.key, label, leftAlone: NOT_TAGGED };\n\t}\n\tfor (const option of found.Certificate.DomainValidationOptions ?? []) {\n\t\tconst r = option.ResourceRecord;\n\t\tif (r?.Name && r.Value && r.Type === 'CNAME') {\n\t\t\tdns.push({ host: r.Name, type: 'CNAME', value: r.Value });\n\t\t}\n\t}\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tawait acm.send(new ACM.DeleteCertificateCommand({ CertificateArn: arn }));\n\t\t},\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// SNS and SQS\n// ---------------------------------------------------------------------------\n\ninterface EventClients {\n\tSNS: typeof import('@aws-sdk/client-sns');\n\tSQS: typeof import('@aws-sdk/client-sqs');\n\tsns: (\n\t\tregion: string,\n\t) => Promise<InstanceType<typeof import('@aws-sdk/client-sns')['SNSClient']>>;\n\tsqs: (\n\t\tregion: string,\n\t) => Promise<InstanceType<typeof import('@aws-sdk/client-sqs')['SQSClient']>>;\n}\n\nasync function eventClients(\n\tcredential: AwsProvisioning,\n\t_records: readonly ResourceRecord[],\n): Promise<EventClients> {\n\tconst SNS = await import('@aws-sdk/client-sns');\n\tconst SQS = await import('@aws-sdk/client-sqs');\n\tconst sns = new Map<string, InstanceType<typeof SNS.SNSClient>>();\n\tconst sqs = new Map<string, InstanceType<typeof SQS.SQSClient>>();\n\treturn {\n\t\tSNS,\n\t\tSQS,\n\t\tsns: async (region) => {\n\t\t\tif (!sns.has(region)) {\n\t\t\t\tconst endpoint = awsEndpoint(process.env, 'SNS');\n\t\t\t\tsns.set(\n\t\t\t\t\tregion,\n\t\t\t\t\tnew SNS.SNSClient({\n\t\t\t\t\t\t...(await awsClientConfig(credential, region)),\n\t\t\t\t\t\t...(endpoint ? { endpoint } : {}),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn sns.get(region)!;\n\t\t},\n\t\tsqs: async (region) => {\n\t\t\tif (!sqs.has(region)) {\n\t\t\t\tconst endpoint = awsEndpoint(process.env, 'SQS');\n\t\t\t\tsqs.set(\n\t\t\t\t\tregion,\n\t\t\t\t\tnew SQS.SQSClient({\n\t\t\t\t\t\t...(await awsClientConfig(credential, region)),\n\t\t\t\t\t\t...(endpoint ? { endpoint } : {}),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn sqs.get(region)!;\n\t\t},\n\t};\n}\n\n/** `arn:aws:sns:<region>:<account>:<name>` */\nfunction arnParts(arn: string) {\n\tconst [, , , region = '', account = '', ...rest] = arn.split(':');\n\treturn { region, account, name: rest.join(':') };\n}\n\nfunction subscriptionStep(\n\t{ SNS, sns }: EventClients,\n\trecord: ResourceRecord,\n): AwsDestroyStep {\n\tconst arn = record.id ?? '';\n\tconst label = `SNS subscription ${keyId(record)}`;\n\t// Made by gkm, to its own push endpoint: a pending one has no ARN yet.\n\tif (!arn.startsWith('arn:')) return { key: record.key, label, gone: true };\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tconst client = await sns(arnParts(arn).region);\n\t\t\tawait readOr(\n\t\t\t\t() => client.send(new SNS.UnsubscribeCommand({ SubscriptionArn: arn })),\n\t\t\t\t['NotFound', 'NotFoundException'],\n\t\t\t);\n\t\t},\n\t};\n}\n\nasync function topicStep(\n\t{ SNS, sns }: EventClients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n): Promise<AwsDestroyStep> {\n\tconst arn = record.id ?? '';\n\tconst label = `SNS topic ${arnParts(arn).name}`;\n\tconst client = await sns(arnParts(arn).region);\n\tconst tags = await readOr(\n\t\t() => client.send(new SNS.ListTagsForResourceCommand({ ResourceArn: arn })),\n\t\t[\n\t\t\t'NotFound',\n\t\t\t'NotFoundException',\n\t\t\t'ResourceNotFound',\n\t\t\t'ResourceNotFoundException',\n\t\t],\n\t);\n\tif (!tags) return { key: record.key, label, gone: true };\n\tif (!ours(tags.Tags, input)) {\n\t\treturn { key: record.key, label, leftAlone: NOT_TAGGED };\n\t}\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tawait client.send(new SNS.DeleteTopicCommand({ TopicArn: arn }));\n\t\t},\n\t};\n}\n\nasync function queueStep(\n\t{ SQS, sqs }: EventClients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n): Promise<AwsDestroyStep> {\n\tconst arn = record.id ?? '';\n\tconst { region, account, name } = arnParts(arn);\n\tconst label = `SQS queue ${name}`;\n\tconst client = await sqs(region);\n\tconst url = await readOr(\n\t\t() =>\n\t\t\tclient.send(\n\t\t\t\tnew SQS.GetQueueUrlCommand({\n\t\t\t\t\tQueueName: name,\n\t\t\t\t\tQueueOwnerAWSAccountId: account,\n\t\t\t\t}),\n\t\t\t),\n\t\t['QueueDoesNotExist', 'AWS.SimpleQueueService.NonExistentQueue'],\n\t);\n\tif (!url?.QueueUrl) return { key: record.key, label, gone: true };\n\tconst queueUrl = url.QueueUrl;\n\tconst tags = await client.send(\n\t\tnew SQS.ListQueueTagsCommand({ QueueUrl: queueUrl }),\n\t);\n\tconst list = Object.entries(tags.Tags ?? {}).map(([Key, Value]) => ({\n\t\tKey,\n\t\tValue,\n\t}));\n\tif (!ours(list, input)) {\n\t\treturn { key: record.key, label, leftAlone: NOT_TAGGED };\n\t}\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tawait client.send(new SQS.DeleteQueueCommand({ QueueUrl: queueUrl }));\n\t\t},\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// IAM and S3\n// ---------------------------------------------------------------------------\n\ntype S3Clients = Awaited<ReturnType<typeof defaultClients>>;\n\nasync function userStep(\n\t{ IAM, iam }: S3Clients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n): Promise<AwsDestroyStep> {\n\tconst name = record.id ?? '';\n\tconst label = `IAM user ${name}, its access keys and policies`;\n\tconst found = await readOr(\n\t\t() => iam.send(new IAM.GetUserCommand({ UserName: name })),\n\t\t['NoSuchEntity', 'NoSuchEntityException'],\n\t);\n\tif (!found?.User) return { key: record.key, label, gone: true };\n\tconst tags = await iam.send(new IAM.ListUserTagsCommand({ UserName: name }));\n\tif (found.User.Path !== IAM_USER_PATH || !ours(tags.Tags, input)) {\n\t\treturn { key: record.key, label, leftAlone: NOT_TAGGED };\n\t}\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tconst keys = await iam.send(\n\t\t\t\tnew IAM.ListAccessKeysCommand({ UserName: name }),\n\t\t\t);\n\t\t\tfor (const key of keys.AccessKeyMetadata ?? []) {\n\t\t\t\tawait iam.send(\n\t\t\t\t\tnew IAM.DeleteAccessKeyCommand({\n\t\t\t\t\t\tUserName: name,\n\t\t\t\t\t\tAccessKeyId: key.AccessKeyId,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst inline = await iam.send(\n\t\t\t\tnew IAM.ListUserPoliciesCommand({ UserName: name }),\n\t\t\t);\n\t\t\tfor (const policy of inline.PolicyNames ?? []) {\n\t\t\t\tawait iam.send(\n\t\t\t\t\tnew IAM.DeleteUserPolicyCommand({\n\t\t\t\t\t\tUserName: name,\n\t\t\t\t\t\tPolicyName: policy,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst attached = await iam.send(\n\t\t\t\tnew IAM.ListAttachedUserPoliciesCommand({ UserName: name }),\n\t\t\t);\n\t\t\tfor (const policy of attached.AttachedPolicies ?? []) {\n\t\t\t\tawait iam.send(\n\t\t\t\t\tnew IAM.DetachUserPolicyCommand({\n\t\t\t\t\t\tUserName: name,\n\t\t\t\t\t\tPolicyArn: policy.PolicyArn,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait iam.send(new IAM.DeleteUserCommand({ UserName: name }));\n\t\t},\n\t};\n}\n\n/** Every object version and delete marker in a bucket, a page at a time. */\nasync function* bucketVersions({ S3, s3 }: S3Clients, bucket: string) {\n\tlet KeyMarker: string | undefined;\n\tlet VersionIdMarker: string | undefined;\n\tfor (;;) {\n\t\tconst page = await s3.send(\n\t\t\tnew S3.ListObjectVersionsCommand({\n\t\t\t\tBucket: bucket,\n\t\t\t\t...(KeyMarker ? { KeyMarker } : {}),\n\t\t\t\t...(VersionIdMarker ? { VersionIdMarker } : {}),\n\t\t\t}),\n\t\t);\n\t\tconst objects = [...(page.Versions ?? []), ...(page.DeleteMarkers ?? [])]\n\t\t\t.filter((o) => o.Key)\n\t\t\t.map((o) => ({\n\t\t\t\tKey: o.Key!,\n\t\t\t\t// `null` is the one version an unversioned bucket's object has:\n\t\t\t\t// named or not, the same object is deleted.\n\t\t\t\t...(o.VersionId && o.VersionId !== 'null'\n\t\t\t\t\t? { VersionId: o.VersionId }\n\t\t\t\t\t: {}),\n\t\t\t}));\n\t\tif (objects.length > 0) yield objects;\n\t\tif (!page.IsTruncated) return;\n\t\tKeyMarker = page.NextKeyMarker;\n\t\tVersionIdMarker = page.NextVersionIdMarker;\n\t}\n}\n\nasync function bucketStep(\n\tclients: S3Clients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n): Promise<AwsDestroyStep> {\n\tconst { S3, s3 } = clients;\n\tconst bucket = record.id ?? '';\n\tconst tagging = await readOr(\n\t\t() => s3.send(new S3.GetBucketTaggingCommand({ Bucket: bucket })),\n\t\t['NoSuchBucket', 'NoSuchTagSet', 'NoSuchTagSetError'],\n\t);\n\tconst exists = await readOr(\n\t\t() => s3.send(new S3.HeadBucketCommand({ Bucket: bucket })),\n\t\t['NotFound', 'NoSuchBucket'],\n\t);\n\tconst base = `S3 bucket ${bucket}`;\n\tif (!exists) return { key: record.key, label: base, gone: true };\n\tif (!ours(tagging?.TagSet, input)) {\n\t\treturn { key: record.key, label: base, leftAlone: NOT_TAGGED };\n\t}\n\tlet count = 0;\n\tfor await (const page of bucketVersions(clients, bucket))\n\t\tcount += page.length;\n\treturn {\n\t\tkey: record.key,\n\t\tlabel: `${base}, emptied first: ${count} object version${count === 1 ? '' : 's'}`,\n\t\tremove: async () => {\n\t\t\t// Until it lists nothing: deleting a version-less object in a bucket\n\t\t\t// whose versioning was suspended leaves a delete marker behind.\n\t\t\tfor (let pass = 0; pass < 5; pass++) {\n\t\t\t\tlet deleted = 0;\n\t\t\t\tfor await (const page of bucketVersions(clients, bucket)) {\n\t\t\t\t\t// At most a thousand a call.\n\t\t\t\t\tfor (let i = 0; i < page.length; i += 1000) {\n\t\t\t\t\t\tawait s3.send(\n\t\t\t\t\t\t\tnew S3.DeleteObjectsCommand({\n\t\t\t\t\t\t\t\tBucket: bucket,\n\t\t\t\t\t\t\t\tDelete: { Objects: page.slice(i, i + 1000), Quiet: true },\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tdeleted += page.length;\n\t\t\t\t}\n\t\t\t\tif (deleted === 0) break;\n\t\t\t}\n\t\t\tawait s3.send(new S3.DeleteBucketCommand({ Bucket: bucket }));\n\t\t},\n\t};\n}\n","/**\n * `gkm compose --stage <stage> --destroy`: everything a deploy made for the\n * stage, deleted for good.\n *\n * The one thing in gkm that deletes what a deploy created — a deploy itself\n * never does. So it is careful in three ways:\n *\n * - **Only what is provably gkm's.** Each AWS resource is checked against\n * what gkm marks its own with before it is deleted (see\n * `providers/s3/destroy.ts`); a DNS record only while it still holds the\n * value gkm wrote. What fails is listed, and left where it is.\n * - **Only with a person typing the stage.** The whole plan is printed\n * first, then the compose project's name — `<project>-<stage>` — has to be\n * typed back. Nothing skips that: there is no flag that answers it, and\n * with no terminal to ask at it refuses before reading anything.\n * - **Resumable.** Each resource's record is forgotten as soon as it is gone,\n * so a run that stops part way — a distribution still deploying — carries\n * on from there when it is run again.\n *\n * What other stages or projects share is never touched: the project bucket\n * that holds every stage's state, the shared Traefik edge, the server's own\n * setup (`gkm compose:server`). The stage's secrets are kept unless\n * `--secrets` is passed.\n */\n\nimport { existsSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport type { DnsProvider } from '@geekmidas/edge/dns';\nimport { EDGE_PROJECT } from '@geekmidas/edge/proxy/traefik';\nimport { loadWorkspaceConfig } from '../config';\nimport {\n\ttype CredentialProvider,\n\tstoredCredentials,\n} from '../deploy/credentials.js';\nimport { dnsRecordFqdn, dnsResources } from '../deploy/dnsResources.js';\nimport { deployIdentity } from '../deploy/identity.js';\nimport { createStateStore, type StateStore } from '../deploy/StateStore.js';\nimport {\n\textractSubdomain,\n\tfindRootDomain,\n\tnormalizeDnsConfig,\n} from '../dns/index';\nimport { GkmError } from '../errors';\nimport { canPrompt, prompt } from '../prompt';\nimport {\n\ttype AwsProvisioning,\n\tawsProvisioningCredentials,\n} from '../providers/aws.js';\nimport {\n\tAWS_RESOURCE_TYPES,\n\ttype AwsDestroyInput,\n\ttype AwsDestroyStep,\n\tplanAwsDestroy,\n} from '../providers/s3/destroy.js';\nimport { secretsStoreFor } from '../secrets/store.js';\nimport { stackOverrideFile } from '../target/compose/index';\nimport { assertDeployedStage } from '../workspace/stages.js';\nimport type {\n\tDnsProvider as DnsProviderConfig,\n\tNormalizedWorkspace,\n} from '../workspace/types.js';\nimport {\n\tdnsCredentials,\n\tpruneStackDns,\n\ttype RecordedDnsRecord,\n\trecordTtl,\n} from './dns';\nimport { type ComposeDocker, dockerCompose, type StackRef } from './docker';\nimport { edgeRef, removeEdgeRoutes } from './edge';\nimport { composeServer, dockerHost, sshTarget } from './server';\nimport { composeProject, stackDir } from './stack';\n\nexport interface ComposeDestroyOptions {\n\tcwd?: string;\n\tstage: string;\n\t/** Delete the stage's secrets too. Kept otherwise. */\n\tsecrets?: boolean;\n\t/** Print what would be deleted; delete nothing, ask nothing. */\n\tdryRun?: boolean;\n}\n\nexport interface ComposeDestroyDeps {\n\tdocker?: ComposeDocker;\n\t/** Whether a person is at a terminal to answer. */\n\tinteractive?: () => boolean;\n\t/** Ask the person, and resolve with what they typed. */\n\task?: (question: string) => Promise<string>;\n\t/** Where the DNS providers' tokens come from. */\n\tcredentials?: CredentialProvider;\n\t/** The provider for a domain — `createDnsProvider` by default. */\n\tdnsProviderFor?: (config: DnsProviderConfig) => Promise<DnsProvider | null>;\n\t/**\n\t * How the AWS account's credential is found — the machine's, as a deploy\n\t * finds it, by default.\n\t */\n\tawsCredentials?: () => Promise<AwsProvisioning | undefined>;\n\t/** For tests: the AWS clients and how long a distribution is waited on. */\n\taws?: Pick<AwsDestroyInput, 'clients' | 'wait'>;\n\tstate?: StateStore;\n\tenv?: NodeJS.ProcessEnv;\n\thome?: string;\n\tlog?: (line: string) => void;\n}\n\n/** A destroy with no terminal to type the stage's name at. */\nexport class ComposeDestroyNeedsTerminal extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly project: string,\n\t) {\n\t\tsuper(\n\t\t\t`Destroying '${stage}' deletes everything its deploys made, and asks you to ` +\n\t\t\t\t`type ${project} first — there is no terminal here to ask at, and no flag ` +\n\t\t\t\t'answers it. Run it yourself, from a terminal. `--dry-run` prints what it ' +\n\t\t\t\t'would delete, anywhere.',\n\t\t);\n\t\tthis.name = 'ComposeDestroyNeedsTerminal';\n\t}\n}\n\n/** What was typed was not the project's name. */\nexport class ComposeDestroyNotConfirmed extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly project: string,\n\t) {\n\t\tsuper(\n\t\t\t`Nothing was deleted: destroying '${stage}' needs ${project} typed exactly.`,\n\t\t);\n\t\tthis.name = 'ComposeDestroyNotConfirmed';\n\t}\n}\n\n/** AWS resources to delete, and no credentials to delete them with. */\nexport class ComposeDestroyNeedsAwsCredentials extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly resources: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`'${stage}' has ${resources.length} AWS resource${resources.length === 1 ? '' : 's'} ` +\n\t\t\t\t`to delete (${resources.slice(0, 3).join(', ')}${resources.length > 3 ? ', …' : ''}), ` +\n\t\t\t\t\"and no AWS credentials were found to delete them with. Supply the stage's \" +\n\t\t\t\t'account the way a deploy does — AWS_PROFILE, or AWS_ACCESS_KEY_ID and ' +\n\t\t\t\t'AWS_SECRET_ACCESS_KEY — and run it again. Nothing was deleted.',\n\t\t);\n\t\tthis.name = 'ComposeDestroyNeedsAwsCredentials';\n\t}\n}\n\n/** `--secrets`, and a store that cannot delete. */\nexport class SecretsStoreCannotDelete extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly store: string,\n\t) {\n\t\tsuper(\n\t\t\t`--secrets deletes '${stage}''s secrets, and its store (${store}) has no ` +\n\t\t\t\t'delete(stage). Give the custom store one, or run without --secrets and ' +\n\t\t\t\t'delete them where they are kept. Nothing was deleted.',\n\t\t);\n\t\tthis.name = 'SecretsStoreCannotDelete';\n\t}\n}\n\n/** One line of the plan, and how it is carried out. */\ninterface Step {\n\tlabel: string;\n\tleftAlone?: string;\n\t/** Forgotten from the stage's state once done. */\n\tkeys?: string[];\n\trun?: () => Promise<void>;\n}\n\n/** What a record of each type is to destroy. */\nconst KEPT_TYPES: Record<string, string> = {\n\t// The server's setup — its users, firewall, Docker — is the server's.\n\tserver:\n\t\t\"the server's setup is kept: gkm compose:server made it, for any stage\",\n};\n\n/** Records that name no resource of their own — a key in the secrets. */\nconst VALUE_TYPES = new Set(['url', 'email-from']);\n\n/**\n * The stage's stack: its project on the server (or this machine), as\n * `gkm compose --down` finds it.\n */\nexport async function composeStackRef(\n\tworkspace: NormalizedWorkspace,\n\tstage: string,\n): Promise<{\n\tref: StackRef;\n\tdir: string;\n\tserver?: ReturnType<typeof composeServer>;\n}> {\n\tconst local = stage === workspace.stages.local;\n\tconst server = local\n\t\t? undefined\n\t\t: composeServer({\n\t\t\t\tstage,\n\t\t\t\tlocal,\n\t\t\t\tconfig: workspace.deploy?.compose?.server,\n\t\t\t\tcustom: (await (await secretsStoreFor(workspace, stage)).read(stage))\n\t\t\t\t\t?.custom,\n\t\t\t});\n\tconst override = stackOverrideFile(workspace.root, stage);\n\tconst dir = join(workspace.root, stackDir(stage));\n\tconst ref: StackRef = {\n\t\tproject: composeProject(deployIdentity(workspace, stage)),\n\t\tfile: join(dir, 'docker-compose.yml'),\n\t\t...(existsSync(override) ? { overrides: [override] } : {}),\n\t\tcwd: workspace.root,\n\t\t...(server ? { host: dockerHost(server) } : {}),\n\t};\n\treturn { ref, dir, ...(server ? { server } : {}) };\n}\n\n/** `gkm compose --stage <stage> --destroy`. */\nexport async function composeDestroyCommand(\n\toptions: ComposeDestroyOptions,\n\tdeps: ComposeDestroyDeps = {},\n): Promise<void> {\n\tconst log = deps.log ?? ((line: string) => console.log(line));\n\tconst env = deps.env ?? process.env;\n\tconst cwd = resolve(options.cwd ?? process.cwd());\n\tconst { workspace } = await loadWorkspaceConfig(cwd);\n\tconst { stage } = options;\n\tconst local = stage === workspace.stages.local;\n\tif (!local) assertDeployedStage(workspace.stages, stage);\n\n\tconst identity = deployIdentity(workspace, stage);\n\tconst project = composeProject(identity);\n\tconst interactive = deps.interactive ?? canPrompt;\n\tif (!options.dryRun && !interactive()) {\n\t\tthrow new ComposeDestroyNeedsTerminal(stage, project);\n\t}\n\n\tconst state =\n\t\tdeps.state ??\n\t\t(await createStateStore({\n\t\t\tconfig: local ? undefined : workspace.state,\n\t\t\tworkspaceRoot: workspace.root,\n\t\t\tworkspaceName: workspace.name,\n\t\t\tnamespace: workspace.deploy?.namespace,\n\t\t}));\n\t// Held throughout: a deploy of the stage while it is torn down would\n\t// make what this is deleting.\n\tconst lock = options.dryRun\n\t\t? undefined\n\t\t: await state.lock(stage, { operation: 'destroy' });\n\ttry {\n\t\tconst steps = await plan(workspace, stage, options, deps, state, env);\n\t\tconst { ref } = await composeStackRef(workspace, stage);\n\n\t\tlog(\n\t\t\t`\\n🧨 ${options.dryRun ? 'Would delete' : 'This deletes'} stage '${stage}' of ${workspace.name} for good:\\n`,\n\t\t);\n\t\tconst doing = steps.filter((s) => !s.leftAlone);\n\t\tconst kept = steps.filter((s) => s.leftAlone);\n\t\tfor (const step of doing) log(` - ${step.label}`);\n\t\tif (kept.length > 0) {\n\t\t\tlog('\\n Left where it is:');\n\t\t\tfor (const step of kept) log(` · ${step.label} — ${step.leftAlone}`);\n\t\t}\n\t\tif (!options.secrets) {\n\t\t\tlog(\n\t\t\t\t\"\\n The stage's secrets are kept: a deploy of it again reuses them. --secrets deletes them too.\",\n\t\t\t);\n\t\t}\n\n\t\tif (options.dryRun) {\n\t\t\tlog('\\n--dry-run: nothing was deleted.');\n\t\t\treturn;\n\t\t}\n\n\t\tconst ask =\n\t\t\tdeps.ask ??\n\t\t\t((question: string) =>\n\t\t\t\tprompt(question, {\n\t\t\t\t\tinstead: 'Run it yourself, from a terminal.',\n\t\t\t\t}));\n\t\tconst typed = await ask(`\\n Type ${project} to destroy it: `);\n\t\tif (typed.trim() !== project) {\n\t\t\tthrow new ComposeDestroyNotConfirmed(stage, project);\n\t\t}\n\n\t\tlog('');\n\t\tfor (const step of doing) {\n\t\t\tawait step.run?.();\n\t\t\tfor (const key of step.keys ?? []) {\n\t\t\t\tawait state.deleteResource(stage, key);\n\t\t\t}\n\t\t\tlog(` ✓ ${step.label}`);\n\t\t}\n\t\tlog(`\\n💥 '${stage}' destroyed. ${ref.project} is gone.`);\n\t} finally {\n\t\tawait lock?.release();\n\t}\n}\n\n/** Every step, in the order it is carried out. */\nasync function plan(\n\tworkspace: NormalizedWorkspace,\n\tstage: string,\n\toptions: ComposeDestroyOptions,\n\tdeps: ComposeDestroyDeps,\n\tstate: StateStore,\n\tenv: NodeJS.ProcessEnv,\n): Promise<Step[]> {\n\tconst steps: Step[] = [];\n\tconst resources = (await state.read(stage))?.resources ?? {};\n\tconst records = Object.values(resources);\n\n\t// ── The stack: containers, volumes, its routes on the edge ─────────────\n\tconst { ref, dir, server } = await composeStackRef(workspace, stage);\n\tconst docker = deps.docker ?? dockerCompose;\n\tsteps.push({\n\t\tlabel: `${server ? `on ${sshTarget(server)}: ` : ''}stack ${ref.project} — its containers, its volumes and their data, its routes on ${EDGE_PROJECT}`,\n\t\trun: async () => {\n\t\t\tconst edgeFile = join(dir, `${EDGE_PROJECT}.yml`);\n\t\t\tif (server || existsSync(edgeFile)) {\n\t\t\t\tawait removeEdgeRoutes(\n\t\t\t\t\tdocker,\n\t\t\t\t\tedgeRef(edgeFile, { host: ref.host }),\n\t\t\t\t\tref.project,\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait docker.down(ref, { volumes: true });\n\t\t},\n\t});\n\n\t// ── AWS ─────────────────────────────────────────────────────────────────\n\tconst aws = records.filter((r) =>\n\t\t(AWS_RESOURCE_TYPES as readonly string[]).includes(r.type),\n\t);\n\tlet cdnDns: RecordedDnsRecord[] = [];\n\tif (aws.length > 0) {\n\t\tconst credential = await (\n\t\t\tdeps.awsCredentials ??\n\t\t\t(() =>\n\t\t\t\tawsProvisioningCredentials({\n\t\t\t\t\tstage,\n\t\t\t\t\tenv,\n\t\t\t\t\t...(deps.home ? { home: deps.home } : {}),\n\t\t\t\t}))\n\t\t)();\n\t\tif (!credential) {\n\t\t\tthrow new ComposeDestroyNeedsAwsCredentials(\n\t\t\t\tstage,\n\t\t\t\taws.map((r) => r.key),\n\t\t\t);\n\t\t}\n\t\tconst identity = deployIdentity(workspace, stage);\n\t\tconst planned = await planAwsDestroy({\n\t\t\tresources,\n\t\t\tidentityKey: identity.key,\n\t\t\tscope: identity.scope,\n\t\t\tstage,\n\t\t\tcredential,\n\t\t\t...(deps.aws ?? {}),\n\t\t});\n\t\tfor (const step of planned.steps) steps.push(awsStep(step));\n\t\tcdnDns = providerDnsRecords(workspace, planned.dns);\n\t}\n\n\t// ── DNS: what the stage recorded, and what its CDN was given ───────────\n\tconst recorded = dnsResources(resources).map((r) => ({\n\t\t...r,\n\t\tfqdn: r.fqdn || dnsRecordFqdn(r.domain, r.name),\n\t}));\n\tconst seen = new Set(recorded.map((r) => `${r.fqdn} ${r.type}`));\n\tconst dnsRecords: RecordedDnsRecord[] = [\n\t\t...recorded,\n\t\t...cdnDns.filter((r) => !seen.has(`${r.fqdn} ${r.type}`)),\n\t];\n\tif (dnsRecords.length > 0) {\n\t\t// The providers' tokens are read now: a missing one stops the destroy\n\t\t// before anything is deleted, rather than after the stack is gone.\n\t\tconst dns = workspace.dns ? normalizeDnsConfig(workspace.dns) : {};\n\t\tconst domains = [...new Set(dnsRecords.map((r) => r.domain))]\n\t\t\t.filter((domain) => dns[domain])\n\t\t\t.map((domain) => ({ domain, config: dns[domain]! }));\n\t\tconst tokens = await dnsCredentials(\n\t\t\tstage,\n\t\t\tdomains,\n\t\t\tdeps.credentials ?? storedCredentials({ env }),\n\t\t);\n\t\tconst log = deps.log ?? ((line: string) => console.log(line));\n\t\tsteps.push({\n\t\t\tlabel: `DNS: ${dnsRecords.map((r) => `${r.type} ${r.fqdn}`).join(', ')} — each only while it holds the value gkm wrote`,\n\t\t\tkeys: recorded.map(\n\t\t\t\t(r) => `dns-record:${r.fqdn.toLowerCase()}:${r.type.toUpperCase()}`,\n\t\t\t),\n\t\t\trun: async () => {\n\t\t\t\tawait pruneStackDns(dnsRecords, {\n\t\t\t\t\tstage,\n\t\t\t\t\tdns: workspace.dns,\n\t\t\t\t\tlog,\n\t\t\t\t\tcredentials: {\n\t\t\t\t\t\t...(tokens.godaddy ? { credential: tokens.godaddy } : {}),\n\t\t\t\t\t\tlog,\n\t\t\t\t\t},\n\t\t\t\t\t...(tokens.hostinger ? { hostinger: tokens.hostinger } : {}),\n\t\t\t\t\t...(deps.dnsProviderFor ? { providerFor: deps.dnsProviderFor } : {}),\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\t// ── What gkm cannot delete, and what names nothing ──────────────────────\n\tconst handled = new Set<string>([\n\t\t...(AWS_RESOURCE_TYPES as readonly string[]),\n\t\t'dns-record',\n\t]);\n\tconst values = records.filter((r) => VALUE_TYPES.has(r.type));\n\tfor (const record of records) {\n\t\tif (handled.has(record.type) || VALUE_TYPES.has(record.type)) continue;\n\t\tsteps.push({\n\t\t\tlabel: `${record.type} ${record.id ?? record.key}`,\n\t\t\tleftAlone:\n\t\t\t\tKEPT_TYPES[record.type] ??\n\t\t\t\t`gkm does not delete a ${record.type} yet: delete it by hand`,\n\t\t});\n\t}\n\n\t// ── The stage's secrets ────────────────────────────────────────────────\n\tif (options.secrets) {\n\t\tconst store = await secretsStoreFor(workspace, stage, {\n\t\t\t...(deps.home ? { home: deps.home } : {}),\n\t\t});\n\t\tif (!store.delete) throw new SecretsStoreCannotDelete(stage, store.name);\n\t\tsteps.push({\n\t\t\tlabel: `the stage's secrets, in its ${store.name} store`,\n\t\t\t// The keys the deleted resources were reached by go with them.\n\t\t\tkeys: values.map((r) => r.key),\n\t\t\trun: () => store.delete!(stage),\n\t\t});\n\t} else if (values.length > 0) {\n\t\t// Their resources are gone; the keys stay in the kept secrets, and a\n\t\t// deploy writes them again.\n\t\tsteps.push({\n\t\t\tlabel: `${values.length} record${values.length === 1 ? '' : 's'} of keys written into the secrets`,\n\t\t\tkeys: values.map((r) => r.key),\n\t\t});\n\t}\n\n\treturn steps;\n}\n\nfunction awsStep(step: AwsDestroyStep): Step {\n\tif (step.leftAlone) return { label: step.label, leftAlone: step.leftAlone };\n\treturn {\n\t\tlabel: step.gone\n\t\t\t? `${step.label} (already gone)`\n\t\t\t: step.withUser\n\t\t\t\t? `${step.label} — deleted with its user`\n\t\t\t\t: step.label,\n\t\tkeys: [step.key],\n\t\t...(step.remove ? { run: step.remove } : {}),\n\t};\n}\n\n/** The CDN's records, as the DNS prune takes them. */\nfunction providerDnsRecords(\n\tworkspace: NormalizedWorkspace,\n\trecords: readonly { host: string; type: 'CNAME'; value: string }[],\n): RecordedDnsRecord[] {\n\tconst dns = workspace.dns ? normalizeDnsConfig(workspace.dns) : {};\n\tconst out: RecordedDnsRecord[] = [];\n\tfor (const record of records) {\n\t\tconst host = record.host.toLowerCase().replace(/\\.$/, '');\n\t\tconst domain = findRootDomain(host, dns);\n\t\tif (!domain) continue;\n\t\tconst config = dns[domain]!;\n\t\tout.push({\n\t\t\tfqdn: host,\n\t\t\tdomain,\n\t\t\tname: extractSubdomain(host, domain),\n\t\t\ttype: record.type,\n\t\t\tvalue: record.value.replace(/\\.$/, ''),\n\t\t\tttl: recordTtl(config),\n\t\t\t...(typeof config.provider === 'string'\n\t\t\t\t? { provider: config.provider }\n\t\t\t\t: {}),\n\t\t});\n\t}\n\treturn out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA8EA,MAAa,qBAAqB;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;AAGA,MAAM,eAAe;CAAE,WAAW;CAAa,YAAY;AAAO;;AAGlE,IAAa,6BAAb,cAAgD,SAAS;CAE9C;CACA;CAFV,YACC,IACA,UACC;EACD,MACC,2BAA2B,GAAG,8CAC1B,KAAK,MAAM,WAAW,GAAM,EAAE,yLAInC;EATS,KAAA,KAAA;EACA,KAAA,WAAA;EAST,KAAK,OAAO;CACb;AACD;;AAGA,SAAS,UAAU,OAAwB;CAC1C,MAAM,IAAI;CACV,OAAO,GAAG,QAAQ,GAAG,QAAQ;AAC9B;;AAGA,eAAe,OACd,MACA,SACyB;CACzB,IAAI;EACH,OAAO,MAAM,KAAK;CACnB,SAAS,OAAO;EACf,IAAI,QAAQ,SAAS,UAAU,KAAK,CAAC,GAAG,OAAO,KAAA;EAC/C,MAAM;CACP;AACD;AAEA,MAAM,SAAS,OAAe,IAAI,SAAS,MAAM,WAAW,GAAG,EAA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M,SAAS,IAAI;EACnB,IAAI,KAAK;GACR,MAAM;GACN;GACA,MAAM,iBAAiB,MAAM,MAAM;GACnC,MAAM,OAAO;GACb,OAAO,OAAO,MAAM,QAAQ,OAAO,EAAE;GACrC,KAAK,UAAU,MAAM;GACrB,GAAI,OAAO,OAAO,aAAa,WAC5B,EAAE,UAAU,OAAO,SAAS,IAC5B,CAAC;EACL,CAAC;CACF;CACA,OAAO;AACR"}
|
|
1
|
+
{"version":3,"file":"destroy-igN-bUYa.mjs","names":[],"sources":["../src/providers/s3/destroy.ts","../src/compose/destroy.ts"],"sourcesContent":["/**\n * What `gkm compose --destroy` deletes in the stage's AWS account: each\n * resource a deploy recorded in the stage's state, and only once it is\n * proven gkm's own for this stage.\n *\n * A record alone proves nothing — a deploy records what it found and adopted\n * exactly as what it made (a certificate for the host, a bucket with no\n * tags). So each is checked against what gkm marks its own with: the\n * `gkm:project` and `gkm:stage` tags on a bucket, a user, a certificate, a\n * distribution, a topic or a queue; the stage's own name on an origin access\n * control and a headers policy, which take no tags. What fails the check is\n * left where it is, and said so.\n *\n * Nothing here runs on its own: `planAwsDestroy` reads, and returns a step\n * per resource whose `remove()` the command calls — after the person typed\n * the stage's name — in the order AWS needs: a distribution disabled and\n * gone before its certificate, a user's keys and policies before the user,\n * a bucket emptied before it is deleted.\n */\n\nimport type { ResourceRecord } from '../../deploy/StateStore.js';\nimport { GkmError } from '../../errors.js';\nimport { type AwsProvisioning, awsClientConfig, awsEndpoint } from '../aws.js';\nimport { TAG_PROJECT, TAG_STAGE } from '../iam.js';\nimport { type CdnClients, cdnName, defaultCdnClients } from './cdn.js';\nimport { defaultClients } from './index.js';\nimport { IAM_USER_PATH } from './naming.js';\n\n/** What a destroy step is about, as the person reads it. */\nexport interface AwsDestroyStep {\n\t/** The state record it is kept as: forgotten once it is gone. */\n\tkey: string;\n\tlabel: string;\n\t/** Why it is not deleted. Absent for one that will be. */\n\tleftAlone?: string;\n\t/** Already gone from the account: only its record is forgotten. */\n\tgone?: boolean;\n\t/** Deleted along with its user's step: only its record is forgotten here. */\n\twithUser?: boolean;\n\t/** Deletes it. Absent when it is left alone or already gone. */\n\tremove?: () => Promise<void>;\n}\n\n/** A DNS record a resource here needs, worked out from the resource. */\nexport interface AwsDnsRecord {\n\thost: string;\n\ttype: 'CNAME';\n\tvalue: string;\n}\n\nexport interface AwsDestroyPlan {\n\t/** In the order they are removed. */\n\tsteps: AwsDestroyStep[];\n\t/**\n\t * The records the s3 provider wrote for what it deletes — a CDN's name, a\n\t * certificate's validation — which no state record names.\n\t */\n\tdns: AwsDnsRecord[];\n}\n\nexport interface AwsDestroyInput {\n\tresources: Record<string, ResourceRecord>;\n\t/** `deployIdentity(…).key` — what `gkm:project` holds. */\n\tidentityKey: string;\n\t/** `deployIdentity(…).scope` — what CDN resource names start with. */\n\tscope: string;\n\tstage: string;\n\tcredential: AwsProvisioning;\n\t/** How long a disabled distribution is waited on, and how often asked. */\n\twait?: { timeoutMs: number; intervalMs: number };\n\t/** For tests: where the clients come from. */\n\tclients?: {\n\t\ts3?: typeof defaultClients;\n\t\tcdn?: (credential: AwsProvisioning) => Promise<CdnClients>;\n\t};\n}\n\n/** The record types this plans. Every other is the command's to report. */\nexport const AWS_RESOURCE_TYPES = [\n\t'cloudfront-distribution',\n\t'cloudfront-oac',\n\t'cloudfront-headers',\n\t'acm-certificate',\n\t'sns-subscription',\n\t'sns-topic',\n\t'sqs-queue',\n\t'iam-access-key',\n\t'iam-user',\n\t's3-bucket',\n] as const;\n\n/** A distribution disabled before it is deleted can take this long. */\nconst DISABLE_WAIT = { timeoutMs: 45 * 60_000, intervalMs: 20_000 };\n\n/** A disabled distribution that never finished deploying. */\nexport class DistributionStillDeploying extends GkmError {\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly waitedMs: number,\n\t) {\n\t\tsuper(\n\t\t\t`CloudFront distribution ${id} was disabled, and is still deploying after ` +\n\t\t\t\t`${Math.round(waitedMs / 60_000)} minutes. CloudFront deletes only a ` +\n\t\t\t\t'disabled distribution that has finished deploying. Run the destroy ' +\n\t\t\t\t'again later: everything deleted so far is forgotten, and it carries ' +\n\t\t\t\t'on from here.',\n\t\t);\n\t\tthis.name = 'DistributionStillDeploying';\n\t}\n}\n\n/** What an AWS SDK error is called, whichever field carries it. */\nfunction errorName(error: unknown): string {\n\tconst e = error as { name?: string; Code?: string };\n\treturn e?.Code ?? e?.name ?? '';\n}\n\n/** A read whose \"there is none\" answer is one of `missing`. */\nasync function readOr<T>(\n\tread: () => Promise<T>,\n\tmissing: readonly string[],\n): Promise<T | undefined> {\n\ttry {\n\t\treturn await read();\n\t} catch (error) {\n\t\tif (missing.includes(errorName(error))) return undefined;\n\t\tthrow error;\n\t}\n}\n\nconst sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));\n\n/** Whether a tag list says gkm made it for this project's stage. */\nfunction ours(\n\ttags: readonly { Key?: string; Value?: string }[] | undefined,\n\tinput: Pick<AwsDestroyInput, 'identityKey' | 'stage'>,\n): boolean {\n\tconst of = (key: string) => tags?.find((t) => t.Key === key)?.Value;\n\treturn of(TAG_PROJECT) === input.identityKey && of(TAG_STAGE) === input.stage;\n}\n\nconst NOT_TAGGED =\n\t\"not tagged as this stage's (gkm:project, gkm:stage): gkm found it, it did not make it\";\n\n/** The id after the type in a record's key: `cloudfront-oac:Uploads` → `Uploads`. */\nfunction keyId(record: ResourceRecord): string {\n\treturn record.key.slice(record.key.indexOf(':') + 1);\n}\n\n/** The file server a CDN record is for: `cloudfront-headers:Uploads:cors` → `Uploads`. */\nfunction serverOf(record: ResourceRecord): string {\n\treturn keyId(record).split(':')[0] ?? '';\n}\n\n/**\n * Each AWS resource the stage's state records, checked, in the order it is\n * deleted — and the DNS records the deleted ones were given.\n */\nexport async function planAwsDestroy(\n\tinput: AwsDestroyInput,\n): Promise<AwsDestroyPlan> {\n\tconst steps: AwsDestroyStep[] = [];\n\tconst dns: AwsDnsRecord[] = [];\n\tconst records = Object.values(input.resources);\n\tconst of = (type: string) => records.filter((r) => r.type === type);\n\tconst wait = input.wait ?? DISABLE_WAIT;\n\n\tconst cdnRecords = [\n\t\t...of('cloudfront-distribution'),\n\t\t...of('cloudfront-oac'),\n\t\t...of('cloudfront-headers'),\n\t\t...of('acm-certificate'),\n\t];\n\tif (cdnRecords.length > 0) {\n\t\tconst cdn = await (input.clients?.cdn ?? defaultCdnClients)(\n\t\t\tinput.credential,\n\t\t);\n\t\t// A distribution left alone keeps what it uses: deleting its origin\n\t\t// access control, a headers policy or its certificate would break it.\n\t\tconst kept = new Map<string, string>();\n\t\tfor (const record of of('cloudfront-distribution')) {\n\t\t\tconst step = await distributionStep(cdn, record, input, wait, dns);\n\t\t\tif (step.leftAlone) kept.set(serverOf(record), step.label);\n\t\t\tsteps.push(step);\n\t\t}\n\t\tconst usedBy = async (\n\t\t\trecord: ResourceRecord,\n\t\t\tstep: () => Promise<AwsDestroyStep>,\n\t\t): Promise<AwsDestroyStep> => {\n\t\t\tconst holder = kept.get(serverOf(record));\n\t\t\tif (!holder) return step();\n\t\t\tconst label = (await step()).label;\n\t\t\treturn {\n\t\t\t\tkey: record.key,\n\t\t\t\tlabel,\n\t\t\t\tleftAlone: `used by ${holder}, which is left alone`,\n\t\t\t};\n\t\t};\n\t\tfor (const record of of('cloudfront-oac')) {\n\t\t\tsteps.push(\n\t\t\t\tawait usedBy(record, () => originAccessControlStep(cdn, record, input)),\n\t\t\t);\n\t\t}\n\t\tfor (const record of of('cloudfront-headers')) {\n\t\t\tsteps.push(\n\t\t\t\tawait usedBy(record, () => headersPolicyStep(cdn, record, input)),\n\t\t\t);\n\t\t}\n\t\tfor (const record of of('acm-certificate')) {\n\t\t\t// Its validation record goes only with the certificate itself.\n\t\t\tconst found: AwsDnsRecord[] = [];\n\t\t\tconst step = await usedBy(record, () =>\n\t\t\t\tcertificateStep(cdn, record, input, found),\n\t\t\t);\n\t\t\tif (!step.leftAlone) dns.push(...found);\n\t\t\tsteps.push(step);\n\t\t}\n\t}\n\n\tconst eventRecords = [\n\t\t...of('sns-subscription'),\n\t\t...of('sns-topic'),\n\t\t...of('sqs-queue'),\n\t];\n\tif (eventRecords.length > 0) {\n\t\tconst events = await eventClients(input.credential, records);\n\t\tfor (const record of of('sns-subscription')) {\n\t\t\tsteps.push(subscriptionStep(events, record));\n\t\t}\n\t\tfor (const record of of('sns-topic')) {\n\t\t\tsteps.push(await topicStep(events, record, input));\n\t\t}\n\t\tfor (const record of of('sqs-queue')) {\n\t\t\tsteps.push(await queueStep(events, record, input));\n\t\t}\n\t}\n\n\tconst users = of('iam-user');\n\tconst keys = of('iam-access-key');\n\tconst buckets = of('s3-bucket');\n\tif (users.length + keys.length + buckets.length > 0) {\n\t\tconst global = await (input.clients?.s3 ?? defaultClients)(\n\t\t\tinput.credential,\n\t\t\tregionOf(buckets[0]) ?? 'us-east-1',\n\t\t);\n\t\tconst userSteps = new Map<string, AwsDestroyStep>();\n\t\tfor (const record of users) {\n\t\t\tconst step = await userStep(global, record, input);\n\t\t\tuserSteps.set(record.id ?? '', step);\n\t\t\tsteps.push(step);\n\t\t}\n\t\t// A key goes with its user, and is checked through it.\n\t\tfor (const record of keys) {\n\t\t\tconst user = (record.data as { user?: string } | undefined)?.user;\n\t\t\tconst owner = user ? userSteps.get(user) : undefined;\n\t\t\tsteps.push({\n\t\t\t\tkey: record.key,\n\t\t\t\tlabel: `IAM access key ${record.id ?? ''} of ${user ?? 'an unknown user'}`,\n\t\t\t\t...(owner?.leftAlone\n\t\t\t\t\t? { leftAlone: `its user is left alone: ${owner.leftAlone}` }\n\t\t\t\t\t: owner\n\t\t\t\t\t\t? { withUser: true }\n\t\t\t\t\t\t: { leftAlone: 'its user is not one this stage recorded' }),\n\t\t\t});\n\t\t}\n\t\tfor (const record of buckets) {\n\t\t\tconst region = regionOf(record) ?? global.region;\n\t\t\tconst clients =\n\t\t\t\tregion === global.region\n\t\t\t\t\t? global\n\t\t\t\t\t: await (input.clients?.s3 ?? defaultClients)(\n\t\t\t\t\t\t\tinput.credential,\n\t\t\t\t\t\t\tregion,\n\t\t\t\t\t\t);\n\t\t\tsteps.push(await bucketStep(clients, record, input));\n\t\t}\n\t}\n\n\treturn { steps, dns };\n}\n\nfunction regionOf(record: ResourceRecord | undefined): string | undefined {\n\treturn (record?.data as { region?: string } | undefined)?.region;\n}\n\n// ---------------------------------------------------------------------------\n// CloudFront and ACM\n// ---------------------------------------------------------------------------\n\nasync function distributionStep(\n\t{ CF, cloudfront }: CdnClients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n\twait: { timeoutMs: number; intervalMs: number },\n\tdns: AwsDnsRecord[],\n): Promise<AwsDestroyStep> {\n\tconst id = record.id ?? '';\n\tconst found = await readOr(\n\t\t() => cloudfront.send(new CF.GetDistributionCommand({ Id: id })),\n\t\t['NoSuchDistribution'],\n\t);\n\tconst distribution = found?.Distribution;\n\tconst aliases = distribution?.DistributionConfig?.Aliases?.Items ?? [];\n\tconst label = `CloudFront distribution ${id}${aliases.length ? ` (${aliases.join(', ')})` : ''}`;\n\tif (!distribution) return { key: record.key, label, gone: true };\n\n\t// Its tags, or the comment gkm writes on every distribution it makes —\n\t// `gkm <project> <stage> <file server>`, which nothing else writes.\n\tconst tags = await cloudfront.send(\n\t\tnew CF.ListTagsForResourceCommand({ Resource: distribution.ARN }),\n\t);\n\tconst comment = `gkm ${input.identityKey} ${input.stage} ${serverOf(record)}`;\n\tconst marked =\n\t\tdistribution.DistributionConfig?.Comment === comment.slice(0, 128);\n\tif (!ours(tags.Tags?.Items, input) && !marked) {\n\t\treturn {\n\t\t\tkey: record.key,\n\t\t\tlabel,\n\t\t\tleftAlone: `${NOT_TAGGED}, and its comment is not \"${comment}\"`,\n\t\t};\n\t}\n\tfor (const host of aliases) {\n\t\tdns.push({ host, type: 'CNAME', value: distribution.DomainName ?? '' });\n\t}\n\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tlet current = await cloudfront.send(\n\t\t\t\tnew CF.GetDistributionConfigCommand({ Id: id }),\n\t\t\t);\n\t\t\tif (current.DistributionConfig?.Enabled) {\n\t\t\t\tawait cloudfront.send(\n\t\t\t\t\tnew CF.UpdateDistributionCommand({\n\t\t\t\t\t\tId: id,\n\t\t\t\t\t\tIfMatch: current.ETag,\n\t\t\t\t\t\tDistributionConfig: {\n\t\t\t\t\t\t\t...current.DistributionConfig,\n\t\t\t\t\t\t\tEnabled: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst started = Date.now();\n\t\t\tfor (;;) {\n\t\t\t\tconst state = await cloudfront.send(\n\t\t\t\t\tnew CF.GetDistributionCommand({ Id: id }),\n\t\t\t\t);\n\t\t\t\tif (state.Distribution?.Status === 'Deployed') break;\n\t\t\t\tif (Date.now() - started > wait.timeoutMs) {\n\t\t\t\t\tthrow new DistributionStillDeploying(id, Date.now() - started);\n\t\t\t\t}\n\t\t\t\tawait sleep(wait.intervalMs);\n\t\t\t}\n\t\t\tcurrent = await cloudfront.send(\n\t\t\t\tnew CF.GetDistributionConfigCommand({ Id: id }),\n\t\t\t);\n\t\t\tawait cloudfront.send(\n\t\t\t\tnew CF.DeleteDistributionCommand({ Id: id, IfMatch: current.ETag }),\n\t\t\t);\n\t\t},\n\t};\n}\n\nasync function originAccessControlStep(\n\t{ CF, cloudfront }: CdnClients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n): Promise<AwsDestroyStep> {\n\tconst id = record.id ?? '';\n\tconst expected = cdnName(input.scope, input.stage, keyId(record));\n\tconst label = `CloudFront origin access control ${expected}`;\n\tconst found = await readOr(\n\t\t() => cloudfront.send(new CF.GetOriginAccessControlCommand({ Id: id })),\n\t\t['NoSuchOriginAccessControl'],\n\t);\n\tif (!found) return { key: record.key, label, gone: true };\n\tconst name = found.OriginAccessControl?.OriginAccessControlConfig?.Name;\n\tif (name !== expected) {\n\t\treturn {\n\t\t\tkey: record.key,\n\t\t\tlabel,\n\t\t\tleftAlone: `named ${name}, not this stage's ${expected}`,\n\t\t};\n\t}\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tconst { ETag } = await cloudfront.send(\n\t\t\t\tnew CF.GetOriginAccessControlCommand({ Id: id }),\n\t\t\t);\n\t\t\tawait cloudfront.send(\n\t\t\t\tnew CF.DeleteOriginAccessControlCommand({ Id: id, IfMatch: ETag }),\n\t\t\t);\n\t\t},\n\t};\n}\n\nasync function headersPolicyStep(\n\t{ CF, cloudfront }: CdnClients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n): Promise<AwsDestroyStep> {\n\tconst id = record.id ?? '';\n\t// `cloudfront-headers:<server>:<kind>`\n\tconst [server = '', kind = ''] = keyId(record).split(':');\n\tconst expected = `${cdnName(input.scope, input.stage, server)}-${kind}`;\n\tconst label = `CloudFront response headers policy ${expected}`;\n\tconst found = await readOr(\n\t\t() =>\n\t\t\tcloudfront.send(new CF.GetResponseHeadersPolicyConfigCommand({ Id: id })),\n\t\t['NoSuchResponseHeadersPolicy'],\n\t);\n\tif (!found) return { key: record.key, label, gone: true };\n\tconst name = found.ResponseHeadersPolicyConfig?.Name;\n\tif (name !== expected) {\n\t\treturn {\n\t\t\tkey: record.key,\n\t\t\tlabel,\n\t\t\tleftAlone: `named ${name}, not this stage's ${expected}`,\n\t\t};\n\t}\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tconst { ETag } = await cloudfront.send(\n\t\t\t\tnew CF.GetResponseHeadersPolicyConfigCommand({ Id: id }),\n\t\t\t);\n\t\t\tawait cloudfront.send(\n\t\t\t\tnew CF.DeleteResponseHeadersPolicyCommand({ Id: id, IfMatch: ETag }),\n\t\t\t);\n\t\t},\n\t};\n}\n\nasync function certificateStep(\n\t{ ACM, acm }: CdnClients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n\tdns: AwsDnsRecord[],\n): Promise<AwsDestroyStep> {\n\tconst arn = record.id ?? '';\n\tconst host = (record.data as { host?: string } | undefined)?.host ?? arn;\n\tconst label = `ACM certificate ${host} (us-east-1)`;\n\tconst found = await readOr(\n\t\t() => acm.send(new ACM.DescribeCertificateCommand({ CertificateArn: arn })),\n\t\t['ResourceNotFoundException'],\n\t);\n\tif (!found?.Certificate) return { key: record.key, label, gone: true };\n\tconst tags = await acm.send(\n\t\tnew ACM.ListTagsForCertificateCommand({ CertificateArn: arn }),\n\t);\n\tif (!ours(tags.Tags, input)) {\n\t\treturn { key: record.key, label, leftAlone: NOT_TAGGED };\n\t}\n\tfor (const option of found.Certificate.DomainValidationOptions ?? []) {\n\t\tconst r = option.ResourceRecord;\n\t\tif (r?.Name && r.Value && r.Type === 'CNAME') {\n\t\t\tdns.push({ host: r.Name, type: 'CNAME', value: r.Value });\n\t\t}\n\t}\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tawait acm.send(new ACM.DeleteCertificateCommand({ CertificateArn: arn }));\n\t\t},\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// SNS and SQS\n// ---------------------------------------------------------------------------\n\ninterface EventClients {\n\tSNS: typeof import('@aws-sdk/client-sns');\n\tSQS: typeof import('@aws-sdk/client-sqs');\n\tsns: (\n\t\tregion: string,\n\t) => Promise<InstanceType<typeof import('@aws-sdk/client-sns')['SNSClient']>>;\n\tsqs: (\n\t\tregion: string,\n\t) => Promise<InstanceType<typeof import('@aws-sdk/client-sqs')['SQSClient']>>;\n}\n\nasync function eventClients(\n\tcredential: AwsProvisioning,\n\t_records: readonly ResourceRecord[],\n): Promise<EventClients> {\n\tconst SNS = await import('@aws-sdk/client-sns');\n\tconst SQS = await import('@aws-sdk/client-sqs');\n\tconst sns = new Map<string, InstanceType<typeof SNS.SNSClient>>();\n\tconst sqs = new Map<string, InstanceType<typeof SQS.SQSClient>>();\n\treturn {\n\t\tSNS,\n\t\tSQS,\n\t\tsns: async (region) => {\n\t\t\tif (!sns.has(region)) {\n\t\t\t\tconst endpoint = awsEndpoint(process.env, 'SNS');\n\t\t\t\tsns.set(\n\t\t\t\t\tregion,\n\t\t\t\t\tnew SNS.SNSClient({\n\t\t\t\t\t\t...(await awsClientConfig(credential, region)),\n\t\t\t\t\t\t...(endpoint ? { endpoint } : {}),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn sns.get(region)!;\n\t\t},\n\t\tsqs: async (region) => {\n\t\t\tif (!sqs.has(region)) {\n\t\t\t\tconst endpoint = awsEndpoint(process.env, 'SQS');\n\t\t\t\tsqs.set(\n\t\t\t\t\tregion,\n\t\t\t\t\tnew SQS.SQSClient({\n\t\t\t\t\t\t...(await awsClientConfig(credential, region)),\n\t\t\t\t\t\t...(endpoint ? { endpoint } : {}),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn sqs.get(region)!;\n\t\t},\n\t};\n}\n\n/** `arn:aws:sns:<region>:<account>:<name>` */\nfunction arnParts(arn: string) {\n\tconst [, , , region = '', account = '', ...rest] = arn.split(':');\n\treturn { region, account, name: rest.join(':') };\n}\n\nfunction subscriptionStep(\n\t{ SNS, sns }: EventClients,\n\trecord: ResourceRecord,\n): AwsDestroyStep {\n\tconst arn = record.id ?? '';\n\tconst label = `SNS subscription ${keyId(record)}`;\n\t// Made by gkm, to its own push endpoint: a pending one has no ARN yet.\n\tif (!arn.startsWith('arn:')) return { key: record.key, label, gone: true };\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tconst client = await sns(arnParts(arn).region);\n\t\t\tawait readOr(\n\t\t\t\t() => client.send(new SNS.UnsubscribeCommand({ SubscriptionArn: arn })),\n\t\t\t\t['NotFound', 'NotFoundException'],\n\t\t\t);\n\t\t},\n\t};\n}\n\nasync function topicStep(\n\t{ SNS, sns }: EventClients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n): Promise<AwsDestroyStep> {\n\tconst arn = record.id ?? '';\n\tconst label = `SNS topic ${arnParts(arn).name}`;\n\tconst client = await sns(arnParts(arn).region);\n\tconst tags = await readOr(\n\t\t() => client.send(new SNS.ListTagsForResourceCommand({ ResourceArn: arn })),\n\t\t[\n\t\t\t'NotFound',\n\t\t\t'NotFoundException',\n\t\t\t'ResourceNotFound',\n\t\t\t'ResourceNotFoundException',\n\t\t],\n\t);\n\tif (!tags) return { key: record.key, label, gone: true };\n\tif (!ours(tags.Tags, input)) {\n\t\treturn { key: record.key, label, leftAlone: NOT_TAGGED };\n\t}\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tawait client.send(new SNS.DeleteTopicCommand({ TopicArn: arn }));\n\t\t},\n\t};\n}\n\nasync function queueStep(\n\t{ SQS, sqs }: EventClients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n): Promise<AwsDestroyStep> {\n\tconst arn = record.id ?? '';\n\tconst { region, account, name } = arnParts(arn);\n\tconst label = `SQS queue ${name}`;\n\tconst client = await sqs(region);\n\tconst url = await readOr(\n\t\t() =>\n\t\t\tclient.send(\n\t\t\t\tnew SQS.GetQueueUrlCommand({\n\t\t\t\t\tQueueName: name,\n\t\t\t\t\tQueueOwnerAWSAccountId: account,\n\t\t\t\t}),\n\t\t\t),\n\t\t['QueueDoesNotExist', 'AWS.SimpleQueueService.NonExistentQueue'],\n\t);\n\tif (!url?.QueueUrl) return { key: record.key, label, gone: true };\n\tconst queueUrl = url.QueueUrl;\n\tconst tags = await client.send(\n\t\tnew SQS.ListQueueTagsCommand({ QueueUrl: queueUrl }),\n\t);\n\tconst list = Object.entries(tags.Tags ?? {}).map(([Key, Value]) => ({\n\t\tKey,\n\t\tValue,\n\t}));\n\tif (!ours(list, input)) {\n\t\treturn { key: record.key, label, leftAlone: NOT_TAGGED };\n\t}\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tawait client.send(new SQS.DeleteQueueCommand({ QueueUrl: queueUrl }));\n\t\t},\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// IAM and S3\n// ---------------------------------------------------------------------------\n\ntype S3Clients = Awaited<ReturnType<typeof defaultClients>>;\n\nasync function userStep(\n\t{ IAM, iam }: S3Clients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n): Promise<AwsDestroyStep> {\n\tconst name = record.id ?? '';\n\tconst label = `IAM user ${name}, its access keys and policies`;\n\tconst found = await readOr(\n\t\t() => iam.send(new IAM.GetUserCommand({ UserName: name })),\n\t\t['NoSuchEntity', 'NoSuchEntityException'],\n\t);\n\tif (!found?.User) return { key: record.key, label, gone: true };\n\tconst tags = await iam.send(new IAM.ListUserTagsCommand({ UserName: name }));\n\tif (found.User.Path !== IAM_USER_PATH || !ours(tags.Tags, input)) {\n\t\treturn { key: record.key, label, leftAlone: NOT_TAGGED };\n\t}\n\treturn {\n\t\tkey: record.key,\n\t\tlabel,\n\t\tremove: async () => {\n\t\t\tconst keys = await iam.send(\n\t\t\t\tnew IAM.ListAccessKeysCommand({ UserName: name }),\n\t\t\t);\n\t\t\tfor (const key of keys.AccessKeyMetadata ?? []) {\n\t\t\t\tawait iam.send(\n\t\t\t\t\tnew IAM.DeleteAccessKeyCommand({\n\t\t\t\t\t\tUserName: name,\n\t\t\t\t\t\tAccessKeyId: key.AccessKeyId,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst inline = await iam.send(\n\t\t\t\tnew IAM.ListUserPoliciesCommand({ UserName: name }),\n\t\t\t);\n\t\t\tfor (const policy of inline.PolicyNames ?? []) {\n\t\t\t\tawait iam.send(\n\t\t\t\t\tnew IAM.DeleteUserPolicyCommand({\n\t\t\t\t\t\tUserName: name,\n\t\t\t\t\t\tPolicyName: policy,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst attached = await iam.send(\n\t\t\t\tnew IAM.ListAttachedUserPoliciesCommand({ UserName: name }),\n\t\t\t);\n\t\t\tfor (const policy of attached.AttachedPolicies ?? []) {\n\t\t\t\tawait iam.send(\n\t\t\t\t\tnew IAM.DetachUserPolicyCommand({\n\t\t\t\t\t\tUserName: name,\n\t\t\t\t\t\tPolicyArn: policy.PolicyArn,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait iam.send(new IAM.DeleteUserCommand({ UserName: name }));\n\t\t},\n\t};\n}\n\n/** Every object version and delete marker in a bucket, a page at a time. */\nasync function* bucketVersions({ S3, s3 }: S3Clients, bucket: string) {\n\tlet KeyMarker: string | undefined;\n\tlet VersionIdMarker: string | undefined;\n\tfor (;;) {\n\t\tconst page = await s3.send(\n\t\t\tnew S3.ListObjectVersionsCommand({\n\t\t\t\tBucket: bucket,\n\t\t\t\t...(KeyMarker ? { KeyMarker } : {}),\n\t\t\t\t...(VersionIdMarker ? { VersionIdMarker } : {}),\n\t\t\t}),\n\t\t);\n\t\tconst objects = [...(page.Versions ?? []), ...(page.DeleteMarkers ?? [])]\n\t\t\t.filter((o) => o.Key)\n\t\t\t.map((o) => ({\n\t\t\t\tKey: o.Key!,\n\t\t\t\t// `null` is the one version an unversioned bucket's object has:\n\t\t\t\t// named or not, the same object is deleted.\n\t\t\t\t...(o.VersionId && o.VersionId !== 'null'\n\t\t\t\t\t? { VersionId: o.VersionId }\n\t\t\t\t\t: {}),\n\t\t\t}));\n\t\tif (objects.length > 0) yield objects;\n\t\tif (!page.IsTruncated) return;\n\t\tKeyMarker = page.NextKeyMarker;\n\t\tVersionIdMarker = page.NextVersionIdMarker;\n\t}\n}\n\nasync function bucketStep(\n\tclients: S3Clients,\n\trecord: ResourceRecord,\n\tinput: AwsDestroyInput,\n): Promise<AwsDestroyStep> {\n\tconst { S3, s3 } = clients;\n\tconst bucket = record.id ?? '';\n\tconst tagging = await readOr(\n\t\t() => s3.send(new S3.GetBucketTaggingCommand({ Bucket: bucket })),\n\t\t['NoSuchBucket', 'NoSuchTagSet', 'NoSuchTagSetError'],\n\t);\n\tconst exists = await readOr(\n\t\t() => s3.send(new S3.HeadBucketCommand({ Bucket: bucket })),\n\t\t['NotFound', 'NoSuchBucket'],\n\t);\n\tconst base = `S3 bucket ${bucket}`;\n\tif (!exists) return { key: record.key, label: base, gone: true };\n\tif (!ours(tagging?.TagSet, input)) {\n\t\treturn { key: record.key, label: base, leftAlone: NOT_TAGGED };\n\t}\n\tlet count = 0;\n\tfor await (const page of bucketVersions(clients, bucket))\n\t\tcount += page.length;\n\treturn {\n\t\tkey: record.key,\n\t\tlabel: `${base}, emptied first: ${count} object version${count === 1 ? '' : 's'}`,\n\t\tremove: async () => {\n\t\t\t// Until it lists nothing: deleting a version-less object in a bucket\n\t\t\t// whose versioning was suspended leaves a delete marker behind.\n\t\t\tfor (let pass = 0; pass < 5; pass++) {\n\t\t\t\tlet deleted = 0;\n\t\t\t\tfor await (const page of bucketVersions(clients, bucket)) {\n\t\t\t\t\t// At most a thousand a call.\n\t\t\t\t\tfor (let i = 0; i < page.length; i += 1000) {\n\t\t\t\t\t\tawait s3.send(\n\t\t\t\t\t\t\tnew S3.DeleteObjectsCommand({\n\t\t\t\t\t\t\t\tBucket: bucket,\n\t\t\t\t\t\t\t\tDelete: { Objects: page.slice(i, i + 1000), Quiet: true },\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tdeleted += page.length;\n\t\t\t\t}\n\t\t\t\tif (deleted === 0) break;\n\t\t\t}\n\t\t\tawait s3.send(new S3.DeleteBucketCommand({ Bucket: bucket }));\n\t\t},\n\t};\n}\n","/**\n * `gkm compose --stage <stage> --destroy`: everything a deploy made for the\n * stage, deleted for good.\n *\n * The one thing in gkm that deletes what a deploy created — a deploy itself\n * never does. So it is careful in three ways:\n *\n * - **Only what is provably gkm's.** Each AWS resource is checked against\n * what gkm marks its own with before it is deleted (see\n * `providers/s3/destroy.ts`); a DNS record only while it still holds the\n * value gkm wrote. What fails is listed, and left where it is.\n * - **Only with a person typing the stage.** The whole plan is printed\n * first, then the compose project's name — `<project>-<stage>` — has to be\n * typed back. Nothing skips that: there is no flag that answers it, and\n * with no terminal to ask at it refuses before reading anything.\n * - **Resumable.** Each resource's record is forgotten as soon as it is gone,\n * so a run that stops part way — a distribution still deploying — carries\n * on from there when it is run again.\n *\n * What other stages or projects share is never touched: the project bucket\n * that holds every stage's state, the shared Traefik edge, the server's own\n * setup (`gkm compose:server`). The stage's secrets are kept unless\n * `--secrets` is passed.\n */\n\nimport { existsSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport type { DnsProvider } from '@geekmidas/edge/dns';\nimport { EDGE_PROJECT } from '@geekmidas/edge/proxy/traefik';\nimport { loadWorkspaceConfig } from '../config';\nimport {\n\ttype CredentialProvider,\n\tstoredCredentials,\n} from '../deploy/credentials.js';\nimport { dnsRecordFqdn, dnsResources } from '../deploy/dnsResources.js';\nimport { deployIdentity } from '../deploy/identity.js';\nimport { createStateStore, type StateStore } from '../deploy/StateStore.js';\nimport {\n\textractSubdomain,\n\tfindRootDomain,\n\tnormalizeDnsConfig,\n} from '../dns/index';\nimport { GkmError } from '../errors';\nimport { canPrompt, prompt } from '../prompt';\nimport {\n\ttype AwsProvisioning,\n\tawsProvisioningCredentials,\n} from '../providers/aws.js';\nimport {\n\tAWS_RESOURCE_TYPES,\n\ttype AwsDestroyInput,\n\ttype AwsDestroyStep,\n\tplanAwsDestroy,\n} from '../providers/s3/destroy.js';\nimport { secretsStoreFor } from '../secrets/store.js';\nimport { stackOverrideFile } from '../target/compose/index';\nimport { assertDeployedStage } from '../workspace/stages.js';\nimport type {\n\tDnsProvider as DnsProviderConfig,\n\tNormalizedWorkspace,\n} from '../workspace/types.js';\nimport {\n\tdnsCredentials,\n\tpruneStackDns,\n\ttype RecordedDnsRecord,\n\trecordTtl,\n} from './dns';\nimport { type ComposeDocker, dockerCompose, type StackRef } from './docker';\nimport { edgeRef, removeEdgeRoutes } from './edge';\nimport { composeServer, dockerHost, sshTarget } from './server';\nimport { composeProject, stackDir } from './stack';\n\nexport interface ComposeDestroyOptions {\n\tcwd?: string;\n\tstage: string;\n\t/** Delete the stage's secrets too. Kept otherwise. */\n\tsecrets?: boolean;\n\t/** Print what would be deleted; delete nothing, ask nothing. */\n\tdryRun?: boolean;\n}\n\nexport interface ComposeDestroyDeps {\n\tdocker?: ComposeDocker;\n\t/** Whether a person is at a terminal to answer. */\n\tinteractive?: () => boolean;\n\t/** Ask the person, and resolve with what they typed. */\n\task?: (question: string) => Promise<string>;\n\t/** Where the DNS providers' tokens come from. */\n\tcredentials?: CredentialProvider;\n\t/** The provider for a domain — `createDnsProvider` by default. */\n\tdnsProviderFor?: (config: DnsProviderConfig) => Promise<DnsProvider | null>;\n\t/**\n\t * How the AWS account's credential is found — the machine's, as a deploy\n\t * finds it, by default.\n\t */\n\tawsCredentials?: () => Promise<AwsProvisioning | undefined>;\n\t/** For tests: the AWS clients and how long a distribution is waited on. */\n\taws?: Pick<AwsDestroyInput, 'clients' | 'wait'>;\n\tstate?: StateStore;\n\tenv?: NodeJS.ProcessEnv;\n\thome?: string;\n\tlog?: (line: string) => void;\n}\n\n/** A destroy with no terminal to type the stage's name at. */\nexport class ComposeDestroyNeedsTerminal extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly project: string,\n\t) {\n\t\tsuper(\n\t\t\t`Destroying '${stage}' deletes everything its deploys made, and asks you to ` +\n\t\t\t\t`type ${project} first — there is no terminal here to ask at, and no flag ` +\n\t\t\t\t'answers it. Run it yourself, from a terminal. `--dry-run` prints what it ' +\n\t\t\t\t'would delete, anywhere.',\n\t\t);\n\t\tthis.name = 'ComposeDestroyNeedsTerminal';\n\t}\n}\n\n/** What was typed was not the project's name. */\nexport class ComposeDestroyNotConfirmed extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly project: string,\n\t) {\n\t\tsuper(\n\t\t\t`Nothing was deleted: destroying '${stage}' needs ${project} typed exactly.`,\n\t\t);\n\t\tthis.name = 'ComposeDestroyNotConfirmed';\n\t}\n}\n\n/** AWS resources to delete, and no credentials to delete them with. */\nexport class ComposeDestroyNeedsAwsCredentials extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly resources: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`'${stage}' has ${resources.length} AWS resource${resources.length === 1 ? '' : 's'} ` +\n\t\t\t\t`to delete (${resources.slice(0, 3).join(', ')}${resources.length > 3 ? ', …' : ''}), ` +\n\t\t\t\t\"and no AWS credentials were found to delete them with. Supply the stage's \" +\n\t\t\t\t'account the way a deploy does — AWS_PROFILE, or AWS_ACCESS_KEY_ID and ' +\n\t\t\t\t'AWS_SECRET_ACCESS_KEY — and run it again. Nothing was deleted.',\n\t\t);\n\t\tthis.name = 'ComposeDestroyNeedsAwsCredentials';\n\t}\n}\n\n/** `--secrets`, and a store that cannot delete. */\nexport class SecretsStoreCannotDelete extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly store: string,\n\t) {\n\t\tsuper(\n\t\t\t`--secrets deletes '${stage}''s secrets, and its store (${store}) has no ` +\n\t\t\t\t'delete(stage). Give the custom store one, or run without --secrets and ' +\n\t\t\t\t'delete them where they are kept. Nothing was deleted.',\n\t\t);\n\t\tthis.name = 'SecretsStoreCannotDelete';\n\t}\n}\n\n/** One line of the plan, and how it is carried out. */\ninterface Step {\n\tlabel: string;\n\tleftAlone?: string;\n\t/** Forgotten from the stage's state once done. */\n\tkeys?: string[];\n\trun?: () => Promise<void>;\n}\n\n/** What a record of each type is to destroy. */\nconst KEPT_TYPES: Record<string, string> = {\n\t// The server's setup — its users, firewall, Docker — is the server's.\n\tserver:\n\t\t\"the server's setup is kept: gkm compose:server made it, for any stage\",\n};\n\n/** Records that name no resource of their own — a key in the secrets. */\nconst VALUE_TYPES = new Set(['url', 'email-from']);\n\n/**\n * The stage's stack: its project on the server (or this machine), as\n * `gkm compose --down` finds it.\n */\nexport async function composeStackRef(\n\tworkspace: NormalizedWorkspace,\n\tstage: string,\n): Promise<{\n\tref: StackRef;\n\tdir: string;\n\tserver?: ReturnType<typeof composeServer>;\n}> {\n\tconst local = stage === workspace.stages.local;\n\tconst server = local\n\t\t? undefined\n\t\t: composeServer({\n\t\t\t\tstage,\n\t\t\t\tlocal,\n\t\t\t\tconfig: workspace.deploy?.compose?.server,\n\t\t\t\tcustom: (await (await secretsStoreFor(workspace, stage)).read(stage))\n\t\t\t\t\t?.custom,\n\t\t\t});\n\tconst override = stackOverrideFile(workspace.root, stage);\n\tconst dir = join(workspace.root, stackDir(stage));\n\tconst ref: StackRef = {\n\t\tproject: composeProject(deployIdentity(workspace, stage)),\n\t\tfile: join(dir, 'docker-compose.yml'),\n\t\t...(existsSync(override) ? { overrides: [override] } : {}),\n\t\tcwd: workspace.root,\n\t\t...(server ? { host: dockerHost(server) } : {}),\n\t};\n\treturn { ref, dir, ...(server ? { server } : {}) };\n}\n\n/** `gkm compose --stage <stage> --destroy`. */\nexport async function composeDestroyCommand(\n\toptions: ComposeDestroyOptions,\n\tdeps: ComposeDestroyDeps = {},\n): Promise<void> {\n\tconst log = deps.log ?? ((line: string) => console.log(line));\n\tconst env = deps.env ?? process.env;\n\tconst cwd = resolve(options.cwd ?? process.cwd());\n\tconst { workspace } = await loadWorkspaceConfig(cwd);\n\tconst { stage } = options;\n\tconst local = stage === workspace.stages.local;\n\tif (!local) assertDeployedStage(workspace.stages, stage);\n\n\tconst identity = deployIdentity(workspace, stage);\n\tconst project = composeProject(identity);\n\tconst interactive = deps.interactive ?? canPrompt;\n\tif (!options.dryRun && !interactive()) {\n\t\tthrow new ComposeDestroyNeedsTerminal(stage, project);\n\t}\n\n\tconst state =\n\t\tdeps.state ??\n\t\t(await createStateStore({\n\t\t\tconfig: local ? undefined : workspace.state,\n\t\t\tworkspaceRoot: workspace.root,\n\t\t\tworkspaceName: workspace.name,\n\t\t\tnamespace: workspace.deploy?.namespace,\n\t\t}));\n\t// Held throughout: a deploy of the stage while it is torn down would\n\t// make what this is deleting.\n\tconst lock = options.dryRun\n\t\t? undefined\n\t\t: await state.lock(stage, { operation: 'destroy' });\n\ttry {\n\t\tconst steps = await plan(workspace, stage, options, deps, state, env);\n\t\tconst { ref } = await composeStackRef(workspace, stage);\n\n\t\tlog(\n\t\t\t`\\n🧨 ${options.dryRun ? 'Would delete' : 'This deletes'} stage '${stage}' of ${workspace.name} for good:\\n`,\n\t\t);\n\t\tconst doing = steps.filter((s) => !s.leftAlone);\n\t\tconst kept = steps.filter((s) => s.leftAlone);\n\t\tfor (const step of doing) log(` - ${step.label}`);\n\t\tif (kept.length > 0) {\n\t\t\tlog('\\n Left where it is:');\n\t\t\tfor (const step of kept) log(` · ${step.label} — ${step.leftAlone}`);\n\t\t}\n\t\tif (!options.secrets) {\n\t\t\tlog(\n\t\t\t\t\"\\n The stage's secrets are kept: a deploy of it again reuses them. --secrets deletes them too.\",\n\t\t\t);\n\t\t}\n\n\t\tif (options.dryRun) {\n\t\t\tlog('\\n--dry-run: nothing was deleted.');\n\t\t\treturn;\n\t\t}\n\n\t\tconst ask =\n\t\t\tdeps.ask ??\n\t\t\t((question: string) =>\n\t\t\t\tprompt(question, {\n\t\t\t\t\tinstead: 'Run it yourself, from a terminal.',\n\t\t\t\t}));\n\t\tconst typed = await ask(`\\n Type ${project} to destroy it: `);\n\t\tif (typed.trim() !== project) {\n\t\t\tthrow new ComposeDestroyNotConfirmed(stage, project);\n\t\t}\n\n\t\tlog('');\n\t\tfor (const step of doing) {\n\t\t\tawait step.run?.();\n\t\t\tfor (const key of step.keys ?? []) {\n\t\t\t\tawait state.deleteResource(stage, key);\n\t\t\t}\n\t\t\tlog(` ✓ ${step.label}`);\n\t\t}\n\t\tlog(`\\n💥 '${stage}' destroyed. ${ref.project} is gone.`);\n\t} finally {\n\t\tawait lock?.release();\n\t}\n}\n\n/** Every step, in the order it is carried out. */\nasync function plan(\n\tworkspace: NormalizedWorkspace,\n\tstage: string,\n\toptions: ComposeDestroyOptions,\n\tdeps: ComposeDestroyDeps,\n\tstate: StateStore,\n\tenv: NodeJS.ProcessEnv,\n): Promise<Step[]> {\n\tconst steps: Step[] = [];\n\tconst resources = (await state.read(stage))?.resources ?? {};\n\tconst records = Object.values(resources);\n\n\t// ── The stack: containers, volumes, its routes on the edge ─────────────\n\tconst { ref, dir, server } = await composeStackRef(workspace, stage);\n\tconst docker = deps.docker ?? dockerCompose;\n\tsteps.push({\n\t\tlabel: `${server ? `on ${sshTarget(server)}: ` : ''}stack ${ref.project} — its containers, its volumes and their data, its routes on ${EDGE_PROJECT}`,\n\t\trun: async () => {\n\t\t\tconst edgeFile = join(dir, `${EDGE_PROJECT}.yml`);\n\t\t\tif (server || existsSync(edgeFile)) {\n\t\t\t\tawait removeEdgeRoutes(\n\t\t\t\t\tdocker,\n\t\t\t\t\tedgeRef(edgeFile, { host: ref.host }),\n\t\t\t\t\tref.project,\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait docker.down(ref, { volumes: true });\n\t\t},\n\t});\n\n\t// ── AWS ─────────────────────────────────────────────────────────────────\n\tconst aws = records.filter((r) =>\n\t\t(AWS_RESOURCE_TYPES as readonly string[]).includes(r.type),\n\t);\n\tlet cdnDns: RecordedDnsRecord[] = [];\n\tif (aws.length > 0) {\n\t\tconst credential = await (\n\t\t\tdeps.awsCredentials ??\n\t\t\t(() =>\n\t\t\t\tawsProvisioningCredentials({\n\t\t\t\t\tstage,\n\t\t\t\t\tenv,\n\t\t\t\t\t...(deps.home ? { home: deps.home } : {}),\n\t\t\t\t}))\n\t\t)();\n\t\tif (!credential) {\n\t\t\tthrow new ComposeDestroyNeedsAwsCredentials(\n\t\t\t\tstage,\n\t\t\t\taws.map((r) => r.key),\n\t\t\t);\n\t\t}\n\t\tconst identity = deployIdentity(workspace, stage);\n\t\tconst planned = await planAwsDestroy({\n\t\t\tresources,\n\t\t\tidentityKey: identity.key,\n\t\t\tscope: identity.scope,\n\t\t\tstage,\n\t\t\tcredential,\n\t\t\t...(deps.aws ?? {}),\n\t\t});\n\t\tfor (const step of planned.steps) steps.push(awsStep(step));\n\t\tcdnDns = providerDnsRecords(workspace, planned.dns);\n\t}\n\n\t// ── DNS: what the stage recorded, and what its CDN was given ───────────\n\tconst recorded = dnsResources(resources).map((r) => ({\n\t\t...r,\n\t\tfqdn: r.fqdn || dnsRecordFqdn(r.domain, r.name),\n\t}));\n\tconst seen = new Set(recorded.map((r) => `${r.fqdn} ${r.type}`));\n\tconst dnsRecords: RecordedDnsRecord[] = [\n\t\t...recorded,\n\t\t...cdnDns.filter((r) => !seen.has(`${r.fqdn} ${r.type}`)),\n\t];\n\tif (dnsRecords.length > 0) {\n\t\t// The providers' tokens are read now: a missing one stops the destroy\n\t\t// before anything is deleted, rather than after the stack is gone.\n\t\tconst dns = workspace.dns ? normalizeDnsConfig(workspace.dns) : {};\n\t\tconst domains = [...new Set(dnsRecords.map((r) => r.domain))]\n\t\t\t.filter((domain) => dns[domain])\n\t\t\t.map((domain) => ({ domain, config: dns[domain]! }));\n\t\tconst tokens = await dnsCredentials(\n\t\t\tstage,\n\t\t\tdomains,\n\t\t\tdeps.credentials ?? storedCredentials({ env }),\n\t\t);\n\t\tconst log = deps.log ?? ((line: string) => console.log(line));\n\t\tsteps.push({\n\t\t\tlabel: `DNS: ${dnsRecords.map((r) => `${r.type} ${r.fqdn}`).join(', ')} — each only while it holds the value gkm wrote`,\n\t\t\tkeys: recorded.map(\n\t\t\t\t(r) => `dns-record:${r.fqdn.toLowerCase()}:${r.type.toUpperCase()}`,\n\t\t\t),\n\t\t\trun: async () => {\n\t\t\t\tawait pruneStackDns(dnsRecords, {\n\t\t\t\t\tstage,\n\t\t\t\t\tdns: workspace.dns,\n\t\t\t\t\tlog,\n\t\t\t\t\tcredentials: {\n\t\t\t\t\t\t...(tokens.godaddy ? { credential: tokens.godaddy } : {}),\n\t\t\t\t\t\tlog,\n\t\t\t\t\t},\n\t\t\t\t\t...(tokens.hostinger ? { hostinger: tokens.hostinger } : {}),\n\t\t\t\t\t...(deps.dnsProviderFor ? { providerFor: deps.dnsProviderFor } : {}),\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\t// ── What gkm cannot delete, and what names nothing ──────────────────────\n\tconst handled = new Set<string>([\n\t\t...(AWS_RESOURCE_TYPES as readonly string[]),\n\t\t'dns-record',\n\t]);\n\tconst values = records.filter((r) => VALUE_TYPES.has(r.type));\n\tfor (const record of records) {\n\t\tif (handled.has(record.type) || VALUE_TYPES.has(record.type)) continue;\n\t\tsteps.push({\n\t\t\tlabel: `${record.type} ${record.id ?? record.key}`,\n\t\t\tleftAlone:\n\t\t\t\tKEPT_TYPES[record.type] ??\n\t\t\t\t`gkm does not delete a ${record.type} yet: delete it by hand`,\n\t\t});\n\t}\n\n\t// ── The stage's secrets ────────────────────────────────────────────────\n\tif (options.secrets) {\n\t\tconst store = await secretsStoreFor(workspace, stage, {\n\t\t\t...(deps.home ? { home: deps.home } : {}),\n\t\t});\n\t\tif (!store.delete) throw new SecretsStoreCannotDelete(stage, store.name);\n\t\tsteps.push({\n\t\t\tlabel: `the stage's secrets, in its ${store.name} store`,\n\t\t\t// The keys the deleted resources were reached by go with them.\n\t\t\tkeys: values.map((r) => r.key),\n\t\t\trun: () => store.delete!(stage),\n\t\t});\n\t} else if (values.length > 0) {\n\t\t// Their resources are gone; the keys stay in the kept secrets, and a\n\t\t// deploy writes them again.\n\t\tsteps.push({\n\t\t\tlabel: `${values.length} record${values.length === 1 ? '' : 's'} of keys written into the secrets`,\n\t\t\tkeys: values.map((r) => r.key),\n\t\t});\n\t}\n\n\treturn steps;\n}\n\nfunction awsStep(step: AwsDestroyStep): Step {\n\tif (step.leftAlone) return { label: step.label, leftAlone: step.leftAlone };\n\treturn {\n\t\tlabel: step.gone\n\t\t\t? `${step.label} (already gone)`\n\t\t\t: step.withUser\n\t\t\t\t? `${step.label} — deleted with its user`\n\t\t\t\t: step.label,\n\t\tkeys: [step.key],\n\t\t...(step.remove ? { run: step.remove } : {}),\n\t};\n}\n\n/** The CDN's records, as the DNS prune takes them. */\nfunction providerDnsRecords(\n\tworkspace: NormalizedWorkspace,\n\trecords: readonly { host: string; type: 'CNAME'; value: string }[],\n): RecordedDnsRecord[] {\n\tconst dns = workspace.dns ? normalizeDnsConfig(workspace.dns) : {};\n\tconst out: RecordedDnsRecord[] = [];\n\tfor (const record of records) {\n\t\tconst host = record.host.toLowerCase().replace(/\\.$/, '');\n\t\tconst domain = findRootDomain(host, dns);\n\t\tif (!domain) continue;\n\t\tconst config = dns[domain]!;\n\t\tout.push({\n\t\t\tfqdn: host,\n\t\t\tdomain,\n\t\t\tname: extractSubdomain(host, domain),\n\t\t\ttype: record.type,\n\t\t\tvalue: record.value.replace(/\\.$/, ''),\n\t\t\tttl: recordTtl(config),\n\t\t\t...(typeof config.provider === 'string'\n\t\t\t\t? { provider: config.provider }\n\t\t\t\t: {}),\n\t\t});\n\t}\n\treturn out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA8EA,MAAa,qBAAqB;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;AAGA,MAAM,eAAe;CAAE,WAAW;CAAa,YAAY;AAAO;;AAGlE,IAAa,6BAAb,cAAgD,SAAS;CAE9C;CACA;CAFV,YACC,IACA,UACC;EACD,MACC,2BAA2B,GAAG,8CAC1B,KAAK,MAAM,WAAW,GAAM,EAAE,yLAInC;EATS,KAAA,KAAA;EACA,KAAA,WAAA;EAST,KAAK,OAAO;CACb;AACD;;AAGA,SAAS,UAAU,OAAwB;CAC1C,MAAM,IAAI;CACV,OAAO,GAAG,QAAQ,GAAG,QAAQ;AAC9B;;AAGA,eAAe,OACd,MACA,SACyB;CACzB,IAAI;EACH,OAAO,MAAM,KAAK;CACnB,SAAS,OAAO;EACf,IAAI,QAAQ,SAAS,UAAU,KAAK,CAAC,GAAG,OAAO,KAAA;EAC/C,MAAM;CACP;AACD;AAEA,MAAM,SAAS,OAAe,IAAI,SAAS,MAAM,WAAW,GAAG,EAAE,CAAC;;AAGlE,SAAS,KACR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KAAK;GACR,MAAM;GACN;GACA,MAAM,iBAAiB,MAAM,MAAM;GACnC,MAAM,OAAO;GACb,OAAO,OAAO,MAAM,QAAQ,OAAO,EAAE;GACrC,KAAK,UAAU,MAAM;GACrB,GAAI,OAAO,OAAO,aAAa,WAC5B,EAAE,UAAU,OAAO,SAAS,IAC5B,CAAC;EACL,CAAC;CACF;CACA,OAAO;AACR"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_define = require("./define-zKgLY65H.cjs");
|
|
2
|
-
const require_engine = require("./engine-
|
|
2
|
+
const require_engine = require("./engine-DBuoGHhE.cjs");
|
|
3
3
|
//#region src/target/dokploy/index.ts
|
|
4
4
|
/**
|
|
5
5
|
* The built-in `dokploy` target: the Dokploy engine `gkm deploy` has always
|
|
@@ -35,4 +35,4 @@ const dokployTarget = require_define.defineTarget({
|
|
|
35
35
|
//#endregion
|
|
36
36
|
exports.dokployTarget = dokployTarget;
|
|
37
37
|
|
|
38
|
-
//# sourceMappingURL=dokploy-
|
|
38
|
+
//# sourceMappingURL=dokploy-BSDyt4OK.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dokploy-
|
|
1
|
+
{"version":3,"file":"dokploy-BSDyt4OK.cjs","names":["defineTarget","validateDokploy","planDokploy","provisionDokploy","releaseDokploy","verifyDokploy","rollbackDokploy","dokployResult"],"sources":["../src/target/dokploy/index.ts"],"sourcesContent":["/**\n * The built-in `dokploy` target: the Dokploy engine `gkm deploy` has always\n * run, behind the phases.\n *\n * - `provision`: the project, environment and registry, and what the\n * manifest declares — its databases' roles applied over a port published\n * for the purpose.\n * - `release`: the stage's migrations, then each image built and pushed\n * beside its application and deployed, waited on until Dokploy has\n * finished; backends first and checked before any site is released.\n * - `verify`: each site answering its health check.\n * - `rollback`: what failed — or, `--atomic`, everything the run released —\n * pointed back at the image it ran before.\n */\n\nimport { defineTarget } from '../define';\nimport {\n\ttype DokployRun,\n\tdokployResult,\n\tplanDokploy,\n\tprovisionDokploy,\n\treleaseDokploy,\n\trollbackDokploy,\n\tvalidateDokploy,\n\tverifyDokploy,\n} from './engine';\n\nexport const dokployTarget = defineTarget<undefined, DokployRun>({\n\tname: 'dokploy',\n\truntime: 'server',\n\tcapabilities: { rollback: true, migrations: 'target', images: true },\n\tcredentials: ['dokploy', 'registry'],\n\tvalidate: (ctx) => validateDokploy(ctx),\n\tplan: (_ctx, run) => planDokploy(run),\n\tprovision: (_ctx, run) => provisionDokploy(run),\n\trelease: (_ctx, run) => releaseDokploy(run),\n\tverify: (_ctx, run) => verifyDokploy(run),\n\trollback: (_ctx, run, failure) => rollbackDokploy(run, failure),\n\tresult: (_ctx, run) => dokployResult(run),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;AA2BA,MAAa,gBAAgBA,eAAAA,aAAoC;CAChE,MAAM;CACN,SAAS;CACT,cAAc;EAAE,UAAU;EAAM,YAAY;EAAU,QAAQ;CAAK;CACnE,aAAa,CAAC,WAAW,UAAU;CACnC,WAAW,QAAQC,eAAAA,gBAAgB,GAAG;CACtC,OAAO,MAAM,QAAQC,eAAAA,YAAY,GAAG;CACpC,YAAY,MAAM,QAAQC,eAAAA,iBAAiB,GAAG;CAC9C,UAAU,MAAM,QAAQC,eAAAA,eAAe,GAAG;CAC1C,SAAS,MAAM,QAAQC,eAAAA,cAAc,GAAG;CACxC,WAAW,MAAM,KAAK,YAAYC,eAAAA,gBAAgB,KAAK,OAAO;CAC9D,SAAS,MAAM,QAAQC,eAAAA,cAAc,GAAG;AACzC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as defineTarget } from "./define-BfrNaY82.mjs";
|
|
2
|
-
import { a as dokployResult, c as releaseDokploy, d as validateDokploy, f as verifyDokploy, o as planDokploy, s as provisionDokploy, u as rollbackDokploy } from "./engine-
|
|
2
|
+
import { a as dokployResult, c as releaseDokploy, d as validateDokploy, f as verifyDokploy, o as planDokploy, s as provisionDokploy, u as rollbackDokploy } from "./engine-4nWsBOM9.mjs";
|
|
3
3
|
//#region src/target/dokploy/index.ts
|
|
4
4
|
/**
|
|
5
5
|
* The built-in `dokploy` target: the Dokploy engine `gkm deploy` has always
|
|
@@ -35,4 +35,4 @@ const dokployTarget = defineTarget({
|
|
|
35
35
|
//#endregion
|
|
36
36
|
export { dokployTarget };
|
|
37
37
|
|
|
38
|
-
//# sourceMappingURL=dokploy-
|
|
38
|
+
//# sourceMappingURL=dokploy-DlgTAdSK.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dokploy-
|
|
1
|
+
{"version":3,"file":"dokploy-DlgTAdSK.mjs","names":[],"sources":["../src/target/dokploy/index.ts"],"sourcesContent":["/**\n * The built-in `dokploy` target: the Dokploy engine `gkm deploy` has always\n * run, behind the phases.\n *\n * - `provision`: the project, environment and registry, and what the\n * manifest declares — its databases' roles applied over a port published\n * for the purpose.\n * - `release`: the stage's migrations, then each image built and pushed\n * beside its application and deployed, waited on until Dokploy has\n * finished; backends first and checked before any site is released.\n * - `verify`: each site answering its health check.\n * - `rollback`: what failed — or, `--atomic`, everything the run released —\n * pointed back at the image it ran before.\n */\n\nimport { defineTarget } from '../define';\nimport {\n\ttype DokployRun,\n\tdokployResult,\n\tplanDokploy,\n\tprovisionDokploy,\n\treleaseDokploy,\n\trollbackDokploy,\n\tvalidateDokploy,\n\tverifyDokploy,\n} from './engine';\n\nexport const dokployTarget = defineTarget<undefined, DokployRun>({\n\tname: 'dokploy',\n\truntime: 'server',\n\tcapabilities: { rollback: true, migrations: 'target', images: true },\n\tcredentials: ['dokploy', 'registry'],\n\tvalidate: (ctx) => validateDokploy(ctx),\n\tplan: (_ctx, run) => planDokploy(run),\n\tprovision: (_ctx, run) => provisionDokploy(run),\n\trelease: (_ctx, run) => releaseDokploy(run),\n\tverify: (_ctx, run) => verifyDokploy(run),\n\trollback: (_ctx, run, failure) => rollbackDokploy(run, failure),\n\tresult: (_ctx, run) => dokployResult(run),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;AA2BA,MAAa,gBAAgB,aAAoC;CAChE,MAAM;CACN,SAAS;CACT,cAAc;EAAE,UAAU;EAAM,YAAY;EAAU,QAAQ;CAAK;CACnE,aAAa,CAAC,WAAW,UAAU;CACnC,WAAW,QAAQ,gBAAgB,GAAG;CACtC,OAAO,MAAM,QAAQ,YAAY,GAAG;CACpC,YAAY,MAAM,QAAQ,iBAAiB,GAAG;CAC9C,UAAU,MAAM,QAAQ,eAAe,GAAG;CAC1C,SAAS,MAAM,QAAQ,cAAc,GAAG;CACxC,WAAW,MAAM,KAAK,YAAY,gBAAgB,KAAK,OAAO;CAC9D,SAAS,MAAM,QAAQ,cAAc,GAAG;AACzC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_errors = require("./errors-D1x8duqI.cjs");
|
|
2
2
|
const require_workspace = require("./workspace-CTspddnJ.cjs");
|
|
3
3
|
const require_index = require("./index.cjs");
|
|
4
|
-
const require_stage = require("./stage-
|
|
4
|
+
const require_stage = require("./stage-CvUrBgxq.cjs");
|
|
5
5
|
let node_path = require("node:path");
|
|
6
6
|
let node_fs = require("node:fs");
|
|
7
7
|
let node_fs_promises = require("node:fs/promises");
|
|
@@ -334,4 +334,4 @@ exports.easCli = easCli;
|
|
|
334
334
|
exports.easSync = easSync;
|
|
335
335
|
exports.withStageProfiles = withStageProfiles;
|
|
336
336
|
|
|
337
|
-
//# sourceMappingURL=eas-
|
|
337
|
+
//# sourceMappingURL=eas-2DGYQ0Qf.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eas-BAitvB5R.cjs","names":["GkmError","spawn","join","delimiter","appKey","loadStage","mobileStage","existsSync","readFile","easWorkflowPath","easWorkflow","writeFile","mkdir","dirname"],"sources":["../src/mobile/eas.ts"],"sourcesContent":["/**\n * `gkm eas:sync --stage <stage>`: a mobile app's EAS project set up for a\n * deployed stage, from what the workspace declares — so a store build, which\n * EAS runs on its own machines, outside gkm, is built with the same values\n * the stage's servers were deployed with.\n *\n * - **`eas.json`**: the stage's build profile (`build.<stage>`) reads its EAS\n * environment and listens on its channel; its submit profile\n * (`submit.<stage>.android`) has its Play track and release status — see\n * `mobileStage`. Every other field is left as it is.\n * - **The EAS environment**: each value the app's build reads for the stage\n * (`StackMobileApp.values`) — its scheme, its edges' public URLs under\n * `EXPO_PUBLIC_`, and every stage secret already named so — set with\n * `eas env:set`, as `plaintext`: a bundle inlines them, so none is secret.\n * Nothing else is written: no server key reaches EAS.\n */\n\nimport { spawn } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { delimiter, dirname, join } from 'node:path';\nimport type {\n\tConstructManifest,\n\tMobileAppDeclaration,\n} from '@geekmidas/manifest';\nimport { GkmError } from '../errors';\nimport { loadStage } from '../exec/stage.js';\nimport { appKey } from '../workspace/derive.js';\nimport { easWorkflow, easWorkflowPath } from './easWorkflow.js';\nimport { type MobileStage, mobileStage } from './stage.js';\n\nconst logger = console;\n\n/** The workspace declares no `MobileApp`: nothing to set up. */\nexport class NoMobileApp extends GkmError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t'The workspace declares no MobileApp, so there is no EAS project to set ' +\n\t\t\t\t\"up. Declare one: new MobileApp('App', { path: 'apps/app' }).dependsOn([api, auth]).\",\n\t\t);\n\t\tthis.name = 'NoMobileApp';\n\t}\n}\n\n/** Several `MobileApp`s, and nothing to say which. */\nexport class MobileAppNotChosen extends GkmError {\n\tconstructor(readonly apps: readonly string[]) {\n\t\tsuper(\n\t\t\t`The workspace declares ${apps.length} mobile apps (${apps.join(', ')}). ` +\n\t\t\t\t`Run from one's directory, or name it: --app ${apps[0]}.`,\n\t\t);\n\t\tthis.name = 'MobileAppNotChosen';\n\t}\n}\n\n/** `--app` names no `MobileApp`. */\nexport class MobileAppUnknown extends GkmError {\n\tconstructor(\n\t\treadonly app: string,\n\t\treadonly apps: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`'${app}' is not one of the workspace's mobile apps (${apps.join(', ')}).`,\n\t\t);\n\t\tthis.name = 'MobileAppUnknown';\n\t}\n}\n\n/** `eas` is not installed where the app is. */\nexport class EasCliMissing extends GkmError {\n\tconstructor(readonly dir: string) {\n\t\tsuper(\n\t\t\t`No \\`eas\\` to run in ${dir}. Add it to the app: pnpm add -D eas-cli ` +\n\t\t\t\t'(or install it globally: npm install -g eas-cli).',\n\t\t);\n\t\tthis.name = 'EasCliMissing';\n\t}\n}\n\n/** `eas` refused a command. */\nexport class EasCommandFailed extends GkmError {\n\tconstructor(\n\t\treadonly command: string,\n\t\treadonly code: number | null,\n\t\treadonly stderr: string,\n\t) {\n\t\tsuper(\n\t\t\t`\\`eas ${command}\\` failed (exit ${code}): ${stderr.trim() || 'it said nothing'}. ` +\n\t\t\t\t'In CI, EXPO_TOKEN must be set; on this machine, `eas login`.',\n\t\t);\n\t\tthis.name = 'EasCommandFailed';\n\t}\n}\n\n/** A platform EAS builds for. */\nexport type EasPlatform = 'ios' | 'android';\n\n/** What gkm asks of EAS, so tests can stand in. */\nexport interface EasCli {\n\t/** Create or update a variable in one of the project's environments. */\n\tsetEnv(\n\t\tdir: string,\n\t\tvariable: { environment: string; name: string; value: string },\n\t): Promise<void>;\n\t/**\n\t * The fingerprint of the app's native code, as a build with `profile`\n\t * would compute it — what its runtime version is.\n\t */\n\tfingerprint(\n\t\tdir: string,\n\t\toptions: { platform: EasPlatform; profile: string },\n\t): Promise<string>;\n\t/** A finished store build of `profile` with that fingerprint, if any. */\n\tstoreBuild(\n\t\tdir: string,\n\t\toptions: { platform: EasPlatform; profile: string; fingerprint: string },\n\t): Promise<string | undefined>;\n\t/** Start a store build of `profile`, submitted to the store when asked. */\n\tbuild(\n\t\tdir: string,\n\t\toptions: {\n\t\t\tplatform: EasPlatform;\n\t\t\tprofile: string;\n\t\t\tsubmit: boolean;\n\t\t\twait: boolean;\n\t\t},\n\t): Promise<void>;\n\t/** Publish an update of the app's JavaScript on a channel. */\n\tupdate(\n\t\tdir: string,\n\t\toptions: {\n\t\t\tplatform: EasPlatform;\n\t\t\tchannel: string;\n\t\t\tenvironment: string;\n\t\t\tmessage: string;\n\t\t},\n\t): Promise<void>;\n}\n\n/**\n * Run `eas` in `dir`: the app's own, else the workspace's, else the one on\n * PATH. What it prints on stdout is answered; a failure is\n * {@link EasCommandFailed} with what it said.\n */\nfunction runEas(\n\troot: string,\n\tdir: string,\n\targs: readonly string[],\n\toptions: { inherit?: boolean; env?: Readonly<Record<string, string>> } = {},\n): Promise<string> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst child = spawn('eas', [...args, '--non-interactive'], {\n\t\t\tcwd: dir,\n\t\t\t// A build's or an update's progress is the user's to read.\n\t\t\tstdio: ['ignore', options.inherit ? 'inherit' : 'pipe', 'pipe'],\n\t\t\tenv: {\n\t\t\t\t...process.env,\n\t\t\t\t...options.env,\n\t\t\t\tPATH: [\n\t\t\t\t\tjoin(dir, 'node_modules', '.bin'),\n\t\t\t\t\tjoin(root, 'node_modules', '.bin'),\n\t\t\t\t\tprocess.env.PATH,\n\t\t\t\t].join(delimiter),\n\t\t\t},\n\t\t});\n\t\tlet stdout = '';\n\t\tlet stderr = '';\n\t\tchild.stdout?.on('data', (chunk: Buffer) => {\n\t\t\tstdout += chunk.toString();\n\t\t});\n\t\tchild.stderr?.on('data', (chunk: Buffer) => {\n\t\t\tstderr += chunk.toString();\n\t\t\tif (options.inherit) process.stderr.write(chunk);\n\t\t});\n\t\tconst command = args.slice(0, 3).join(' ');\n\t\tchild.on('error', (error: NodeJS.ErrnoException) =>\n\t\t\treject(\n\t\t\t\terror.code === 'ENOENT'\n\t\t\t\t\t? new EasCliMissing(dir)\n\t\t\t\t\t: new EasCommandFailed(command, null, error.message),\n\t\t\t),\n\t\t);\n\t\tchild.on('close', (code) =>\n\t\t\tcode === 0\n\t\t\t\t? resolve(stdout)\n\t\t\t\t: reject(new EasCommandFailed(command, code, stderr)),\n\t\t);\n\t});\n}\n\n/** The JSON `eas … --json` printed, read for `what`. */\nfunction easJson(output: string, what: string): unknown {\n\ttry {\n\t\treturn JSON.parse(output);\n\t} catch {\n\t\tthrow new EasCommandFailed(what, 0, `not JSON: ${output.slice(0, 200)}`);\n\t}\n}\n\n/**\n * The real one — never a prompt (`--non-interactive`). `env` is what the\n * app's `app.config.ts` reads for the stage: every `eas` command evaluates\n * it, and one that reads a value it lacks fails before it starts — and a\n * fingerprint computed here must match the one EAS computes with the\n * stage's values.\n */\nexport function easCli(\n\troot: string,\n\tenv: Readonly<Record<string, string>> = {},\n): EasCli {\n\tconst run = (\n\t\tdir: string,\n\t\targs: readonly string[],\n\t\toptions: { inherit?: boolean } = {},\n\t) => runEas(root, dir, args, { ...options, env });\n\treturn {\n\t\tasync setEnv(dir, { environment, name, value }) {\n\t\t\tawait run(dir, [\n\t\t\t\t'env:set',\n\t\t\t\t'--environment',\n\t\t\t\tenvironment,\n\t\t\t\t'--name',\n\t\t\t\tname,\n\t\t\t\t'--value',\n\t\t\t\tvalue,\n\t\t\t\t'--visibility',\n\t\t\t\t'plaintext',\n\t\t\t\t'--scope',\n\t\t\t\t'project',\n\t\t\t]);\n\t\t},\n\n\t\tasync fingerprint(dir, { platform, profile }) {\n\t\t\tconst output = await run(dir, [\n\t\t\t\t'fingerprint:generate',\n\t\t\t\t'--platform',\n\t\t\t\tplatform,\n\t\t\t\t'--build-profile',\n\t\t\t\tprofile,\n\t\t\t\t'--json',\n\t\t\t]);\n\t\t\tconst hash = (\n\t\t\t\teasJson(output, 'fingerprint:generate') as { hash?: unknown }\n\t\t\t).hash;\n\t\t\tif (typeof hash !== 'string') {\n\t\t\t\tthrow new EasCommandFailed('fingerprint:generate', 0, 'no hash');\n\t\t\t}\n\t\t\treturn hash;\n\t\t},\n\n\t\tasync storeBuild(dir, { platform, profile, fingerprint }) {\n\t\t\tconst output = await run(dir, [\n\t\t\t\t'build:list',\n\t\t\t\t'--platform',\n\t\t\t\tplatform,\n\t\t\t\t'--build-profile',\n\t\t\t\tprofile,\n\t\t\t\t'--fingerprint-hash',\n\t\t\t\tfingerprint,\n\t\t\t\t'--status',\n\t\t\t\t'finished',\n\t\t\t\t'--distribution',\n\t\t\t\t'store',\n\t\t\t\t'--limit',\n\t\t\t\t'1',\n\t\t\t\t'--json',\n\t\t\t]);\n\t\t\tconst builds = easJson(output, 'build:list');\n\t\t\tif (!Array.isArray(builds)) return undefined;\n\t\t\tconst id = (builds[0] as { id?: unknown } | undefined)?.id;\n\t\t\treturn typeof id === 'string' ? id : undefined;\n\t\t},\n\n\t\tasync build(dir, { platform, profile, submit, wait }) {\n\t\t\tawait run(\n\t\t\t\tdir,\n\t\t\t\t[\n\t\t\t\t\t'build',\n\t\t\t\t\t'--platform',\n\t\t\t\t\tplatform,\n\t\t\t\t\t'--profile',\n\t\t\t\t\tprofile,\n\t\t\t\t\t...(submit ? ['--auto-submit'] : []),\n\t\t\t\t\t...(wait ? [] : ['--no-wait']),\n\t\t\t\t],\n\t\t\t\t{ inherit: true },\n\t\t\t);\n\t\t},\n\n\t\tasync update(dir, { platform, channel, environment, message }) {\n\t\t\tawait run(\n\t\t\t\tdir,\n\t\t\t\t[\n\t\t\t\t\t'update',\n\t\t\t\t\t'--platform',\n\t\t\t\t\tplatform,\n\t\t\t\t\t'--channel',\n\t\t\t\t\tchannel,\n\t\t\t\t\t'--environment',\n\t\t\t\t\tenvironment,\n\t\t\t\t\t'--message',\n\t\t\t\t\tmessage,\n\t\t\t\t],\n\t\t\t\t{ inherit: true },\n\t\t\t);\n\t\t},\n\t};\n}\n\n/**\n * The mobile app a command is about: the one `--app` names, else the one\n * this directory is, else the only one.\n *\n * @throws {NoMobileApp}, {MobileAppNotChosen}, {MobileAppUnknown}\n */\nexport function chooseMobileApp(\n\tmanifest: ConstructManifest,\n\tapp: string | undefined,\n\there: string | undefined,\n): MobileAppDeclaration {\n\tconst declarations = Object.values(manifest).filter(\n\t\t(declaration): declaration is MobileAppDeclaration =>\n\t\t\tdeclaration.kind === 'mobile-app',\n\t);\n\tconst names = declarations.map((declaration) => appKey(declaration.id));\n\tif (declarations.length === 0) throw new NoMobileApp();\n\tconst name =\n\t\tapp ??\n\t\t(here && names.includes(here)\n\t\t\t? here\n\t\t\t: names.length === 1\n\t\t\t\t? names[0]\n\t\t\t\t: undefined);\n\tif (!name) throw new MobileAppNotChosen(names);\n\tconst declaration = declarations.find((d) => appKey(d.id) === name);\n\tif (!declaration) throw new MobileAppUnknown(name, names);\n\treturn declaration;\n}\n\n/** `eas.json`, as far as gkm writes it. */\ninterface EasJson {\n\tbuild?: Record<string, Record<string, unknown>>;\n\tsubmit?: Record<string, Record<string, unknown>>;\n\t[key: string]: unknown;\n}\n\n/**\n * `eas.json` with the stage's build and submit profiles as `stage` says:\n * every field gkm does not decide is kept.\n */\nexport function withStageProfiles(\n\teasJson: EasJson,\n\tstage: MobileStage,\n): EasJson {\n\tconst build = easJson.build?.[stage.stage] ?? {};\n\tconst submit = easJson.submit?.[stage.stage] ?? {};\n\tconst android = (submit.android as Record<string, unknown> | undefined) ?? {};\n\treturn {\n\t\t...easJson,\n\t\tbuild: {\n\t\t\t...easJson.build,\n\t\t\t[stage.stage]: {\n\t\t\t\t...build,\n\t\t\t\tenvironment: stage.environment,\n\t\t\t\tchannel: stage.channel,\n\t\t\t},\n\t\t},\n\t\tsubmit: {\n\t\t\t...easJson.submit,\n\t\t\t[stage.stage]: {\n\t\t\t\t...submit,\n\t\t\t\tandroid: {\n\t\t\t\t\t...android,\n\t\t\t\t\ttrack: stage.android.track,\n\t\t\t\t\treleaseStatus: stage.android.releaseStatus,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t};\n}\n\nexport interface EasSyncOptions {\n\tstage: string;\n\t/** The mobile app, by its app key; the one here, or the only one, if not. */\n\tapp?: string;\n\t/** The AWS profile for the stage's account, where its secrets are kept. */\n\tprofile?: string;\n\tcwd?: string;\n\t/** Say what would be written, and write nothing. */\n\tdryRun?: boolean;\n}\n\n/** What a sync wrote — or, dry, would. */\nexport interface EasSyncResult {\n\tapp: string;\n\t/** The workspace's root, where its `eas` may be installed. */\n\troot: string;\n\tdir: string;\n\tstage: MobileStage;\n\tvalues: Record<string, string>;\n\t/** Whether `eas.json` changed. */\n\teasJsonChanged: boolean;\n\t/** The stage's EAS workflow, relative to the app, and whether it changed. */\n\tworkflow: { path: string; changed: boolean };\n}\n\n/**\n * Set up a mobile app's EAS project for a deployed stage.\n *\n * @throws {NoMobileApp}, {MobileAppNotChosen}, {MobileAppUnknown},\n * {MobileAppStageUndeclared}, {EasCliMissing}, {EasCommandFailed} — and\n * what loading the stage throws: {UndeclaredStage}, {ExecStageNotComposed},\n * {ExecStageNotDeployed}\n */\nexport async function easSync(\n\toptions: EasSyncOptions,\n\teas?: EasCli,\n): Promise<EasSyncResult> {\n\tconst loaded = await loadStage(options);\n\tconst { workspace, manifest, stack } = loaded;\n\n\tconst declaration = chooseMobileApp(manifest, options.app, loaded.appName);\n\tconst name = appKey(declaration.id);\n\n\tconst stage = mobileStage(workspace, declaration, options.stage);\n\tconst values =\n\t\tstack.mobileApps.find((candidate) => candidate.name === name)?.values ?? {};\n\tconst dir = join(workspace.root, declaration.app.path);\n\n\tconst path = join(dir, 'eas.json');\n\tconst before = existsSync(path)\n\t\t? (JSON.parse(await readFile(path, 'utf8')) as EasJson)\n\t\t: {};\n\tconst after = withStageProfiles(before, stage);\n\tconst easJsonChanged = JSON.stringify(before) !== JSON.stringify(after);\n\n\tconst workflowPath = easWorkflowPath(stage.stage);\n\tconst workflowFile = join(dir, workflowPath);\n\tconst workflowYaml = easWorkflow(stage, {\n\t\trelease: workspace.stages.protected?.includes(stage.stage) ?? false,\n\t\tiosSubmits: Boolean(\n\t\t\t(after.submit?.[stage.stage]?.ios as { ascAppId?: string } | undefined)\n\t\t\t\t?.ascAppId,\n\t\t),\n\t});\n\tconst workflow = {\n\t\tpath: workflowPath,\n\t\tchanged:\n\t\t\t!existsSync(workflowFile) ||\n\t\t\t(await readFile(workflowFile, 'utf8')) !== workflowYaml,\n\t};\n\n\tconst where = `${name} on '${stage.stage}': EAS environment '${stage.environment}', channel '${stage.channel}', Play track '${stage.android.track}' (${stage.android.releaseStatus})`;\n\tif (options.dryRun) {\n\t\tlogger.log(`📱 ${where} (dry run)`);\n\t\tif (easJsonChanged) {\n\t\t\tlogger.log(\n\t\t\t\t` would write build.${stage.stage} and submit.${stage.stage} in ${path}`,\n\t\t\t);\n\t\t}\n\t\tif (workflow.changed) logger.log(` would write ${workflowFile}`);\n\t\tfor (const [key, value] of Object.entries(values)) {\n\t\t\tlogger.log(` would set ${key}=${value}`);\n\t\t}\n\t\treturn {\n\t\t\tapp: name,\n\t\t\troot: workspace.root,\n\t\t\tdir,\n\t\t\tstage,\n\t\t\tvalues,\n\t\t\teasJsonChanged,\n\t\t\tworkflow,\n\t\t};\n\t}\n\n\tlogger.log(`📱 ${where}`);\n\tif (easJsonChanged) {\n\t\tawait writeFile(path, `${JSON.stringify(after, null, 2)}\\n`);\n\t\tlogger.log(\n\t\t\t` wrote build.${stage.stage} and submit.${stage.stage} in ${path}`,\n\t\t);\n\t}\n\tif (workflow.changed) {\n\t\tawait mkdir(dirname(workflowFile), { recursive: true });\n\t\tawait writeFile(workflowFile, workflowYaml);\n\t\tlogger.log(` wrote ${workflowFile}`);\n\t}\n\tconst cli = eas ?? easCli(workspace.root, values);\n\tfor (const [key, value] of Object.entries(values)) {\n\t\tawait cli.setEnv(dir, { environment: stage.environment, name: key, value });\n\t\tlogger.log(` set ${key}`);\n\t}\n\treturn {\n\t\tapp: name,\n\t\troot: workspace.root,\n\t\tdir,\n\t\tstage,\n\t\tvalues,\n\t\teasJsonChanged,\n\t\tworkflow,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAM,SAAS;;AAGf,IAAa,cAAb,cAAiCA,eAAAA,SAAS;CACzC,cAAc;EACb,MACC,4JAED;EACA,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,qBAAb,cAAw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SAAS;EACrB,OAAA,GAAMC,iBAAAA,MAAAA,EAAAA,GAAMC,UAAAA,QAAAA,CAAQ,YAAY,GAAG,EAAE,WAAW,KAAK,CAAC;EACtD,OAAA,GAAMF,iBAAAA,UAAAA,CAAU,cAAc,YAAY;EAC1C,OAAO,IAAI,YAAY,cAAc;CACtC;CACA,MAAM,MAAM,OAAO,OAAO,UAAU,MAAM,MAAM;CAChD,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,GAAG;EAClD,MAAM,IAAI,OAAO,KAAK;GAAE,aAAa,MAAM;GAAa,MAAM;GAAK;EAAM,CAAC;EAC1E,OAAO,IAAI,UAAU,KAAK;CAC3B;CACA,OAAO;EACN,KAAK;EACL,MAAM,UAAU;EAChB;EACA;EACA;EACA;EACA;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"eas-2DGYQ0Qf.cjs","names":["GkmError","spawn","join","delimiter","appKey","loadStage","mobileStage","existsSync","readFile","easWorkflowPath","easWorkflow","writeFile","mkdir","dirname"],"sources":["../src/mobile/eas.ts"],"sourcesContent":["/**\n * `gkm eas:sync --stage <stage>`: a mobile app's EAS project set up for a\n * deployed stage, from what the workspace declares — so a store build, which\n * EAS runs on its own machines, outside gkm, is built with the same values\n * the stage's servers were deployed with.\n *\n * - **`eas.json`**: the stage's build profile (`build.<stage>`) reads its EAS\n * environment and listens on its channel; its submit profile\n * (`submit.<stage>.android`) has its Play track and release status — see\n * `mobileStage`. Every other field is left as it is.\n * - **The EAS environment**: each value the app's build reads for the stage\n * (`StackMobileApp.values`) — its scheme, its edges' public URLs under\n * `EXPO_PUBLIC_`, and every stage secret already named so — set with\n * `eas env:set`, as `plaintext`: a bundle inlines them, so none is secret.\n * Nothing else is written: no server key reaches EAS.\n */\n\nimport { spawn } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { delimiter, dirname, join } from 'node:path';\nimport type {\n\tConstructManifest,\n\tMobileAppDeclaration,\n} from '@geekmidas/manifest';\nimport { GkmError } from '../errors';\nimport { loadStage } from '../exec/stage.js';\nimport { appKey } from '../workspace/derive.js';\nimport { easWorkflow, easWorkflowPath } from './easWorkflow.js';\nimport { type MobileStage, mobileStage } from './stage.js';\n\nconst logger = console;\n\n/** The workspace declares no `MobileApp`: nothing to set up. */\nexport class NoMobileApp extends GkmError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t'The workspace declares no MobileApp, so there is no EAS project to set ' +\n\t\t\t\t\"up. Declare one: new MobileApp('App', { path: 'apps/app' }).dependsOn([api, auth]).\",\n\t\t);\n\t\tthis.name = 'NoMobileApp';\n\t}\n}\n\n/** Several `MobileApp`s, and nothing to say which. */\nexport class MobileAppNotChosen extends GkmError {\n\tconstructor(readonly apps: readonly string[]) {\n\t\tsuper(\n\t\t\t`The workspace declares ${apps.length} mobile apps (${apps.join(', ')}). ` +\n\t\t\t\t`Run from one's directory, or name it: --app ${apps[0]}.`,\n\t\t);\n\t\tthis.name = 'MobileAppNotChosen';\n\t}\n}\n\n/** `--app` names no `MobileApp`. */\nexport class MobileAppUnknown extends GkmError {\n\tconstructor(\n\t\treadonly app: string,\n\t\treadonly apps: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`'${app}' is not one of the workspace's mobile apps (${apps.join(', ')}).`,\n\t\t);\n\t\tthis.name = 'MobileAppUnknown';\n\t}\n}\n\n/** `eas` is not installed where the app is. */\nexport class EasCliMissing extends GkmError {\n\tconstructor(readonly dir: string) {\n\t\tsuper(\n\t\t\t`No \\`eas\\` to run in ${dir}. Add it to the app: pnpm add -D eas-cli ` +\n\t\t\t\t'(or install it globally: npm install -g eas-cli).',\n\t\t);\n\t\tthis.name = 'EasCliMissing';\n\t}\n}\n\n/** `eas` refused a command. */\nexport class EasCommandFailed extends GkmError {\n\tconstructor(\n\t\treadonly command: string,\n\t\treadonly code: number | null,\n\t\treadonly stderr: string,\n\t) {\n\t\tsuper(\n\t\t\t`\\`eas ${command}\\` failed (exit ${code}): ${stderr.trim() || 'it said nothing'}. ` +\n\t\t\t\t'In CI, EXPO_TOKEN must be set; on this machine, `eas login`.',\n\t\t);\n\t\tthis.name = 'EasCommandFailed';\n\t}\n}\n\n/** A platform EAS builds for. */\nexport type EasPlatform = 'ios' | 'android';\n\n/** What gkm asks of EAS, so tests can stand in. */\nexport interface EasCli {\n\t/** Create or update a variable in one of the project's environments. */\n\tsetEnv(\n\t\tdir: string,\n\t\tvariable: { environment: string; name: string; value: string },\n\t): Promise<void>;\n\t/**\n\t * The fingerprint of the app's native code, as a build with `profile`\n\t * would compute it — what its runtime version is.\n\t */\n\tfingerprint(\n\t\tdir: string,\n\t\toptions: { platform: EasPlatform; profile: string },\n\t): Promise<string>;\n\t/** A finished store build of `profile` with that fingerprint, if any. */\n\tstoreBuild(\n\t\tdir: string,\n\t\toptions: { platform: EasPlatform; profile: string; fingerprint: string },\n\t): Promise<string | undefined>;\n\t/** Start a store build of `profile`, submitted to the store when asked. */\n\tbuild(\n\t\tdir: string,\n\t\toptions: {\n\t\t\tplatform: EasPlatform;\n\t\t\tprofile: string;\n\t\t\tsubmit: boolean;\n\t\t\twait: boolean;\n\t\t},\n\t): Promise<void>;\n\t/** Publish an update of the app's JavaScript on a channel. */\n\tupdate(\n\t\tdir: string,\n\t\toptions: {\n\t\t\tplatform: EasPlatform;\n\t\t\tchannel: string;\n\t\t\tenvironment: string;\n\t\t\tmessage: string;\n\t\t},\n\t): Promise<void>;\n}\n\n/**\n * Run `eas` in `dir`: the app's own, else the workspace's, else the one on\n * PATH. What it prints on stdout is answered; a failure is\n * {@link EasCommandFailed} with what it said.\n */\nfunction runEas(\n\troot: string,\n\tdir: string,\n\targs: readonly string[],\n\toptions: { inherit?: boolean; env?: Readonly<Record<string, string>> } = {},\n): Promise<string> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst child = spawn('eas', [...args, '--non-interactive'], {\n\t\t\tcwd: dir,\n\t\t\t// A build's or an update's progress is the user's to read.\n\t\t\tstdio: ['ignore', options.inherit ? 'inherit' : 'pipe', 'pipe'],\n\t\t\tenv: {\n\t\t\t\t...process.env,\n\t\t\t\t...options.env,\n\t\t\t\tPATH: [\n\t\t\t\t\tjoin(dir, 'node_modules', '.bin'),\n\t\t\t\t\tjoin(root, 'node_modules', '.bin'),\n\t\t\t\t\tprocess.env.PATH,\n\t\t\t\t].join(delimiter),\n\t\t\t},\n\t\t});\n\t\tlet stdout = '';\n\t\tlet stderr = '';\n\t\tchild.stdout?.on('data', (chunk: Buffer) => {\n\t\t\tstdout += chunk.toString();\n\t\t});\n\t\tchild.stderr?.on('data', (chunk: Buffer) => {\n\t\t\tstderr += chunk.toString();\n\t\t\tif (options.inherit) process.stderr.write(chunk);\n\t\t});\n\t\tconst command = args.slice(0, 3).join(' ');\n\t\tchild.on('error', (error: NodeJS.ErrnoException) =>\n\t\t\treject(\n\t\t\t\terror.code === 'ENOENT'\n\t\t\t\t\t? new EasCliMissing(dir)\n\t\t\t\t\t: new EasCommandFailed(command, null, error.message),\n\t\t\t),\n\t\t);\n\t\tchild.on('close', (code) =>\n\t\t\tcode === 0\n\t\t\t\t? resolve(stdout)\n\t\t\t\t: reject(new EasCommandFailed(command, code, stderr)),\n\t\t);\n\t});\n}\n\n/** The JSON `eas … --json` printed, read for `what`. */\nfunction easJson(output: string, what: string): unknown {\n\ttry {\n\t\treturn JSON.parse(output);\n\t} catch {\n\t\tthrow new EasCommandFailed(what, 0, `not JSON: ${output.slice(0, 200)}`);\n\t}\n}\n\n/**\n * The real one — never a prompt (`--non-interactive`). `env` is what the\n * app's `app.config.ts` reads for the stage: every `eas` command evaluates\n * it, and one that reads a value it lacks fails before it starts — and a\n * fingerprint computed here must match the one EAS computes with the\n * stage's values.\n */\nexport function easCli(\n\troot: string,\n\tenv: Readonly<Record<string, string>> = {},\n): EasCli {\n\tconst run = (\n\t\tdir: string,\n\t\targs: readonly string[],\n\t\toptions: { inherit?: boolean } = {},\n\t) => runEas(root, dir, args, { ...options, env });\n\treturn {\n\t\tasync setEnv(dir, { environment, name, value }) {\n\t\t\tawait run(dir, [\n\t\t\t\t'env:set',\n\t\t\t\t'--environment',\n\t\t\t\tenvironment,\n\t\t\t\t'--name',\n\t\t\t\tname,\n\t\t\t\t'--value',\n\t\t\t\tvalue,\n\t\t\t\t'--visibility',\n\t\t\t\t'plaintext',\n\t\t\t\t'--scope',\n\t\t\t\t'project',\n\t\t\t]);\n\t\t},\n\n\t\tasync fingerprint(dir, { platform, profile }) {\n\t\t\tconst output = await run(dir, [\n\t\t\t\t'fingerprint:generate',\n\t\t\t\t'--platform',\n\t\t\t\tplatform,\n\t\t\t\t'--build-profile',\n\t\t\t\tprofile,\n\t\t\t\t'--json',\n\t\t\t]);\n\t\t\tconst hash = (\n\t\t\t\teasJson(output, 'fingerprint:generate') as { hash?: unknown }\n\t\t\t).hash;\n\t\t\tif (typeof hash !== 'string') {\n\t\t\t\tthrow new EasCommandFailed('fingerprint:generate', 0, 'no hash');\n\t\t\t}\n\t\t\treturn hash;\n\t\t},\n\n\t\tasync storeBuild(dir, { platform, profile, fingerprint }) {\n\t\t\tconst output = await run(dir, [\n\t\t\t\t'build:list',\n\t\t\t\t'--platform',\n\t\t\t\tplatform,\n\t\t\t\t'--build-profile',\n\t\t\t\tprofile,\n\t\t\t\t'--fingerprint-hash',\n\t\t\t\tfingerprint,\n\t\t\t\t'--status',\n\t\t\t\t'finished',\n\t\t\t\t'--distribution',\n\t\t\t\t'store',\n\t\t\t\t'--limit',\n\t\t\t\t'1',\n\t\t\t\t'--json',\n\t\t\t]);\n\t\t\tconst builds = easJson(output, 'build:list');\n\t\t\tif (!Array.isArray(builds)) return undefined;\n\t\t\tconst id = (builds[0] as { id?: unknown } | undefined)?.id;\n\t\t\treturn typeof id === 'string' ? id : undefined;\n\t\t},\n\n\t\tasync build(dir, { platform, profile, submit, wait }) {\n\t\t\tawait run(\n\t\t\t\tdir,\n\t\t\t\t[\n\t\t\t\t\t'build',\n\t\t\t\t\t'--platform',\n\t\t\t\t\tplatform,\n\t\t\t\t\t'--profile',\n\t\t\t\t\tprofile,\n\t\t\t\t\t...(submit ? ['--auto-submit'] : []),\n\t\t\t\t\t...(wait ? [] : ['--no-wait']),\n\t\t\t\t],\n\t\t\t\t{ inherit: true },\n\t\t\t);\n\t\t},\n\n\t\tasync update(dir, { platform, channel, environment, message }) {\n\t\t\tawait run(\n\t\t\t\tdir,\n\t\t\t\t[\n\t\t\t\t\t'update',\n\t\t\t\t\t'--platform',\n\t\t\t\t\tplatform,\n\t\t\t\t\t'--channel',\n\t\t\t\t\tchannel,\n\t\t\t\t\t'--environment',\n\t\t\t\t\tenvironment,\n\t\t\t\t\t'--message',\n\t\t\t\t\tmessage,\n\t\t\t\t],\n\t\t\t\t{ inherit: true },\n\t\t\t);\n\t\t},\n\t};\n}\n\n/**\n * The mobile app a command is about: the one `--app` names, else the one\n * this directory is, else the only one.\n *\n * @throws {NoMobileApp}, {MobileAppNotChosen}, {MobileAppUnknown}\n */\nexport function chooseMobileApp(\n\tmanifest: ConstructManifest,\n\tapp: string | undefined,\n\there: string | undefined,\n): MobileAppDeclaration {\n\tconst declarations = Object.values(manifest).filter(\n\t\t(declaration): declaration is MobileAppDeclaration =>\n\t\t\tdeclaration.kind === 'mobile-app',\n\t);\n\tconst names = declarations.map((declaration) => appKey(declaration.id));\n\tif (declarations.length === 0) throw new NoMobileApp();\n\tconst name =\n\t\tapp ??\n\t\t(here && names.includes(here)\n\t\t\t? here\n\t\t\t: names.length === 1\n\t\t\t\t? names[0]\n\t\t\t\t: undefined);\n\tif (!name) throw new MobileAppNotChosen(names);\n\tconst declaration = declarations.find((d) => appKey(d.id) === name);\n\tif (!declaration) throw new MobileAppUnknown(name, names);\n\treturn declaration;\n}\n\n/** `eas.json`, as far as gkm writes it. */\ninterface EasJson {\n\tbuild?: Record<string, Record<string, unknown>>;\n\tsubmit?: Record<string, Record<string, unknown>>;\n\t[key: string]: unknown;\n}\n\n/**\n * `eas.json` with the stage's build and submit profiles as `stage` says:\n * every field gkm does not decide is kept.\n */\nexport function withStageProfiles(\n\teasJson: EasJson,\n\tstage: MobileStage,\n): EasJson {\n\tconst build = easJson.build?.[stage.stage] ?? {};\n\tconst submit = easJson.submit?.[stage.stage] ?? {};\n\tconst android = (submit.android as Record<string, unknown> | undefined) ?? {};\n\treturn {\n\t\t...easJson,\n\t\tbuild: {\n\t\t\t...easJson.build,\n\t\t\t[stage.stage]: {\n\t\t\t\t...build,\n\t\t\t\tenvironment: stage.environment,\n\t\t\t\tchannel: stage.channel,\n\t\t\t},\n\t\t},\n\t\tsubmit: {\n\t\t\t...easJson.submit,\n\t\t\t[stage.stage]: {\n\t\t\t\t...submit,\n\t\t\t\tandroid: {\n\t\t\t\t\t...android,\n\t\t\t\t\ttrack: stage.android.track,\n\t\t\t\t\treleaseStatus: stage.android.releaseStatus,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t};\n}\n\nexport interface EasSyncOptions {\n\tstage: string;\n\t/** The mobile app, by its app key; the one here, or the only one, if not. */\n\tapp?: string;\n\t/** The AWS profile for the stage's account, where its secrets are kept. */\n\tprofile?: string;\n\tcwd?: string;\n\t/** Say what would be written, and write nothing. */\n\tdryRun?: boolean;\n}\n\n/** What a sync wrote — or, dry, would. */\nexport interface EasSyncResult {\n\tapp: string;\n\t/** The workspace's root, where its `eas` may be installed. */\n\troot: string;\n\tdir: string;\n\tstage: MobileStage;\n\tvalues: Record<string, string>;\n\t/** Whether `eas.json` changed. */\n\teasJsonChanged: boolean;\n\t/** The stage's EAS workflow, relative to the app, and whether it changed. */\n\tworkflow: { path: string; changed: boolean };\n}\n\n/**\n * Set up a mobile app's EAS project for a deployed stage.\n *\n * @throws {NoMobileApp}, {MobileAppNotChosen}, {MobileAppUnknown},\n * {MobileAppStageUndeclared}, {EasCliMissing}, {EasCommandFailed} — and\n * what loading the stage throws: {UndeclaredStage}, {ExecStageNotComposed},\n * {ExecStageNotDeployed}\n */\nexport async function easSync(\n\toptions: EasSyncOptions,\n\teas?: EasCli,\n): Promise<EasSyncResult> {\n\tconst loaded = await loadStage(options);\n\tconst { workspace, manifest, stack } = loaded;\n\n\tconst declaration = chooseMobileApp(manifest, options.app, loaded.appName);\n\tconst name = appKey(declaration.id);\n\n\tconst stage = mobileStage(workspace, declaration, options.stage);\n\tconst values =\n\t\tstack.mobileApps.find((candidate) => candidate.name === name)?.values ?? {};\n\tconst dir = join(workspace.root, declaration.app.path);\n\n\tconst path = join(dir, 'eas.json');\n\tconst before = existsSync(path)\n\t\t? (JSON.parse(await readFile(path, 'utf8')) as EasJson)\n\t\t: {};\n\tconst after = withStageProfiles(before, stage);\n\tconst easJsonChanged = JSON.stringify(before) !== JSON.stringify(after);\n\n\tconst workflowPath = easWorkflowPath(stage.stage);\n\tconst workflowFile = join(dir, workflowPath);\n\tconst workflowYaml = easWorkflow(stage, {\n\t\trelease: workspace.stages.protected?.includes(stage.stage) ?? false,\n\t\tiosSubmits: Boolean(\n\t\t\t(after.submit?.[stage.stage]?.ios as { ascAppId?: string } | undefined)\n\t\t\t\t?.ascAppId,\n\t\t),\n\t});\n\tconst workflow = {\n\t\tpath: workflowPath,\n\t\tchanged:\n\t\t\t!existsSync(workflowFile) ||\n\t\t\t(await readFile(workflowFile, 'utf8')) !== workflowYaml,\n\t};\n\n\tconst where = `${name} on '${stage.stage}': EAS environment '${stage.environment}', channel '${stage.channel}', Play track '${stage.android.track}' (${stage.android.releaseStatus})`;\n\tif (options.dryRun) {\n\t\tlogger.log(`📱 ${where} (dry run)`);\n\t\tif (easJsonChanged) {\n\t\t\tlogger.log(\n\t\t\t\t` would write build.${stage.stage} and submit.${stage.stage} in ${path}`,\n\t\t\t);\n\t\t}\n\t\tif (workflow.changed) logger.log(` would write ${workflowFile}`);\n\t\tfor (const [key, value] of Object.entries(values)) {\n\t\t\tlogger.log(` would set ${key}=${value}`);\n\t\t}\n\t\treturn {\n\t\t\tapp: name,\n\t\t\troot: workspace.root,\n\t\t\tdir,\n\t\t\tstage,\n\t\t\tvalues,\n\t\t\teasJsonChanged,\n\t\t\tworkflow,\n\t\t};\n\t}\n\n\tlogger.log(`📱 ${where}`);\n\tif (easJsonChanged) {\n\t\tawait writeFile(path, `${JSON.stringify(after, null, 2)}\\n`);\n\t\tlogger.log(\n\t\t\t` wrote build.${stage.stage} and submit.${stage.stage} in ${path}`,\n\t\t);\n\t}\n\tif (workflow.changed) {\n\t\tawait mkdir(dirname(workflowFile), { recursive: true });\n\t\tawait writeFile(workflowFile, workflowYaml);\n\t\tlogger.log(` wrote ${workflowFile}`);\n\t}\n\tconst cli = eas ?? easCli(workspace.root, values);\n\tfor (const [key, value] of Object.entries(values)) {\n\t\tawait cli.setEnv(dir, { environment: stage.environment, name: key, value });\n\t\tlogger.log(` set ${key}`);\n\t}\n\treturn {\n\t\tapp: name,\n\t\troot: workspace.root,\n\t\tdir,\n\t\tstage,\n\t\tvalues,\n\t\teasJsonChanged,\n\t\tworkflow,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAM,SAAS;;AAGf,IAAa,cAAb,cAAiCA,eAAAA,SAAS;CACzC,cAAc;EACb,MACC,4JAED;EACA,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,qBAAb,cAAwCA,eAAAA,SAAS;CAC3B;CAArB,YAAY,MAAkC;EAC7C,MACC,0BAA0B,KAAK,OAAO,gBAAgB,KAAK,KAAK,IAAI,EAAE,iDACtB,KAAK,GAAG,EACzD;EAJoB,KAAA,OAAA;EAKpB,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,mBAAb,cAAsCA,eAAAA,SAAS;CAEpC;CACA;CAFV,YACC,KACA,MACC;EACD,MACC,IAAI,IAAI,+CAA+C,KAAK,KAAK,IAAI,EAAE,GACxE;EALS,KAAA,MAAA;EACA,KAAA,OAAA;EAKT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,gBAAb,cAAmCA,eAAAA,SAAS;CACtB;CAArB,YAAY,KAAsB;EACjC,MACC,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AAM,UAAU;EAChB;EACA;EACA;EACA;EACA;CACD;AACD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as GkmError } from "./errors-C9uIyIDt.mjs";
|
|
2
2
|
import { ot as appKey } from "./workspace-CdiCMRap.mjs";
|
|
3
3
|
import { i as easWorkflowPath, n as mobileStage, r as easWorkflow } from "./index.mjs";
|
|
4
|
-
import { r as loadStage } from "./stage-
|
|
4
|
+
import { r as loadStage } from "./stage-xkuXOSsr.mjs";
|
|
5
5
|
import { delimiter, dirname, join } from "node:path";
|
|
6
6
|
import { existsSync } from "node:fs";
|
|
7
7
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
@@ -331,4 +331,4 @@ async function easSync(options, eas) {
|
|
|
331
331
|
//#endregion
|
|
332
332
|
export { chooseMobileApp, easCli, easSync, withStageProfiles };
|
|
333
333
|
|
|
334
|
-
//# sourceMappingURL=eas-
|
|
334
|
+
//# sourceMappingURL=eas-DMg91c_V.mjs.map
|