@geekmidas/cli 10.0.0-alpha.96 → 10.0.0-alpha.98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/dist/{GoDaddyProvider-BsUKjGcg.mjs → GoDaddyProvider-C2fK-zeQ.mjs} +2 -2
  2. package/dist/{GoDaddyProvider-BsUKjGcg.mjs.map → GoDaddyProvider-C2fK-zeQ.mjs.map} +1 -1
  3. package/dist/{GoDaddyProvider-DyHXHDHe.cjs → GoDaddyProvider-SLlyDwD1.cjs} +2 -2
  4. package/dist/{GoDaddyProvider-DyHXHDHe.cjs.map → GoDaddyProvider-SLlyDwD1.cjs.map} +1 -1
  5. package/dist/{LegacyStateStore-BnMcONE0.cjs → LegacyStateStore-CAvxM8U5.cjs} +3 -3
  6. package/dist/{LegacyStateStore-BnMcONE0.cjs.map → LegacyStateStore-CAvxM8U5.cjs.map} +1 -1
  7. package/dist/{LegacyStateStore-B6SOqRFi.mjs → LegacyStateStore-D9QDWCst.mjs} +3 -3
  8. package/dist/{LegacyStateStore-B6SOqRFi.mjs.map → LegacyStateStore-D9QDWCst.mjs.map} +1 -1
  9. package/dist/{LocalStateStore-6CrsZzqI.mjs → LocalStateStore-DPQSqkSb.mjs} +2 -2
  10. package/dist/{LocalStateStore-6CrsZzqI.mjs.map → LocalStateStore-DPQSqkSb.mjs.map} +1 -1
  11. package/dist/{LocalStateStore-pd4bbdJJ.cjs → LocalStateStore-QcrdjCl6.cjs} +2 -2
  12. package/dist/{LocalStateStore-pd4bbdJJ.cjs.map → LocalStateStore-QcrdjCl6.cjs.map} +1 -1
  13. package/dist/{S3StateStore-CoGk6ZKU.cjs → S3StateStore-C16tVikU.cjs} +73 -11
  14. package/dist/S3StateStore-C16tVikU.cjs.map +1 -0
  15. package/dist/{S3StateStore-DP_7Q4yb.mjs → S3StateStore-jorgKaee.mjs} +73 -11
  16. package/dist/S3StateStore-jorgKaee.mjs.map +1 -0
  17. package/dist/{SSMStateStore-Bo6_KDYY.mjs → SSMStateStore-Dvjt_INw.mjs} +58 -7
  18. package/dist/SSMStateStore-Dvjt_INw.mjs.map +1 -0
  19. package/dist/{SSMStateStore-D9s4_Do3.cjs → SSMStateStore-mPAEr2P2.cjs} +58 -7
  20. package/dist/SSMStateStore-mPAEr2P2.cjs.map +1 -0
  21. package/dist/{add-BQS2QZHp.mjs → add-CZIIsTcv.mjs} +4 -4
  22. package/dist/{add-BQS2QZHp.mjs.map → add-CZIIsTcv.mjs.map} +1 -1
  23. package/dist/{add-CjURJ-vI.cjs → add-SRk65Udu.cjs} +4 -4
  24. package/dist/{add-CjURJ-vI.cjs.map → add-SRk65Udu.cjs.map} +1 -1
  25. package/dist/{aws-Dz2bYxK1.mjs → aws-8QQ8n-t6.mjs} +2 -2
  26. package/dist/{aws-Dz2bYxK1.mjs.map → aws-8QQ8n-t6.mjs.map} +1 -1
  27. package/dist/{aws-BTReGjpY.cjs → aws-DY9NqQIT.cjs} +2 -2
  28. package/dist/{aws-BTReGjpY.cjs.map → aws-DY9NqQIT.cjs.map} +1 -1
  29. package/dist/{awsStore-BWa1KNY-.mjs → awsStore-Bx5nCFnS.mjs} +8 -6
  30. package/dist/awsStore-Bx5nCFnS.mjs.map +1 -0
  31. package/dist/{awsStore-B5We7bMg.cjs → awsStore-u3ehhMoY.cjs} +8 -6
  32. package/dist/awsStore-u3ehhMoY.cjs.map +1 -0
  33. package/dist/{bundler-DmLJQ7AY.cjs → bundler-B0Pj5FXT.cjs} +5 -5
  34. package/dist/{bundler-DmLJQ7AY.cjs.map → bundler-B0Pj5FXT.cjs.map} +1 -1
  35. package/dist/{bundler-BMM3UsGm.mjs → bundler-DxJ-cIEt.mjs} +5 -5
  36. package/dist/{bundler-BMM3UsGm.mjs.map → bundler-DxJ-cIEt.mjs.map} +1 -1
  37. package/dist/{cli-C2c-jOVK.cjs → cli-CRDJWWmZ.cjs} +2 -2
  38. package/dist/{cli-C2c-jOVK.cjs.map → cli-CRDJWWmZ.cjs.map} +1 -1
  39. package/dist/{cli-Ce6NgaQF.mjs → cli-CV85bY3-.mjs} +2 -2
  40. package/dist/{cli-Ce6NgaQF.mjs.map → cli-CV85bY3-.mjs.map} +1 -1
  41. package/dist/{compose-BJDPFBAN.mjs → compose-CQQRRJC3.mjs} +7 -7
  42. package/dist/{compose-BJDPFBAN.mjs.map → compose-CQQRRJC3.mjs.map} +1 -1
  43. package/dist/{compose-ETFKqkTu.cjs → compose-DMY4ouEk.cjs} +7 -7
  44. package/dist/{compose-ETFKqkTu.cjs.map → compose-DMY4ouEk.cjs.map} +1 -1
  45. package/dist/{config-C8NPCn1l.d.mts → config-CS76CzXM.d.cts} +4 -4
  46. package/dist/{config-4yirvxS8.d.cts.map → config-CS76CzXM.d.cts.map} +1 -1
  47. package/dist/{config-4yirvxS8.d.cts → config-pBzLfNef.d.mts} +4 -4
  48. package/dist/{config-C8NPCn1l.d.mts.map → config-pBzLfNef.d.mts.map} +1 -1
  49. package/dist/config.cjs +1 -1
  50. package/dist/config.d.cts +3 -3
  51. package/dist/config.d.mts +3 -3
  52. package/dist/config.mjs +1 -1
  53. package/dist/deploy/public.cjs +7 -7
  54. package/dist/deploy/public.d.cts +5 -5
  55. package/dist/deploy/public.d.cts.map +1 -1
  56. package/dist/deploy/public.d.mts +5 -5
  57. package/dist/deploy/public.d.mts.map +1 -1
  58. package/dist/deploy/public.mjs +7 -7
  59. package/dist/{deploy-BdN0ym2i.cjs → deploy-277jek46.cjs} +19 -8
  60. package/dist/deploy-277jek46.cjs.map +1 -0
  61. package/dist/{deploy-DktQl7ti.mjs → deploy-Dw8g3sLY.mjs} +19 -8
  62. package/dist/{deploy-DktQl7ti.mjs.map → deploy-Dw8g3sLY.mjs.map} +1 -1
  63. package/dist/{discover-D-MdXZgm.d.mts → discover-CU1LjCOf.d.cts} +2 -2
  64. package/dist/{discover-BtFofyQB.d.cts.map → discover-CU1LjCOf.d.cts.map} +1 -1
  65. package/dist/{discover-BtFofyQB.d.cts → discover-DJCCgimv.d.mts} +2 -2
  66. package/dist/{discover-D-MdXZgm.d.mts.map → discover-DJCCgimv.d.mts.map} +1 -1
  67. package/dist/{dns-ClI7-d5g.cjs → dns-4RAiVFa7.cjs} +5 -5
  68. package/dist/{dns-ClI7-d5g.cjs.map → dns-4RAiVFa7.cjs.map} +1 -1
  69. package/dist/{dns-BjHECDO7.mjs → dns-CU22K_i0.mjs} +5 -5
  70. package/dist/{dns-BjHECDO7.mjs.map → dns-CU22K_i0.mjs.map} +1 -1
  71. package/dist/{dns-C-X6PLkV.cjs → dns-Dhjbnjgl.cjs} +3 -3
  72. package/dist/{dns-C-X6PLkV.cjs.map → dns-Dhjbnjgl.cjs.map} +1 -1
  73. package/dist/{dns-C2EeR6n2.mjs → dns-LqWzPb8l.mjs} +3 -3
  74. package/dist/{dns-C2EeR6n2.mjs.map → dns-LqWzPb8l.mjs.map} +1 -1
  75. package/dist/{dokploy-CxtkS5hl.mjs → dokploy-D_uCbZQ7.mjs} +2 -2
  76. package/dist/{dokploy-CxtkS5hl.mjs.map → dokploy-D_uCbZQ7.mjs.map} +1 -1
  77. package/dist/{dokploy-CD_Bc4EV.cjs → dokploy-Dw4oCXqR.cjs} +2 -2
  78. package/dist/{dokploy-CD_Bc4EV.cjs.map → dokploy-Dw4oCXqR.cjs.map} +1 -1
  79. package/dist/{encryption-BgQd4f2S.mjs → encryption-C0uKYE9v.mjs} +3 -3
  80. package/dist/{encryption-BgQd4f2S.mjs.map → encryption-C0uKYE9v.mjs.map} +1 -1
  81. package/dist/{encryption-CqVfz-m7.cjs → encryption-CtVPHWWq.cjs} +3 -3
  82. package/dist/{encryption-CqVfz-m7.cjs.map → encryption-CtVPHWWq.cjs.map} +1 -1
  83. package/dist/{engine-YlXzlTUl.mjs → engine-BE5PdE8S.mjs} +4 -4
  84. package/dist/{engine-YlXzlTUl.mjs.map → engine-BE5PdE8S.mjs.map} +1 -1
  85. package/dist/{engine-OVVKtPmW.cjs → engine-HI8aLw1M.cjs} +4 -4
  86. package/dist/{engine-OVVKtPmW.cjs.map → engine-HI8aLw1M.cjs.map} +1 -1
  87. package/dist/{github-CsMloeSL.cjs → github-BCdfZ9zO.cjs} +63 -26
  88. package/dist/github-BCdfZ9zO.cjs.map +1 -0
  89. package/dist/{github-DuuvqI3Z.mjs → github-CT3X720_.mjs} +63 -26
  90. package/dist/github-CT3X720_.mjs.map +1 -0
  91. package/dist/{index-5eL8rM6H.d.mts → index-DKtB01YC.d.cts} +2 -2
  92. package/dist/{index-5eL8rM6H.d.mts.map → index-DKtB01YC.d.cts.map} +1 -1
  93. package/dist/{index-Dz-gyjm_.d.cts → index-ZAUrXH6Q.d.mts} +2 -2
  94. package/dist/{index-Dz-gyjm_.d.cts.map → index-ZAUrXH6Q.d.mts.map} +1 -1
  95. package/dist/index.cjs +81 -62
  96. package/dist/index.cjs.map +1 -1
  97. package/dist/index.mjs +81 -62
  98. package/dist/index.mjs.map +1 -1
  99. package/dist/{migrate-CB8B6W9y.mjs → migrate-CCZUgxMK.mjs} +3 -3
  100. package/dist/{migrate-CB8B6W9y.mjs.map → migrate-CCZUgxMK.mjs.map} +1 -1
  101. package/dist/{migrate-BAmJeVq1.cjs → migrate-Cs7kQxD5.cjs} +3 -3
  102. package/dist/{migrate-BAmJeVq1.cjs.map → migrate-Cs7kQxD5.cjs.map} +1 -1
  103. package/dist/migrate-DBGyoBvZ.cjs +181 -0
  104. package/dist/migrate-DBGyoBvZ.cjs.map +1 -0
  105. package/dist/migrate-DH-lOK3j.mjs +181 -0
  106. package/dist/migrate-DH-lOK3j.mjs.map +1 -0
  107. package/dist/openapi.cjs +1 -1
  108. package/dist/openapi.d.cts +1 -1
  109. package/dist/openapi.d.mts +1 -1
  110. package/dist/openapi.mjs +1 -1
  111. package/dist/projectBucket-BjeDcAYy.cjs +206 -0
  112. package/dist/projectBucket-BjeDcAYy.cjs.map +1 -0
  113. package/dist/projectBucket-DrkEht-j.mjs +177 -0
  114. package/dist/projectBucket-DrkEht-j.mjs.map +1 -0
  115. package/dist/reconcile/public.d.cts +2 -2
  116. package/dist/reconcile/public.d.mts +2 -2
  117. package/dist/{resolve-BDatNOoG.cjs → resolve-CScrqgdC.cjs} +3 -3
  118. package/dist/{resolve-BDatNOoG.cjs.map → resolve-CScrqgdC.cjs.map} +1 -1
  119. package/dist/{resolve-CUne0qOm.mjs → resolve-OfLaxaxY.mjs} +3 -3
  120. package/dist/{resolve-CUne0qOm.mjs.map → resolve-OfLaxaxY.mjs.map} +1 -1
  121. package/dist/{rollback-CuG3DkTY.cjs → rollback-D7p4wJNO.cjs} +7 -6
  122. package/dist/{rollback-CuG3DkTY.cjs.map → rollback-D7p4wJNO.cjs.map} +1 -1
  123. package/dist/{rollback-CCdEEEcF.mjs → rollback-DQBSN-i7.mjs} +7 -6
  124. package/dist/{rollback-CCdEEEcF.mjs.map → rollback-DQBSN-i7.mjs.map} +1 -1
  125. package/dist/{runtime-Vr6mleo2.d.mts → runtime-BlHOVx8L.d.cts} +2 -2
  126. package/dist/{runtime-DUQdM-mW.d.cts.map → runtime-BlHOVx8L.d.cts.map} +1 -1
  127. package/dist/{runtime-DUQdM-mW.d.cts → runtime-DMq9C3KB.d.mts} +2 -2
  128. package/dist/{runtime-Vr6mleo2.d.mts.map → runtime-DMq9C3KB.d.mts.map} +1 -1
  129. package/dist/s3-CUKzBBae.mjs +215 -0
  130. package/dist/s3-CUKzBBae.mjs.map +1 -0
  131. package/dist/s3-QQi4sNOQ.cjs +215 -0
  132. package/dist/s3-QQi4sNOQ.cjs.map +1 -0
  133. package/dist/{sandbox-DGOsMPMf.d.mts → sandbox-ArJ_hEKk.d.cts} +2 -2
  134. package/dist/{sandbox-BbJmh2rI.d.cts.map → sandbox-ArJ_hEKk.d.cts.map} +1 -1
  135. package/dist/{sandbox-BbJmh2rI.d.cts → sandbox-Cm4X6HRh.d.mts} +2 -2
  136. package/dist/{sandbox-DGOsMPMf.d.mts.map → sandbox-Cm4X6HRh.d.mts.map} +1 -1
  137. package/dist/{secrets-ZikTIxEm.mjs → secrets-AA_tQUl-.mjs} +3 -3
  138. package/dist/{secrets-ZikTIxEm.mjs.map → secrets-AA_tQUl-.mjs.map} +1 -1
  139. package/dist/{secrets-C5qROlbp.cjs → secrets-B_biKsKx.cjs} +3 -3
  140. package/dist/{secrets-C5qROlbp.cjs.map → secrets-B_biKsKx.cjs.map} +1 -1
  141. package/dist/{secretsManager-C6wm-9uZ.mjs → secretsManager-CQORubp9.mjs} +2 -2
  142. package/dist/{secretsManager-C6wm-9uZ.mjs.map → secretsManager-CQORubp9.mjs.map} +1 -1
  143. package/dist/{secretsManager-Cwwgs81g.cjs → secretsManager-RAGcEDX1.cjs} +2 -2
  144. package/dist/{secretsManager-Cwwgs81g.cjs.map → secretsManager-RAGcEDX1.cjs.map} +1 -1
  145. package/dist/{seeds-CbJSne1A.mjs → seeds-BvxWUGKJ.mjs} +32 -6
  146. package/dist/seeds-BvxWUGKJ.mjs.map +1 -0
  147. package/dist/{seeds-BjXW-Krf.cjs → seeds-Df4BI-T3.cjs} +32 -6
  148. package/dist/seeds-Df4BI-T3.cjs.map +1 -0
  149. package/dist/{sniffer-DQGBYY8i.mjs → sniffer-BqjXvcaK.mjs} +77 -11
  150. package/dist/sniffer-BqjXvcaK.mjs.map +1 -0
  151. package/dist/{sniffer-NPD1dyab.cjs → sniffer-DZeQJKty.cjs} +100 -10
  152. package/dist/sniffer-DZeQJKty.cjs.map +1 -0
  153. package/dist/{stack-BFq3K-_z.mjs → stack-A6MAFZ6u.mjs} +3 -3
  154. package/dist/{stack-BFq3K-_z.mjs.map → stack-A6MAFZ6u.mjs.map} +1 -1
  155. package/dist/{stack-DOVvEd1T.cjs → stack-BpkZEEfB.cjs} +3 -3
  156. package/dist/{stack-DOVvEd1T.cjs.map → stack-BpkZEEfB.cjs.map} +1 -1
  157. package/dist/{stages-BEn2ArJZ.mjs → stages-6SEoRA4x.mjs} +6 -5
  158. package/dist/stages-6SEoRA4x.mjs.map +1 -0
  159. package/dist/{stages-Cw6urZyJ.cjs → stages-DH5z89eT.cjs} +6 -5
  160. package/dist/stages-DH5z89eT.cjs.map +1 -0
  161. package/dist/target/public.cjs +1 -1
  162. package/dist/target/public.d.cts +2 -2
  163. package/dist/target/public.d.mts +2 -2
  164. package/dist/target/public.mjs +1 -1
  165. package/dist/{types-dipJRmKV.d.cts → types-DipUP9zp.d.cts} +82 -11
  166. package/dist/types-DipUP9zp.d.cts.map +1 -0
  167. package/dist/{types-bkqVscdN.d.mts → types-Drpl9HX9.d.mts} +82 -11
  168. package/dist/types-Drpl9HX9.d.mts.map +1 -0
  169. package/dist/workspace/index.cjs +1 -1
  170. package/dist/workspace/index.d.cts +2 -2
  171. package/dist/workspace/index.d.mts +2 -2
  172. package/dist/workspace/index.mjs +1 -1
  173. package/dist/{workspace-CqFUjObk.mjs → workspace-BBeT6Pil.mjs} +63 -7
  174. package/dist/workspace-BBeT6Pil.mjs.map +1 -0
  175. package/dist/{workspace-DDkm4y6D.cjs → workspace-BJ78Bgvm.cjs} +74 -6
  176. package/dist/workspace-BJ78Bgvm.cjs.map +1 -0
  177. package/package.json +16 -15
  178. package/dist/S3StateStore-CoGk6ZKU.cjs.map +0 -1
  179. package/dist/S3StateStore-DP_7Q4yb.mjs.map +0 -1
  180. package/dist/SSMStateStore-Bo6_KDYY.mjs.map +0 -1
  181. package/dist/SSMStateStore-D9s4_Do3.cjs.map +0 -1
  182. package/dist/awsStore-B5We7bMg.cjs.map +0 -1
  183. package/dist/awsStore-BWa1KNY-.mjs.map +0 -1
  184. package/dist/deploy-BdN0ym2i.cjs.map +0 -1
  185. package/dist/github-CsMloeSL.cjs.map +0 -1
  186. package/dist/github-DuuvqI3Z.mjs.map +0 -1
  187. package/dist/migrate-BdkoNdIu.cjs +0 -94
  188. package/dist/migrate-BdkoNdIu.cjs.map +0 -1
  189. package/dist/migrate-CsPFHgTs.mjs +0 -94
  190. package/dist/migrate-CsPFHgTs.mjs.map +0 -1
  191. package/dist/seeds-BjXW-Krf.cjs.map +0 -1
  192. package/dist/seeds-CbJSne1A.mjs.map +0 -1
  193. package/dist/sniffer-DQGBYY8i.mjs.map +0 -1
  194. package/dist/sniffer-NPD1dyab.cjs.map +0 -1
  195. package/dist/stages-BEn2ArJZ.mjs.map +0 -1
  196. package/dist/stages-Cw6urZyJ.cjs.map +0 -1
  197. package/dist/types-bkqVscdN.d.mts.map +0 -1
  198. package/dist/types-dipJRmKV.d.cts.map +0 -1
  199. package/dist/workspace-CqFUjObk.mjs.map +0 -1
  200. package/dist/workspace-DDkm4y6D.cjs.map +0 -1
@@ -0,0 +1,215 @@
1
+ import { t as GkmError } from "./errors-D8Gwp5kU.mjs";
2
+ import { pt as s3SecretsKey } from "./workspace-BBeT6Pil.mjs";
3
+ import { a as projectBucketName, i as findProjectBucket, n as callerAccountId, r as ensureProjectBucket } from "./projectBucket-DrkEht-j.mjs";
4
+ import { r as withStageCredentials, t as awsClientConfig } from "./awsStore-Bx5nCFnS.mjs";
5
+ import { GetObjectCommand, HeadObjectCommand, PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
6
+ import { STSClient } from "@aws-sdk/client-sts";
7
+ //#region src/secrets/s3.ts
8
+ /**
9
+ * A stage's secrets in S3: one object per stage,
10
+ * `<prefix>/<project>/<stage>/secrets.json`, in the project bucket beside the
11
+ * deploy state (`providers/projectBucket.ts`) — or in a bucket the config
12
+ * names, which must exist.
13
+ *
14
+ * Encrypted at rest with SSE-S3, asked for on every write although the
15
+ * project bucket defaults to it, so no KMS key is another place to keep. The
16
+ * bucket's versioning keeps every past document. Unlike an SSM parameter
17
+ * there is no size to outgrow.
18
+ *
19
+ * The project bucket is created by the first write, never by a read: a stage
20
+ * whose bucket or object does not exist yet has no secrets. Every write is
21
+ * conditional — `If-Match` on the ETag this store last read for the stage,
22
+ * `If-None-Match: *` when it read none — so two `secrets:set` runs at once
23
+ * cannot each overwrite the other's key: the second is refused with
24
+ * {@link StageSecretsChanged}.
25
+ */
26
+ /**
27
+ * Another run wrote the stage's secrets after this one read them. Nothing was
28
+ * written: the change is to be made again, on top of theirs.
29
+ */
30
+ var StageSecretsChanged = class extends GkmError {
31
+ stage;
32
+ location;
33
+ constructor(stage, location) {
34
+ super(`The secrets for stage "${stage}" at ${location} changed after this command read them — another secrets command or deploy wrote them first. Nothing was written; run the command again to make the change on top of theirs.`);
35
+ this.stage = stage;
36
+ this.location = location;
37
+ this.name = "StageSecretsChanged";
38
+ }
39
+ };
40
+ /** A conditional write that lost: the object is not what the write assumed. */
41
+ function lostRace(error) {
42
+ const { name, $metadata } = error;
43
+ return name === "PreconditionFailed" || name === "ConditionalRequestConflict" || $metadata?.httpStatusCode === 412 || $metadata?.httpStatusCode === 409;
44
+ }
45
+ function notFound(error) {
46
+ const { name, $metadata } = error;
47
+ return name === "NoSuchKey" || name === "NotFound" || $metadata?.httpStatusCode === 404;
48
+ }
49
+ var S3SecretsStore = class {
50
+ options;
51
+ name = "s3";
52
+ clients;
53
+ /** The bucket's name, once known. */
54
+ bucketName;
55
+ /** Whether the bucket is known to exist. */
56
+ exists = false;
57
+ /** The ETag each stage was last read at — null: read, and not there. */
58
+ etags = /* @__PURE__ */ new Map();
59
+ constructor(options) {
60
+ this.options = options;
61
+ if (options.bucket) {
62
+ this.bucketName = options.bucket;
63
+ this.exists = true;
64
+ }
65
+ }
66
+ /** The bucket's name; the project bucket's is known after the first call. */
67
+ get bucket() {
68
+ return this.bucketName ?? projectBucketName(this.options.identity.scope, "<account id>");
69
+ }
70
+ /** Where a stage's secrets are kept: `s3://<bucket>/<key>`. */
71
+ location(stage) {
72
+ return `s3://${this.bucket}/${this.key(stage)}`;
73
+ }
74
+ key(stage) {
75
+ return s3SecretsKey(this.options.prefix, this.options.project, stage);
76
+ }
77
+ async client() {
78
+ if (this.clients) return this.clients;
79
+ const base = await awsClientConfig(this.options);
80
+ const endpoint = base.endpoint ?? process.env.AWS_ENDPOINT_URL_S3 ?? process.env.AWS_ENDPOINT_URL;
81
+ const credentials = this.options.credentials ?? base.credentials;
82
+ this.clients = {
83
+ s3: new S3Client({
84
+ region: base.region,
85
+ ...endpoint ? {
86
+ endpoint,
87
+ forcePathStyle: true
88
+ } : {},
89
+ ...credentials ? { credentials } : {}
90
+ }),
91
+ sts: new STSClient({
92
+ region: base.region,
93
+ ...base.endpoint ? { endpoint: base.endpoint } : {},
94
+ ...credentials ? { credentials } : {}
95
+ })
96
+ };
97
+ return this.clients;
98
+ }
99
+ /** One AWS call, a missing or expired credential refused by name. */
100
+ call(stage, access, run) {
101
+ return withStageCredentials({
102
+ stage,
103
+ store: this.name,
104
+ profile: this.options.profile,
105
+ access
106
+ }, run);
107
+ }
108
+ /**
109
+ * The bucket, or null for a project bucket that does not exist yet and is
110
+ * not to be created (a read).
111
+ */
112
+ async use(stage, create) {
113
+ const { s3, sts } = await this.client();
114
+ if (this.exists) return {
115
+ s3,
116
+ bucket: this.bucketName
117
+ };
118
+ const access = create ? "write" : "read";
119
+ this.bucketName ??= projectBucketName(this.options.identity.scope, await this.call(stage, access, () => callerAccountId(sts)));
120
+ const bucket = this.bucketName;
121
+ if (create) await this.call(stage, access, () => ensureProjectBucket(s3, {
122
+ bucket,
123
+ region: this.options.region,
124
+ identity: this.options.identity
125
+ }));
126
+ else if (await this.call(stage, access, () => findProjectBucket(s3, bucket)) === "none") return {
127
+ s3,
128
+ bucket: null
129
+ };
130
+ this.exists = true;
131
+ return {
132
+ s3,
133
+ bucket
134
+ };
135
+ }
136
+ /**
137
+ * @throws {StageSecretsUnreadable} when there are no AWS credentials to
138
+ * read it with, or they have expired
139
+ */
140
+ async read(stage) {
141
+ const { s3, bucket } = await this.use(stage, false);
142
+ if (!bucket) {
143
+ this.etags.set(stage, null);
144
+ return null;
145
+ }
146
+ try {
147
+ const response = await this.call(stage, "read", () => s3.send(new GetObjectCommand({
148
+ Bucket: bucket,
149
+ Key: this.key(stage)
150
+ })));
151
+ const body = await response.Body.transformToString("utf-8");
152
+ this.remember(stage, response.ETag);
153
+ return JSON.parse(body);
154
+ } catch (error) {
155
+ if (!notFound(error)) throw error;
156
+ this.etags.set(stage, null);
157
+ return null;
158
+ }
159
+ }
160
+ /**
161
+ * Replace the stage's secrets — on the condition that they are still what
162
+ * this store last read. A stage never read here is replaced as it is now.
163
+ *
164
+ * @throws {StageSecretsChanged} when another run wrote them in between
165
+ * @throws {StageSecretsUnreadable} when there are no AWS credentials to
166
+ * write it with, or they have expired
167
+ */
168
+ async write(stage, secrets) {
169
+ const { s3, bucket } = await this.use(stage, true);
170
+ const Bucket = bucket;
171
+ const Key = this.key(stage);
172
+ const expected = this.etags.has(stage) ? this.etags.get(stage) ?? null : await this.currentEtag(s3, stage, Bucket, Key);
173
+ try {
174
+ const { ETag } = await this.call(stage, "write", () => s3.send(new PutObjectCommand({
175
+ Bucket,
176
+ Key,
177
+ Body: JSON.stringify(secrets),
178
+ ContentType: "application/json",
179
+ ServerSideEncryption: "AES256",
180
+ ...expected === null ? { IfNoneMatch: "*" } : { IfMatch: expected }
181
+ })));
182
+ this.remember(stage, ETag);
183
+ } catch (error) {
184
+ if (lostRace(error)) {
185
+ this.etags.delete(stage);
186
+ throw new StageSecretsChanged(stage, `s3://${Bucket}/${Key}`);
187
+ }
188
+ throw error;
189
+ }
190
+ }
191
+ /**
192
+ * The ETag the stage is now at. Some S3-compatible servers answer without
193
+ * one: then nothing is remembered, and the next write asks for it first.
194
+ */
195
+ remember(stage, etag) {
196
+ if (etag) this.etags.set(stage, etag);
197
+ else this.etags.delete(stage);
198
+ }
199
+ async currentEtag(s3, stage, Bucket, Key) {
200
+ try {
201
+ const { ETag } = await this.call(stage, "write", () => s3.send(new HeadObjectCommand({
202
+ Bucket,
203
+ Key
204
+ })));
205
+ return ETag ?? null;
206
+ } catch (error) {
207
+ if (notFound(error)) return null;
208
+ throw error;
209
+ }
210
+ }
211
+ };
212
+ //#endregion
213
+ export { S3SecretsStore };
214
+
215
+ //# sourceMappingURL=s3-CUKzBBae.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3-CUKzBBae.mjs","names":[],"sources":["../src/secrets/s3.ts"],"sourcesContent":["/**\n * A stage's secrets in S3: one object per stage,\n * `<prefix>/<project>/<stage>/secrets.json`, in the project bucket beside the\n * deploy state (`providers/projectBucket.ts`) — or in a bucket the config\n * names, which must exist.\n *\n * Encrypted at rest with SSE-S3, asked for on every write although the\n * project bucket defaults to it, so no KMS key is another place to keep. The\n * bucket's versioning keeps every past document. Unlike an SSM parameter\n * there is no size to outgrow.\n *\n * The project bucket is created by the first write, never by a read: a stage\n * whose bucket or object does not exist yet has no secrets. Every write is\n * conditional — `If-Match` on the ETag this store last read for the stage,\n * `If-None-Match: *` when it read none — so two `secrets:set` runs at once\n * cannot each overwrite the other's key: the second is refused with\n * {@link StageSecretsChanged}.\n */\n\nimport {\n\tGetObjectCommand,\n\tHeadObjectCommand,\n\tPutObjectCommand,\n\tS3Client,\n\ttype S3ClientConfig,\n} from '@aws-sdk/client-s3';\nimport { STSClient } from '@aws-sdk/client-sts';\nimport type { DeployIdentity } from '../deploy/identity.js';\nimport { GkmError } from '../errors';\nimport {\n\tcallerAccountId,\n\tensureProjectBucket,\n\tfindProjectBucket,\n\tprojectBucketName,\n} from '../providers/projectBucket.js';\nimport {\n\ttype AwsStoreOptions,\n\tawsClientConfig,\n\twithStageCredentials,\n} from './awsStore.js';\nimport { s3SecretsKey } from './providers.js';\nimport type { SecretsStore } from './store.js';\nimport type { StageSecrets } from './types.js';\n\nexport interface S3SecretsStoreOptions extends AwsStoreOptions {\n\t/** The deploy identity: the project bucket's name and its tag. */\n\tidentity: Pick<DeployIdentity, 'scope' | 'key'>;\n\t/** A bucket that exists; omitted, the project bucket. */\n\tbucket?: string;\n\t/** Key prefix inside the bucket, without a trailing slash. */\n\tprefix: string;\n\t/** For tests: credentials to use instead of the default chain. */\n\tcredentials?: S3ClientConfig['credentials'];\n}\n\n/**\n * Another run wrote the stage's secrets after this one read them. Nothing was\n * written: the change is to be made again, on top of theirs.\n */\nexport class StageSecretsChanged extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\t/** `s3://<bucket>/<key>` */\n\t\treadonly location: string,\n\t) {\n\t\tsuper(\n\t\t\t`The secrets for stage \"${stage}\" at ${location} changed after this command read them — ` +\n\t\t\t\t'another secrets command or deploy wrote them first. Nothing was written; run the command ' +\n\t\t\t\t'again to make the change on top of theirs.',\n\t\t);\n\t\tthis.name = 'StageSecretsChanged';\n\t}\n}\n\ninterface S3Failure {\n\tname?: string;\n\t$metadata?: { httpStatusCode?: number };\n}\n\n/** A conditional write that lost: the object is not what the write assumed. */\nfunction lostRace(error: unknown): boolean {\n\tconst { name, $metadata } = error as S3Failure;\n\treturn (\n\t\tname === 'PreconditionFailed' ||\n\t\tname === 'ConditionalRequestConflict' ||\n\t\t$metadata?.httpStatusCode === 412 ||\n\t\t$metadata?.httpStatusCode === 409\n\t);\n}\n\nfunction notFound(error: unknown): boolean {\n\tconst { name, $metadata } = error as S3Failure;\n\treturn (\n\t\tname === 'NoSuchKey' ||\n\t\tname === 'NotFound' ||\n\t\t$metadata?.httpStatusCode === 404\n\t);\n}\n\nexport class S3SecretsStore implements SecretsStore {\n\treadonly name = 's3';\n\n\tprivate clients?: { s3: S3Client; sts: STSClient };\n\t/** The bucket's name, once known. */\n\tprivate bucketName?: string;\n\t/** Whether the bucket is known to exist. */\n\tprivate exists = false;\n\t/** The ETag each stage was last read at — null: read, and not there. */\n\tprivate readonly etags = new Map<string, string | null>();\n\n\tconstructor(private readonly options: S3SecretsStoreOptions) {\n\t\tif (options.bucket) {\n\t\t\tthis.bucketName = options.bucket;\n\t\t\tthis.exists = true;\n\t\t}\n\t}\n\n\t/** The bucket's name; the project bucket's is known after the first call. */\n\tget bucket(): string {\n\t\treturn (\n\t\t\tthis.bucketName ??\n\t\t\tprojectBucketName(this.options.identity.scope, '<account id>')\n\t\t);\n\t}\n\n\t/** Where a stage's secrets are kept: `s3://<bucket>/<key>`. */\n\tlocation(stage: string): string {\n\t\treturn `s3://${this.bucket}/${this.key(stage)}`;\n\t}\n\n\tprivate key(stage: string): string {\n\t\treturn s3SecretsKey(this.options.prefix, this.options.project, stage);\n\t}\n\n\tprivate async client(): Promise<{ s3: S3Client; sts: STSClient }> {\n\t\tif (this.clients) return this.clients;\n\t\tconst base = await awsClientConfig(this.options);\n\t\tconst endpoint =\n\t\t\tbase.endpoint ??\n\t\t\tprocess.env.AWS_ENDPOINT_URL_S3 ??\n\t\t\tprocess.env.AWS_ENDPOINT_URL;\n\t\tconst credentials = this.options.credentials ?? base.credentials;\n\t\tthis.clients = {\n\t\t\ts3: new S3Client({\n\t\t\t\tregion: base.region,\n\t\t\t\t...(endpoint ? { endpoint, forcePathStyle: true } : {}),\n\t\t\t\t...(credentials ? { credentials } : {}),\n\t\t\t}),\n\t\t\tsts: new STSClient({\n\t\t\t\tregion: base.region,\n\t\t\t\t...(base.endpoint ? { endpoint: base.endpoint } : {}),\n\t\t\t\t...(credentials ? { credentials } : {}),\n\t\t\t}),\n\t\t};\n\t\treturn this.clients;\n\t}\n\n\t/** One AWS call, a missing or expired credential refused by name. */\n\tprivate call<T>(\n\t\tstage: string,\n\t\taccess: 'read' | 'write',\n\t\trun: () => Promise<T>,\n\t): Promise<T> {\n\t\treturn withStageCredentials(\n\t\t\t{ stage, store: this.name, profile: this.options.profile, access },\n\t\t\trun,\n\t\t);\n\t}\n\n\t/**\n\t * The bucket, or null for a project bucket that does not exist yet and is\n\t * not to be created (a read).\n\t */\n\tprivate async use(\n\t\tstage: string,\n\t\tcreate: boolean,\n\t): Promise<{ s3: S3Client; bucket: string | null }> {\n\t\tconst { s3, sts } = await this.client();\n\t\tif (this.exists) return { s3, bucket: this.bucketName! };\n\t\tconst access = create ? 'write' : 'read';\n\t\tthis.bucketName ??= projectBucketName(\n\t\t\tthis.options.identity.scope,\n\t\t\tawait this.call(stage, access, () => callerAccountId(sts)),\n\t\t);\n\t\tconst bucket = this.bucketName;\n\t\tif (create) {\n\t\t\tawait this.call(stage, access, () =>\n\t\t\t\tensureProjectBucket(s3, {\n\t\t\t\t\tbucket,\n\t\t\t\t\tregion: this.options.region,\n\t\t\t\t\tidentity: this.options.identity,\n\t\t\t\t}),\n\t\t\t);\n\t\t} else if (\n\t\t\t(await this.call(stage, access, () => findProjectBucket(s3, bucket))) ===\n\t\t\t'none'\n\t\t) {\n\t\t\treturn { s3, bucket: null };\n\t\t}\n\t\tthis.exists = true;\n\t\treturn { s3, bucket };\n\t}\n\n\t/**\n\t * @throws {StageSecretsUnreadable} when there are no AWS credentials to\n\t * read it with, or they have expired\n\t */\n\tasync read(stage: string): Promise<StageSecrets | null> {\n\t\tconst { s3, bucket } = await this.use(stage, false);\n\t\tif (!bucket) {\n\t\t\tthis.etags.set(stage, null);\n\t\t\treturn null;\n\t\t}\n\t\ttry {\n\t\t\tconst response = await this.call(stage, 'read', () =>\n\t\t\t\ts3.send(new GetObjectCommand({ Bucket: bucket, Key: this.key(stage) })),\n\t\t\t);\n\t\t\tconst body = await (\n\t\t\t\tresponse.Body as {\n\t\t\t\t\ttransformToString(encoding: string): Promise<string>;\n\t\t\t\t}\n\t\t\t).transformToString('utf-8');\n\t\t\tthis.remember(stage, response.ETag);\n\t\t\treturn JSON.parse(body) as StageSecrets;\n\t\t} catch (error) {\n\t\t\tif (!notFound(error)) throw error;\n\t\t\tthis.etags.set(stage, null);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Replace the stage's secrets — on the condition that they are still what\n\t * this store last read. A stage never read here is replaced as it is now.\n\t *\n\t * @throws {StageSecretsChanged} when another run wrote them in between\n\t * @throws {StageSecretsUnreadable} when there are no AWS credentials to\n\t * write it with, or they have expired\n\t */\n\tasync write(stage: string, secrets: StageSecrets): Promise<void> {\n\t\tconst { s3, bucket } = await this.use(stage, true);\n\t\tconst Bucket = bucket!;\n\t\tconst Key = this.key(stage);\n\t\tconst expected = this.etags.has(stage)\n\t\t\t? (this.etags.get(stage) ?? null)\n\t\t\t: await this.currentEtag(s3, stage, Bucket, Key);\n\n\t\ttry {\n\t\t\tconst { ETag } = await this.call(stage, 'write', () =>\n\t\t\t\ts3.send(\n\t\t\t\t\tnew PutObjectCommand({\n\t\t\t\t\t\tBucket,\n\t\t\t\t\t\tKey,\n\t\t\t\t\t\tBody: JSON.stringify(secrets),\n\t\t\t\t\t\tContentType: 'application/json',\n\t\t\t\t\t\tServerSideEncryption: 'AES256',\n\t\t\t\t\t\t...(expected === null\n\t\t\t\t\t\t\t? { IfNoneMatch: '*' }\n\t\t\t\t\t\t\t: { IfMatch: expected }),\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t);\n\t\t\tthis.remember(stage, ETag);\n\t\t} catch (error) {\n\t\t\tif (lostRace(error)) {\n\t\t\t\tthis.etags.delete(stage);\n\t\t\t\tthrow new StageSecretsChanged(stage, `s3://${Bucket}/${Key}`);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * The ETag the stage is now at. Some S3-compatible servers answer without\n\t * one: then nothing is remembered, and the next write asks for it first.\n\t */\n\tprivate remember(stage: string, etag: string | undefined): void {\n\t\tif (etag) this.etags.set(stage, etag);\n\t\telse this.etags.delete(stage);\n\t}\n\n\tprivate async currentEtag(\n\t\ts3: S3Client,\n\t\tstage: string,\n\t\tBucket: string,\n\t\tKey: string,\n\t): Promise<string | null> {\n\t\ttry {\n\t\t\tconst { ETag } = await this.call(stage, 'write', () =>\n\t\t\t\ts3.send(new HeadObjectCommand({ Bucket, Key })),\n\t\t\t);\n\t\t\treturn ETag ?? null;\n\t\t} catch (error) {\n\t\t\tif (notFound(error)) return null;\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,IAAa,sBAAb,cAAyC,SAAS;CAEvC;CAEA;CAHV,YACC,OAEA,UACC;EACD,MACC,0BAA0B,MAAM,OAAO,SAAS,4KAGjD;EARS,KAAA,QAAA;EAEA,KAAA,WAAA;EAOT,K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ACD;AACD"}
@@ -0,0 +1,215 @@
1
+ const require_errors = require("./errors-DMC4Umsb.cjs");
2
+ const require_workspace = require("./workspace-BJ78Bgvm.cjs");
3
+ const require_projectBucket = require("./projectBucket-BjeDcAYy.cjs");
4
+ const require_awsStore = require("./awsStore-u3ehhMoY.cjs");
5
+ let _aws_sdk_client_s3 = require("@aws-sdk/client-s3");
6
+ let _aws_sdk_client_sts = require("@aws-sdk/client-sts");
7
+ //#region src/secrets/s3.ts
8
+ /**
9
+ * A stage's secrets in S3: one object per stage,
10
+ * `<prefix>/<project>/<stage>/secrets.json`, in the project bucket beside the
11
+ * deploy state (`providers/projectBucket.ts`) — or in a bucket the config
12
+ * names, which must exist.
13
+ *
14
+ * Encrypted at rest with SSE-S3, asked for on every write although the
15
+ * project bucket defaults to it, so no KMS key is another place to keep. The
16
+ * bucket's versioning keeps every past document. Unlike an SSM parameter
17
+ * there is no size to outgrow.
18
+ *
19
+ * The project bucket is created by the first write, never by a read: a stage
20
+ * whose bucket or object does not exist yet has no secrets. Every write is
21
+ * conditional — `If-Match` on the ETag this store last read for the stage,
22
+ * `If-None-Match: *` when it read none — so two `secrets:set` runs at once
23
+ * cannot each overwrite the other's key: the second is refused with
24
+ * {@link StageSecretsChanged}.
25
+ */
26
+ /**
27
+ * Another run wrote the stage's secrets after this one read them. Nothing was
28
+ * written: the change is to be made again, on top of theirs.
29
+ */
30
+ var StageSecretsChanged = class extends require_errors.GkmError {
31
+ stage;
32
+ location;
33
+ constructor(stage, location) {
34
+ super(`The secrets for stage "${stage}" at ${location} changed after this command read them — another secrets command or deploy wrote them first. Nothing was written; run the command again to make the change on top of theirs.`);
35
+ this.stage = stage;
36
+ this.location = location;
37
+ this.name = "StageSecretsChanged";
38
+ }
39
+ };
40
+ /** A conditional write that lost: the object is not what the write assumed. */
41
+ function lostRace(error) {
42
+ const { name, $metadata } = error;
43
+ return name === "PreconditionFailed" || name === "ConditionalRequestConflict" || $metadata?.httpStatusCode === 412 || $metadata?.httpStatusCode === 409;
44
+ }
45
+ function notFound(error) {
46
+ const { name, $metadata } = error;
47
+ return name === "NoSuchKey" || name === "NotFound" || $metadata?.httpStatusCode === 404;
48
+ }
49
+ var S3SecretsStore = class {
50
+ options;
51
+ name = "s3";
52
+ clients;
53
+ /** The bucket's name, once known. */
54
+ bucketName;
55
+ /** Whether the bucket is known to exist. */
56
+ exists = false;
57
+ /** The ETag each stage was last read at — null: read, and not there. */
58
+ etags = /* @__PURE__ */ new Map();
59
+ constructor(options) {
60
+ this.options = options;
61
+ if (options.bucket) {
62
+ this.bucketName = options.bucket;
63
+ this.exists = true;
64
+ }
65
+ }
66
+ /** The bucket's name; the project bucket's is known after the first call. */
67
+ get bucket() {
68
+ return this.bucketName ?? require_projectBucket.projectBucketName(this.options.identity.scope, "<account id>");
69
+ }
70
+ /** Where a stage's secrets are kept: `s3://<bucket>/<key>`. */
71
+ location(stage) {
72
+ return `s3://${this.bucket}/${this.key(stage)}`;
73
+ }
74
+ key(stage) {
75
+ return require_workspace.s3SecretsKey(this.options.prefix, this.options.project, stage);
76
+ }
77
+ async client() {
78
+ if (this.clients) return this.clients;
79
+ const base = await require_awsStore.awsClientConfig(this.options);
80
+ const endpoint = base.endpoint ?? process.env.AWS_ENDPOINT_URL_S3 ?? process.env.AWS_ENDPOINT_URL;
81
+ const credentials = this.options.credentials ?? base.credentials;
82
+ this.clients = {
83
+ s3: new _aws_sdk_client_s3.S3Client({
84
+ region: base.region,
85
+ ...endpoint ? {
86
+ endpoint,
87
+ forcePathStyle: true
88
+ } : {},
89
+ ...credentials ? { credentials } : {}
90
+ }),
91
+ sts: new _aws_sdk_client_sts.STSClient({
92
+ region: base.region,
93
+ ...base.endpoint ? { endpoint: base.endpoint } : {},
94
+ ...credentials ? { credentials } : {}
95
+ })
96
+ };
97
+ return this.clients;
98
+ }
99
+ /** One AWS call, a missing or expired credential refused by name. */
100
+ call(stage, access, run) {
101
+ return require_awsStore.withStageCredentials({
102
+ stage,
103
+ store: this.name,
104
+ profile: this.options.profile,
105
+ access
106
+ }, run);
107
+ }
108
+ /**
109
+ * The bucket, or null for a project bucket that does not exist yet and is
110
+ * not to be created (a read).
111
+ */
112
+ async use(stage, create) {
113
+ const { s3, sts } = await this.client();
114
+ if (this.exists) return {
115
+ s3,
116
+ bucket: this.bucketName
117
+ };
118
+ const access = create ? "write" : "read";
119
+ this.bucketName ??= require_projectBucket.projectBucketName(this.options.identity.scope, await this.call(stage, access, () => require_projectBucket.callerAccountId(sts)));
120
+ const bucket = this.bucketName;
121
+ if (create) await this.call(stage, access, () => require_projectBucket.ensureProjectBucket(s3, {
122
+ bucket,
123
+ region: this.options.region,
124
+ identity: this.options.identity
125
+ }));
126
+ else if (await this.call(stage, access, () => require_projectBucket.findProjectBucket(s3, bucket)) === "none") return {
127
+ s3,
128
+ bucket: null
129
+ };
130
+ this.exists = true;
131
+ return {
132
+ s3,
133
+ bucket
134
+ };
135
+ }
136
+ /**
137
+ * @throws {StageSecretsUnreadable} when there are no AWS credentials to
138
+ * read it with, or they have expired
139
+ */
140
+ async read(stage) {
141
+ const { s3, bucket } = await this.use(stage, false);
142
+ if (!bucket) {
143
+ this.etags.set(stage, null);
144
+ return null;
145
+ }
146
+ try {
147
+ const response = await this.call(stage, "read", () => s3.send(new _aws_sdk_client_s3.GetObjectCommand({
148
+ Bucket: bucket,
149
+ Key: this.key(stage)
150
+ })));
151
+ const body = await response.Body.transformToString("utf-8");
152
+ this.remember(stage, response.ETag);
153
+ return JSON.parse(body);
154
+ } catch (error) {
155
+ if (!notFound(error)) throw error;
156
+ this.etags.set(stage, null);
157
+ return null;
158
+ }
159
+ }
160
+ /**
161
+ * Replace the stage's secrets — on the condition that they are still what
162
+ * this store last read. A stage never read here is replaced as it is now.
163
+ *
164
+ * @throws {StageSecretsChanged} when another run wrote them in between
165
+ * @throws {StageSecretsUnreadable} when there are no AWS credentials to
166
+ * write it with, or they have expired
167
+ */
168
+ async write(stage, secrets) {
169
+ const { s3, bucket } = await this.use(stage, true);
170
+ const Bucket = bucket;
171
+ const Key = this.key(stage);
172
+ const expected = this.etags.has(stage) ? this.etags.get(stage) ?? null : await this.currentEtag(s3, stage, Bucket, Key);
173
+ try {
174
+ const { ETag } = await this.call(stage, "write", () => s3.send(new _aws_sdk_client_s3.PutObjectCommand({
175
+ Bucket,
176
+ Key,
177
+ Body: JSON.stringify(secrets),
178
+ ContentType: "application/json",
179
+ ServerSideEncryption: "AES256",
180
+ ...expected === null ? { IfNoneMatch: "*" } : { IfMatch: expected }
181
+ })));
182
+ this.remember(stage, ETag);
183
+ } catch (error) {
184
+ if (lostRace(error)) {
185
+ this.etags.delete(stage);
186
+ throw new StageSecretsChanged(stage, `s3://${Bucket}/${Key}`);
187
+ }
188
+ throw error;
189
+ }
190
+ }
191
+ /**
192
+ * The ETag the stage is now at. Some S3-compatible servers answer without
193
+ * one: then nothing is remembered, and the next write asks for it first.
194
+ */
195
+ remember(stage, etag) {
196
+ if (etag) this.etags.set(stage, etag);
197
+ else this.etags.delete(stage);
198
+ }
199
+ async currentEtag(s3, stage, Bucket, Key) {
200
+ try {
201
+ const { ETag } = await this.call(stage, "write", () => s3.send(new _aws_sdk_client_s3.HeadObjectCommand({
202
+ Bucket,
203
+ Key
204
+ })));
205
+ return ETag ?? null;
206
+ } catch (error) {
207
+ if (notFound(error)) return null;
208
+ throw error;
209
+ }
210
+ }
211
+ };
212
+ //#endregion
213
+ exports.S3SecretsStore = S3SecretsStore;
214
+
215
+ //# sourceMappingURL=s3-QQi4sNOQ.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3-QQi4sNOQ.cjs","names":["GkmError","projectBucketName","s3SecretsKey","awsClientConfig","S3Client","STSClient","withStageCredentials","callerAccountId","ensureProjectBucket","findProjectBucket","GetObjectCommand","PutObjectCommand","HeadObjectCommand"],"sources":["../src/secrets/s3.ts"],"sourcesContent":["/**\n * A stage's secrets in S3: one object per stage,\n * `<prefix>/<project>/<stage>/secrets.json`, in the project bucket beside the\n * deploy state (`providers/projectBucket.ts`) — or in a bucket the config\n * names, which must exist.\n *\n * Encrypted at rest with SSE-S3, asked for on every write although the\n * project bucket defaults to it, so no KMS key is another place to keep. The\n * bucket's versioning keeps every past document. Unlike an SSM parameter\n * there is no size to outgrow.\n *\n * The project bucket is created by the first write, never by a read: a stage\n * whose bucket or object does not exist yet has no secrets. Every write is\n * conditional — `If-Match` on the ETag this store last read for the stage,\n * `If-None-Match: *` when it read none — so two `secrets:set` runs at once\n * cannot each overwrite the other's key: the second is refused with\n * {@link StageSecretsChanged}.\n */\n\nimport {\n\tGetObjectCommand,\n\tHeadObjectCommand,\n\tPutObjectCommand,\n\tS3Client,\n\ttype S3ClientConfig,\n} from '@aws-sdk/client-s3';\nimport { STSClient } from '@aws-sdk/client-sts';\nimport type { DeployIdentity } from '../deploy/identity.js';\nimport { GkmError } from '../errors';\nimport {\n\tcallerAccountId,\n\tensureProjectBucket,\n\tfindProjectBucket,\n\tprojectBucketName,\n} from '../providers/projectBucket.js';\nimport {\n\ttype AwsStoreOptions,\n\tawsClientConfig,\n\twithStageCredentials,\n} from './awsStore.js';\nimport { s3SecretsKey } from './providers.js';\nimport type { SecretsStore } from './store.js';\nimport type { StageSecrets } from './types.js';\n\nexport interface S3SecretsStoreOptions extends AwsStoreOptions {\n\t/** The deploy identity: the project bucket's name and its tag. */\n\tidentity: Pick<DeployIdentity, 'scope' | 'key'>;\n\t/** A bucket that exists; omitted, the project bucket. */\n\tbucket?: string;\n\t/** Key prefix inside the bucket, without a trailing slash. */\n\tprefix: string;\n\t/** For tests: credentials to use instead of the default chain. */\n\tcredentials?: S3ClientConfig['credentials'];\n}\n\n/**\n * Another run wrote the stage's secrets after this one read them. Nothing was\n * written: the change is to be made again, on top of theirs.\n */\nexport class StageSecretsChanged extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\t/** `s3://<bucket>/<key>` */\n\t\treadonly location: string,\n\t) {\n\t\tsuper(\n\t\t\t`The secrets for stage \"${stage}\" at ${location} changed after this command read them — ` +\n\t\t\t\t'another secrets command or deploy wrote them first. Nothing was written; run the command ' +\n\t\t\t\t'again to make the change on top of theirs.',\n\t\t);\n\t\tthis.name = 'StageSecretsChanged';\n\t}\n}\n\ninterface S3Failure {\n\tname?: string;\n\t$metadata?: { httpStatusCode?: number };\n}\n\n/** A conditional write that lost: the object is not what the write assumed. */\nfunction lostRace(error: unknown): boolean {\n\tconst { name, $metadata } = error as S3Failure;\n\treturn (\n\t\tname === 'PreconditionFailed' ||\n\t\tname === 'ConditionalRequestConflict' ||\n\t\t$metadata?.httpStatusCode === 412 ||\n\t\t$metadata?.httpStatusCode === 409\n\t);\n}\n\nfunction notFound(error: unknown): boolean {\n\tconst { name, $metadata } = error as S3Failure;\n\treturn (\n\t\tname === 'NoSuchKey' ||\n\t\tname === 'NotFound' ||\n\t\t$metadata?.httpStatusCode === 404\n\t);\n}\n\nexport class S3SecretsStore implements SecretsStore {\n\treadonly name = 's3';\n\n\tprivate clients?: { s3: S3Client; sts: STSClient };\n\t/** The bucket's name, once known. */\n\tprivate bucketName?: string;\n\t/** Whether the bucket is known to exist. */\n\tprivate exists = false;\n\t/** The ETag each stage was last read at — null: read, and not there. */\n\tprivate readonly etags = new Map<string, string | null>();\n\n\tconstructor(private readonly options: S3SecretsStoreOptions) {\n\t\tif (options.bucket) {\n\t\t\tthis.bucketName = options.bucket;\n\t\t\tthis.exists = true;\n\t\t}\n\t}\n\n\t/** The bucket's name; the project bucket's is known after the first call. */\n\tget bucket(): string {\n\t\treturn (\n\t\t\tthis.bucketName ??\n\t\t\tprojectBucketName(this.options.identity.scope, '<account id>')\n\t\t);\n\t}\n\n\t/** Where a stage's secrets are kept: `s3://<bucket>/<key>`. */\n\tlocation(stage: string): string {\n\t\treturn `s3://${this.bucket}/${this.key(stage)}`;\n\t}\n\n\tprivate key(stage: string): string {\n\t\treturn s3SecretsKey(this.options.prefix, this.options.project, stage);\n\t}\n\n\tprivate async client(): Promise<{ s3: S3Client; sts: STSClient }> {\n\t\tif (this.clients) return this.clients;\n\t\tconst base = await awsClientConfig(this.options);\n\t\tconst endpoint =\n\t\t\tbase.endpoint ??\n\t\t\tprocess.env.AWS_ENDPOINT_URL_S3 ??\n\t\t\tprocess.env.AWS_ENDPOINT_URL;\n\t\tconst credentials = this.options.credentials ?? base.credentials;\n\t\tthis.clients = {\n\t\t\ts3: new S3Client({\n\t\t\t\tregion: base.region,\n\t\t\t\t...(endpoint ? { endpoint, forcePathStyle: true } : {}),\n\t\t\t\t...(credentials ? { credentials } : {}),\n\t\t\t}),\n\t\t\tsts: new STSClient({\n\t\t\t\tregion: base.region,\n\t\t\t\t...(base.endpoint ? { endpoint: base.endpoint } : {}),\n\t\t\t\t...(credentials ? { credentials } : {}),\n\t\t\t}),\n\t\t};\n\t\treturn this.clients;\n\t}\n\n\t/** One AWS call, a missing or expired credential refused by name. */\n\tprivate call<T>(\n\t\tstage: string,\n\t\taccess: 'read' | 'write',\n\t\trun: () => Promise<T>,\n\t): Promise<T> {\n\t\treturn withStageCredentials(\n\t\t\t{ stage, store: this.name, profile: this.options.profile, access },\n\t\t\trun,\n\t\t);\n\t}\n\n\t/**\n\t * The bucket, or null for a project bucket that does not exist yet and is\n\t * not to be created (a read).\n\t */\n\tprivate async use(\n\t\tstage: string,\n\t\tcreate: boolean,\n\t): Promise<{ s3: S3Client; bucket: string | null }> {\n\t\tconst { s3, sts } = await this.client();\n\t\tif (this.exists) return { s3, bucket: this.bucketName! };\n\t\tconst access = create ? 'write' : 'read';\n\t\tthis.bucketName ??= projectBucketName(\n\t\t\tthis.options.identity.scope,\n\t\t\tawait this.call(stage, access, () => callerAccountId(sts)),\n\t\t);\n\t\tconst bucket = this.bucketName;\n\t\tif (create) {\n\t\t\tawait this.call(stage, access, () =>\n\t\t\t\tensureProjectBucket(s3, {\n\t\t\t\t\tbucket,\n\t\t\t\t\tregion: this.options.region,\n\t\t\t\t\tidentity: this.options.identity,\n\t\t\t\t}),\n\t\t\t);\n\t\t} else if (\n\t\t\t(await this.call(stage, access, () => findProjectBucket(s3, bucket))) ===\n\t\t\t'none'\n\t\t) {\n\t\t\treturn { s3, bucket: null };\n\t\t}\n\t\tthis.exists = true;\n\t\treturn { s3, bucket };\n\t}\n\n\t/**\n\t * @throws {StageSecretsUnreadable} when there are no AWS credentials to\n\t * read it with, or they have expired\n\t */\n\tasync read(stage: string): Promise<StageSecrets | null> {\n\t\tconst { s3, bucket } = await this.use(stage, false);\n\t\tif (!bucket) {\n\t\t\tthis.etags.set(stage, null);\n\t\t\treturn null;\n\t\t}\n\t\ttry {\n\t\t\tconst response = await this.call(stage, 'read', () =>\n\t\t\t\ts3.send(new GetObjectCommand({ Bucket: bucket, Key: this.key(stage) })),\n\t\t\t);\n\t\t\tconst body = await (\n\t\t\t\tresponse.Body as {\n\t\t\t\t\ttransformToString(encoding: string): Promise<string>;\n\t\t\t\t}\n\t\t\t).transformToString('utf-8');\n\t\t\tthis.remember(stage, response.ETag);\n\t\t\treturn JSON.parse(body) as StageSecrets;\n\t\t} catch (error) {\n\t\t\tif (!notFound(error)) throw error;\n\t\t\tthis.etags.set(stage, null);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Replace the stage's secrets — on the condition that they are still what\n\t * this store last read. A stage never read here is replaced as it is now.\n\t *\n\t * @throws {StageSecretsChanged} when another run wrote them in between\n\t * @throws {StageSecretsUnreadable} when there are no AWS credentials to\n\t * write it with, or they have expired\n\t */\n\tasync write(stage: string, secrets: StageSecrets): Promise<void> {\n\t\tconst { s3, bucket } = await this.use(stage, true);\n\t\tconst Bucket = bucket!;\n\t\tconst Key = this.key(stage);\n\t\tconst expected = this.etags.has(stage)\n\t\t\t? (this.etags.get(stage) ?? null)\n\t\t\t: await this.currentEtag(s3, stage, Bucket, Key);\n\n\t\ttry {\n\t\t\tconst { ETag } = await this.call(stage, 'write', () =>\n\t\t\t\ts3.send(\n\t\t\t\t\tnew PutObjectCommand({\n\t\t\t\t\t\tBucket,\n\t\t\t\t\t\tKey,\n\t\t\t\t\t\tBody: JSON.stringify(secrets),\n\t\t\t\t\t\tContentType: 'application/json',\n\t\t\t\t\t\tServerSideEncryption: 'AES256',\n\t\t\t\t\t\t...(expected === null\n\t\t\t\t\t\t\t? { IfNoneMatch: '*' }\n\t\t\t\t\t\t\t: { IfMatch: expected }),\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t);\n\t\t\tthis.remember(stage, ETag);\n\t\t} catch (error) {\n\t\t\tif (lostRace(error)) {\n\t\t\t\tthis.etags.delete(stage);\n\t\t\t\tthrow new StageSecretsChanged(stage, `s3://${Bucket}/${Key}`);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * The ETag the stage is now at. Some S3-compatible servers answer without\n\t * one: then nothing is remembered, and the next write asks for it first.\n\t */\n\tprivate remember(stage: string, etag: string | undefined): void {\n\t\tif (etag) this.etags.set(stage, etag);\n\t\telse this.etags.delete(stage);\n\t}\n\n\tprivate async currentEtag(\n\t\ts3: S3Client,\n\t\tstage: string,\n\t\tBucket: string,\n\t\tKey: string,\n\t): Promise<string | null> {\n\t\ttry {\n\t\t\tconst { ETag } = await this.call(stage, 'write', () =>\n\t\t\t\ts3.send(new HeadObjectCommand({ Bucket, Key })),\n\t\t\t);\n\t\t\treturn ETag ?? null;\n\t\t} catch (error) {\n\t\t\tif (notFound(error)) return null;\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,IAAa,sBAAb,cAAyCA,eAAAA,SAAS;CAEvC;CAEA;CAHV,YACC,OAEA,UACC;EACD,MACC,0BAA0B,MAAM,OAAO,SAAS,4KAGjD;EARS,KAAA,QAAA;EAEA,KAAA,WAAA;EAOT,KAAK,OAAO;CACb;AACD;;AAQA,SAAS,SAAS,OAAyB;CAC1C,MAAM,EAAE,MAAM,cAAc;CAC5B,OACC,SAAS,wBACT,SAAS,gCACT,WAAW,mBAAmB,OAC9B,WA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 -1,4 +1,4 @@
1
- import { jt as GkmError } from "./types-bkqVscdN.mjs";
1
+ import { jt as GkmError } from "./types-DipUP9zp.cjs";
2
2
  //#region src/sandbox/sandbox.d.ts
3
3
  /** Where a command's output goes. */
4
4
  type SandboxOutput = 'capture' | 'inherit' | 'stderr' | 'ignore';
@@ -101,4 +101,4 @@ declare class SecretNameInvalid extends GkmError {
101
101
  }
102
102
  //#endregion
103
103
  export { SandboxOutput as a, confineCwd as c, SandboxExecOptions as i, Sandbox as n, SandboxResult as o, SandboxCwdEscape as r, SecretNameInvalid as s, SECRETS_DIR_ENV as t };
104
- //# sourceMappingURL=sandbox-DGOsMPMf.d.mts.map
104
+ //# sourceMappingURL=sandbox-ArJ_hEKk.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox-BbJmh2rI.d.cts","names":[],"sources":["../src/sandbox/sandbox.ts"],"mappings":";;;KA8BY;UAEK;;;;;;EAMhB;;;;;EAKA,KAAK,SAAS;;;;;;EAMd;;;;;;;EAOA,UAAU,SAAS;;;;;;EAMnB,SAAS;;EAET,SAAS;;;UAIO;EAChB;EACA;;EAEA;;EAEA;;;;;;;;;;;UAYgB;;WAEP;;;;;;;;;;;;;WAaA;;;;;WAKA,KAAK,SAAS;EACvB,KACC,iBACA,yBACA,SAAS,qBACP,QAAQ;;;cAIC;;cAGA,yBAAyB;WAE3B;WACA;EAFV,YACU,aACA;;;;;;;;;;iBAwBK,WAAW,cAAc;;cAU5B,0BAA0B;WACjB;EAArB,YAAqB"}
1
+ {"version":3,"file":"sandbox-ArJ_hEKk.d.cts","names":[],"sources":["../src/sandbox/sandbox.ts"],"mappings":";;;KA8BY;UAEK;;;;;;EAMhB;;;;;EAKA,KAAK,SAAS;;;;;;EAMd;;;;;;;EAOA,UAAU,SAAS;;;;;;EAMnB,SAAS;;EAET,SAAS;;;UAIO;EAChB;EACA;;EAEA;;EAEA;;;;;;;;;;;UAYgB;;WAEP;;;;;;;;;;;;;WAaA;;;;;WAKA,KAAK,SAAS;EACvB,KACC,iBACA,yBACA,SAAS,qBACP,QAAQ;;;cAIC;;cAGA,yBAAyB;WAE3B;WACA;EAFV,YACU,aACA;;;;;;;;;;iBAwBK,WAAW,cAAc;;cAU5B,0BAA0B;WACjB;EAArB,YAAqB"}
@@ -1,4 +1,4 @@
1
- import { jt as GkmError } from "./types-dipJRmKV.cjs";
1
+ import { jt as GkmError } from "./types-Drpl9HX9.mjs";
2
2
  //#region src/sandbox/sandbox.d.ts
3
3
  /** Where a command's output goes. */
4
4
  type SandboxOutput = 'capture' | 'inherit' | 'stderr' | 'ignore';
@@ -101,4 +101,4 @@ declare class SecretNameInvalid extends GkmError {
101
101
  }
102
102
  //#endregion
103
103
  export { SandboxOutput as a, confineCwd as c, SandboxExecOptions as i, Sandbox as n, SandboxResult as o, SandboxCwdEscape as r, SecretNameInvalid as s, SECRETS_DIR_ENV as t };
104
- //# sourceMappingURL=sandbox-BbJmh2rI.d.cts.map
104
+ //# sourceMappingURL=sandbox-Cm4X6HRh.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox-DGOsMPMf.d.mts","names":[],"sources":["../src/sandbox/sandbox.ts"],"mappings":";;;KA8BY;UAEK;;;;;;EAMhB;;;;;EAKA,KAAK,SAAS;;;;;;EAMd;;;;;;;EAOA,UAAU,SAAS;;;;;;EAMnB,SAAS;;EAET,SAAS;;;UAIO;EAChB;EACA;;EAEA;;EAEA;;;;;;;;;;;UAYgB;;WAEP;;;;;;;;;;;;;WAaA;;;;;WAKA,KAAK,SAAS;EACvB,KACC,iBACA,yBACA,SAAS,qBACP,QAAQ;;;cAIC;;cAGA,yBAAyB;WAE3B;WACA;EAFV,YACU,aACA;;;;;;;;;;iBAwBK,WAAW,cAAc;;cAU5B,0BAA0B;WACjB;EAArB,YAAqB"}
1
+ {"version":3,"file":"sandbox-Cm4X6HRh.d.mts","names":[],"sources":["../src/sandbox/sandbox.ts"],"mappings":";;;KA8BY;UAEK;;;;;;EAMhB;;;;;EAKA,KAAK,SAAS;;;;;;EAMd;;;;;;;EAOA,UAAU,SAAS;;;;;;EAMnB,SAAS;;EAET,SAAS;;;UAIO;EAChB;EACA;;EAEA;;EAEA;;;;;;;;;;;UAYgB;;WAEP;;;;;;;;;;;;;WAaA;;;;;WAKA,KAAK,SAAS;EACvB,KACC,iBACA,yBACA,SAAS,qBACP,QAAQ;;;cAIC;;cAGA,yBAAyB;WAE3B;WACA;EAFV,YACU,aACA;;;;;;;;;;iBAwBK,WAAW,cAAc;;cAU5B,0BAA0B;WACjB;EAArB,YAAqB"}
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
2
- import { L as resolveStageTelemetry } from "./workspace-CqFUjObk.mjs";
3
- import { St as withRedisPassword, Wn as initStageSecrets, bt as runsRedis, er as withLogsPassword, fn as usesTelemetry, gt as withGeneratedSecrets } from "./seeds-CbJSne1A.mjs";
2
+ import { L as resolveStageTelemetry } from "./workspace-BBeT6Pil.mjs";
3
+ import { St as withRedisPassword, Wn as initStageSecrets, bt as runsRedis, er as withLogsPassword, fn as usesTelemetry, gt as withGeneratedSecrets } from "./seeds-BvxWUGKJ.mjs";
4
4
  //#region src/compose/secrets.ts
5
5
  var secrets_exports = /* @__PURE__ */ __exportAll({ deployedStackSecrets: () => deployedStackSecrets });
6
6
  function deployedStackSecrets(workspace, stage, stored, manifest) {
@@ -33,4 +33,4 @@ function deployedStackSecrets(workspace, stage, stored, manifest) {
33
33
  //#endregion
34
34
  export { secrets_exports as n, deployedStackSecrets as t };
35
35
 
36
- //# sourceMappingURL=secrets-ZikTIxEm.mjs.map
36
+ //# sourceMappingURL=secrets-AA_tQUl-.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"secrets-ZikTIxEm.mjs","names":[],"sources":["../src/compose/secrets.ts"],"sourcesContent":["/**\n * What a deployed stage's stack generates once and keeps: its seed, each\n * `secret` construct's value, the log UI's root password where its telemetry\n * is self-hosted, and the stack's Redis password where a cache lives in it.\n *\n * Pure: the compose target writes the result back to the stage's store, and\n * `gkm deploy --resources-only` composes the stack with it to read its hosts,\n * writing nothing.\n */\n\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport {\n\ttype GeneratedSecrets,\n\twithGeneratedSecrets,\n} from '../deploy/generated.js';\nimport { initStageSecrets } from '../secrets/storage.js';\nimport type { StageSecrets } from '../secrets/types.js';\nimport { resolveStageTelemetry } from '../telemetry/config';\nimport { usesTelemetry } from '../telemetry/edges';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\nimport { withLogsPassword } from './logs';\nimport { runsRedis, withRedisPassword } from './redis';\n\nexport function deployedStackSecrets(\n\tworkspace: NormalizedWorkspace,\n\tstage: string,\n\tstored: StageSecrets | null,\n\tmanifest: ConstructManifest,\n): GeneratedSecrets {\n\tconst withSeed = withGeneratedSecrets(\n\t\tstored ?? initStageSecrets(stage),\n\t\tmanifest,\n\t);\n\t// The log UI's root password, generated once like the seed, where the\n\t// stage's telemetry is self-hosted and the stage set none.\n\tconst telemetry = resolveStageTelemetry({\n\t\t...(workspace.deploy?.telemetry\n\t\t\t? { telemetry: workspace.deploy.telemetry }\n\t\t\t: {}),\n\t\tstage,\n\t\tlocal: false,\n\t\ttarget: 'compose',\n\t\truntime: 'server',\n\t\tselfHosted: true,\n\t\tused: usesTelemetry(manifest),\n\t});\n\tconst withLogs =\n\t\ttelemetry?.provider === 'self-hosted'\n\t\t\t? withLogsPassword(withSeed.secrets)\n\t\t\t: { secrets: withSeed.secrets, generated: [] };\n\t// The stack's Redis password, the same way, where a cache lives in it.\n\tconst withRedis = runsRedis(manifest, withLogs.secrets.custom ?? {})\n\t\t? withRedisPassword(withLogs.secrets)\n\t\t: { secrets: withLogs.secrets, generated: [] };\n\treturn {\n\t\tsecrets: withRedis.secrets,\n\t\tgenerated: [\n\t\t\t...withSeed.generated,\n\t\t\t...withLogs.generated,\n\t\t\t...withRedis.generated,\n\t\t],\n\t};\n}\n"],"mappings":";;;;;AAuBA,SAAgB,qBACf,WACA,OACA,QACA,UACmB;CACnB,MAAM,WAAW,qBAChB,UAAU,iBAAiB,KAAK,GAChC,QACD;CAcA,MAAM,WAXY,sBAAsB;EACvC,GAAI,UAAU,QAAQ,YACnB,EAAE,WAAW,UAAU,OAAO,UAAU,IACxC,CAAC;EACJ;EACA,OAAO;EACP,QAAQ;EACR,SAAS;EACT,YAAY;EACZ,MAAM,cAAc,QAAQ;CAC7B,CAES,CAAC,EAAE,aAAa,gBACrB,iBAAiB,SAAS,OAAO,IACjC;EAAE,SAAS,SAAS;EAAS,WAAW,CAAC;CAAE;CAE/C,MAAM,YAAY,UAAU,UAAU,SAAS,QAAQ,UAAU,CAAC,CAAC,IAChE,kBAAkB,SAAS,OAAO,IAClC;EAAE,SAAS,SAAS;EAAS,WAAW,CAAC;CAAE;CAC9C,OAAO;EACN,SAAS,UAAU;EACnB,WAAW;GACV,GAAG,SAAS;GACZ,GAAG,SAAS;GACZ,GAAG,UAAU;EACd;CACD;AACD"}
1
+ {"version":3,"file":"secrets-AA_tQUl-.mjs","names":[],"sources":["../src/compose/secrets.ts"],"sourcesContent":["/**\n * What a deployed stage's stack generates once and keeps: its seed, each\n * `secret` construct's value, the log UI's root password where its telemetry\n * is self-hosted, and the stack's Redis password where a cache lives in it.\n *\n * Pure: the compose target writes the result back to the stage's store, and\n * `gkm deploy --resources-only` composes the stack with it to read its hosts,\n * writing nothing.\n */\n\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport {\n\ttype GeneratedSecrets,\n\twithGeneratedSecrets,\n} from '../deploy/generated.js';\nimport { initStageSecrets } from '../secrets/storage.js';\nimport type { StageSecrets } from '../secrets/types.js';\nimport { resolveStageTelemetry } from '../telemetry/config';\nimport { usesTelemetry } from '../telemetry/edges';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\nimport { withLogsPassword } from './logs';\nimport { runsRedis, withRedisPassword } from './redis';\n\nexport function deployedStackSecrets(\n\tworkspace: NormalizedWorkspace,\n\tstage: string,\n\tstored: StageSecrets | null,\n\tmanifest: ConstructManifest,\n): GeneratedSecrets {\n\tconst withSeed = withGeneratedSecrets(\n\t\tstored ?? initStageSecrets(stage),\n\t\tmanifest,\n\t);\n\t// The log UI's root password, generated once like the seed, where the\n\t// stage's telemetry is self-hosted and the stage set none.\n\tconst telemetry = resolveStageTelemetry({\n\t\t...(workspace.deploy?.telemetry\n\t\t\t? { telemetry: workspace.deploy.telemetry }\n\t\t\t: {}),\n\t\tstage,\n\t\tlocal: false,\n\t\ttarget: 'compose',\n\t\truntime: 'server',\n\t\tselfHosted: true,\n\t\tused: usesTelemetry(manifest),\n\t});\n\tconst withLogs =\n\t\ttelemetry?.provider === 'self-hosted'\n\t\t\t? withLogsPassword(withSeed.secrets)\n\t\t\t: { secrets: withSeed.secrets, generated: [] };\n\t// The stack's Redis password, the same way, where a cache lives in it.\n\tconst withRedis = runsRedis(manifest, withLogs.secrets.custom ?? {})\n\t\t? withRedisPassword(withLogs.secrets)\n\t\t: { secrets: withLogs.secrets, generated: [] };\n\treturn {\n\t\tsecrets: withRedis.secrets,\n\t\tgenerated: [\n\t\t\t...withSeed.generated,\n\t\t\t...withLogs.generated,\n\t\t\t...withRedis.generated,\n\t\t],\n\t};\n}\n"],"mappings":";;;;;AAuBA,SAAgB,qBACf,WACA,OACA,QACA,UACmB;CACnB,MAAM,WAAW,qBAChB,UAAU,iBAAiB,KAAK,GAChC,QACD;CAcA,MAAM,WAXY,sBAAsB;EACvC,GAAI,UAAU,QAAQ,YACnB,EAAE,WAAW,UAAU,OAAO,UAAU,IACxC,CAAC;EACJ;EACA,OAAO;EACP,QAAQ;EACR,SAAS;EACT,YAAY;EACZ,MAAM,cAAc,QAAQ;CAC7B,CAES,CAAC,EAAE,aAAa,gBACrB,iBAAiB,SAAS,OAAO,IACjC;EAAE,SAAS,SAAS;EAAS,WAAW,CAAC;CAAE;CAE/C,MAAM,YAAY,UAAU,UAAU,SAAS,QAAQ,UAAU,CAAC,CAAC,IAChE,kBAAkB,SAAS,OAAO,IAClC;EAAE,SAAS,SAAS;EAAS,WAAW,CAAC;CAAE;CAC9C,OAAO;EACN,SAAS,UAAU;EACnB,WAAW;GACV,GAAG,SAAS;GACZ,GAAG,SAAS;GACZ,GAAG,UAAU;EACd;CACD;AACD"}
@@ -1,6 +1,6 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
2
- const require_workspace = require("./workspace-DDkm4y6D.cjs");
3
- const require_seeds = require("./seeds-BjXW-Krf.cjs");
2
+ const require_workspace = require("./workspace-BJ78Bgvm.cjs");
3
+ const require_seeds = require("./seeds-Df4BI-T3.cjs");
4
4
  //#region src/compose/secrets.ts
5
5
  var secrets_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ deployedStackSecrets: () => deployedStackSecrets });
6
6
  function deployedStackSecrets(workspace, stage, stored, manifest) {
@@ -44,4 +44,4 @@ Object.defineProperty(exports, "secrets_exports", {
44
44
  }
45
45
  });
46
46
 
47
- //# sourceMappingURL=secrets-C5qROlbp.cjs.map
47
+ //# sourceMappingURL=secrets-B_biKsKx.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"secrets-C5qROlbp.cjs","names":["withGeneratedSecrets","initStageSecrets","resolveStageTelemetry","usesTelemetry","withLogsPassword","runsRedis","withRedisPassword"],"sources":["../src/compose/secrets.ts"],"sourcesContent":["/**\n * What a deployed stage's stack generates once and keeps: its seed, each\n * `secret` construct's value, the log UI's root password where its telemetry\n * is self-hosted, and the stack's Redis password where a cache lives in it.\n *\n * Pure: the compose target writes the result back to the stage's store, and\n * `gkm deploy --resources-only` composes the stack with it to read its hosts,\n * writing nothing.\n */\n\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport {\n\ttype GeneratedSecrets,\n\twithGeneratedSecrets,\n} from '../deploy/generated.js';\nimport { initStageSecrets } from '../secrets/storage.js';\nimport type { StageSecrets } from '../secrets/types.js';\nimport { resolveStageTelemetry } from '../telemetry/config';\nimport { usesTelemetry } from '../telemetry/edges';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\nimport { withLogsPassword } from './logs';\nimport { runsRedis, withRedisPassword } from './redis';\n\nexport function deployedStackSecrets(\n\tworkspace: NormalizedWorkspace,\n\tstage: string,\n\tstored: StageSecrets | null,\n\tmanifest: ConstructManifest,\n): GeneratedSecrets {\n\tconst withSeed = withGeneratedSecrets(\n\t\tstored ?? initStageSecrets(stage),\n\t\tmanifest,\n\t);\n\t// The log UI's root password, generated once like the seed, where the\n\t// stage's telemetry is self-hosted and the stage set none.\n\tconst telemetry = resolveStageTelemetry({\n\t\t...(workspace.deploy?.telemetry\n\t\t\t? { telemetry: workspace.deploy.telemetry }\n\t\t\t: {}),\n\t\tstage,\n\t\tlocal: false,\n\t\ttarget: 'compose',\n\t\truntime: 'server',\n\t\tselfHosted: true,\n\t\tused: usesTelemetry(manifest),\n\t});\n\tconst withLogs =\n\t\ttelemetry?.provider === 'self-hosted'\n\t\t\t? withLogsPassword(withSeed.secrets)\n\t\t\t: { secrets: withSeed.secrets, generated: [] };\n\t// The stack's Redis password, the same way, where a cache lives in it.\n\tconst withRedis = runsRedis(manifest, withLogs.secrets.custom ?? {})\n\t\t? withRedisPassword(withLogs.secrets)\n\t\t: { secrets: withLogs.secrets, generated: [] };\n\treturn {\n\t\tsecrets: withRedis.secrets,\n\t\tgenerated: [\n\t\t\t...withSeed.generated,\n\t\t\t...withLogs.generated,\n\t\t\t...withRedis.generated,\n\t\t],\n\t};\n}\n"],"mappings":";;;;;AAuBA,SAAgB,qBACf,WACA,OACA,QACA,UACmB;CACnB,MAAM,WAAWA,cAAAA,qBAChB,UAAUC,cAAAA,iBAAiB,KAAK,GAChC,QACD;CAcA,MAAM,WAXYC,kBAAAA,sBAAsB;EACvC,GAAI,UAAU,QAAQ,YACnB,EAAE,WAAW,UAAU,OAAO,UAAU,IACxC,CAAC;EACJ;EACA,OAAO;EACP,QAAQ;EACR,SAAS;EACT,YAAY;EACZ,MAAMC,cAAAA,cAAc,QAAQ;CAC7B,CAES,CAAC,EAAE,aAAa,gBACrBC,cAAAA,iBAAiB,SAAS,OAAO,IACjC;EAAE,SAAS,SAAS;EAAS,WAAW,CAAC;CAAE;CAE/C,MAAM,YAAYC,cAAAA,UAAU,UAAU,SAAS,QAAQ,UAAU,CAAC,CAAC,IAChEC,cAAAA,kBAAkB,SAAS,OAAO,IAClC;EAAE,SAAS,SAAS;EAAS,WAAW,CAAC;CAAE;CAC9C,OAAO;EACN,SAAS,UAAU;EACnB,WAAW;GACV,GAAG,SAAS;GACZ,GAAG,SAAS;GACZ,GAAG,UAAU;EACd;CACD;AACD"}
1
+ {"version":3,"file":"secrets-B_biKsKx.cjs","names":["withGeneratedSecrets","initStageSecrets","resolveStageTelemetry","usesTelemetry","withLogsPassword","runsRedis","withRedisPassword"],"sources":["../src/compose/secrets.ts"],"sourcesContent":["/**\n * What a deployed stage's stack generates once and keeps: its seed, each\n * `secret` construct's value, the log UI's root password where its telemetry\n * is self-hosted, and the stack's Redis password where a cache lives in it.\n *\n * Pure: the compose target writes the result back to the stage's store, and\n * `gkm deploy --resources-only` composes the stack with it to read its hosts,\n * writing nothing.\n */\n\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport {\n\ttype GeneratedSecrets,\n\twithGeneratedSecrets,\n} from '../deploy/generated.js';\nimport { initStageSecrets } from '../secrets/storage.js';\nimport type { StageSecrets } from '../secrets/types.js';\nimport { resolveStageTelemetry } from '../telemetry/config';\nimport { usesTelemetry } from '../telemetry/edges';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\nimport { withLogsPassword } from './logs';\nimport { runsRedis, withRedisPassword } from './redis';\n\nexport function deployedStackSecrets(\n\tworkspace: NormalizedWorkspace,\n\tstage: string,\n\tstored: StageSecrets | null,\n\tmanifest: ConstructManifest,\n): GeneratedSecrets {\n\tconst withSeed = withGeneratedSecrets(\n\t\tstored ?? initStageSecrets(stage),\n\t\tmanifest,\n\t);\n\t// The log UI's root password, generated once like the seed, where the\n\t// stage's telemetry is self-hosted and the stage set none.\n\tconst telemetry = resolveStageTelemetry({\n\t\t...(workspace.deploy?.telemetry\n\t\t\t? { telemetry: workspace.deploy.telemetry }\n\t\t\t: {}),\n\t\tstage,\n\t\tlocal: false,\n\t\ttarget: 'compose',\n\t\truntime: 'server',\n\t\tselfHosted: true,\n\t\tused: usesTelemetry(manifest),\n\t});\n\tconst withLogs =\n\t\ttelemetry?.provider === 'self-hosted'\n\t\t\t? withLogsPassword(withSeed.secrets)\n\t\t\t: { secrets: withSeed.secrets, generated: [] };\n\t// The stack's Redis password, the same way, where a cache lives in it.\n\tconst withRedis = runsRedis(manifest, withLogs.secrets.custom ?? {})\n\t\t? withRedisPassword(withLogs.secrets)\n\t\t: { secrets: withLogs.secrets, generated: [] };\n\treturn {\n\t\tsecrets: withRedis.secrets,\n\t\tgenerated: [\n\t\t\t...withSeed.generated,\n\t\t\t...withLogs.generated,\n\t\t\t...withRedis.generated,\n\t\t],\n\t};\n}\n"],"mappings":";;;;;AAuBA,SAAgB,qBACf,WACA,OACA,QACA,UACmB;CACnB,MAAM,WAAWA,cAAAA,qBAChB,UAAUC,cAAAA,iBAAiB,KAAK,GAChC,QACD;CAcA,MAAM,WAXYC,kBAAAA,sBAAsB;EACvC,GAAI,UAAU,QAAQ,YACnB,EAAE,WAAW,UAAU,OAAO,UAAU,IACxC,CAAC;EACJ;EACA,OAAO;EACP,QAAQ;EACR,SAAS;EACT,YAAY;EACZ,MAAMC,cAAAA,cAAc,QAAQ;CAC7B,CAES,CAAC,EAAE,aAAa,gBACrBC,cAAAA,iBAAiB,SAAS,OAAO,IACjC;EAAE,SAAS,SAAS;EAAS,WAAW,CAAC;CAAE;CAE/C,MAAM,YAAYC,cAAAA,UAAU,UAAU,SAAS,QAAQ,UAAU,CAAC,CAAC,IAChEC,cAAAA,kBAAkB,SAAS,OAAO,IAClC;EAAE,SAAS,SAAS;EAAS,WAAW,CAAC;CAAE;CAC9C,OAAO;EACN,SAAS,UAAU;EACnB,WAAW;GACV,GAAG,SAAS;GACZ,GAAG,SAAS;GACZ,GAAG,UAAU;EACd;CACD;AACD"}
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
2
- import { n as serializeWithin, r as withStageCredentials, t as awsClientConfig } from "./awsStore-BWa1KNY-.mjs";
2
+ import { n as serializeWithin, r as withStageCredentials, t as awsClientConfig } from "./awsStore-Bx5nCFnS.mjs";
3
3
  import { CreateSecretCommand, GetSecretValueCommand, PutSecretValueCommand, ResourceNotFoundException, SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
4
4
  //#region src/secrets/secretsManager.ts
5
5
  /**
@@ -94,4 +94,4 @@ var SecretsManagerSecretsStore = class {
94
94
  //#endregion
95
95
  export { secretsManager_exports as n, secretsManagerSecretName as t };
96
96
 
97
- //# sourceMappingURL=secretsManager-C6wm-9uZ.mjs.map
97
+ //# sourceMappingURL=secretsManager-CQORubp9.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"secretsManager-C6wm-9uZ.mjs","names":[],"sources":["../src/secrets/secretsManager.ts"],"sourcesContent":["/**\n * A stage's secrets in AWS Secrets Manager, in the stage's own AWS account.\n *\n * One secret per stage, `gkm/<project>/<stage>/secrets` — the SSM store's\n * parameter name without its leading `/` — holding the same JSON. It is\n * encrypted with the account's `aws/secretsmanager` key unless `kmsKeyId`\n * names another. Which account it is in is whichever credentials are active,\n * exactly as for the SSM store.\n *\n * Chosen over SSM for size (64 KB rather than 8 KB) and for Secrets Manager's\n * own versioning, at a monthly price per secret.\n */\n\nimport {\n\tCreateSecretCommand,\n\tGetSecretValueCommand,\n\tPutSecretValueCommand,\n\tResourceNotFoundException,\n\tSecretsManagerClient,\n} from '@aws-sdk/client-secrets-manager';\nimport {\n\ttype AwsStoreOptions,\n\tawsClientConfig,\n\tserializeWithin,\n\twithStageCredentials,\n} from './awsStore.js';\nimport type { SecretsStore } from './store.js';\nimport type { StageSecrets } from './types.js';\n\nexport interface SecretsManagerStoreOptions extends AwsStoreOptions {\n\t/** The KMS key a new secret is encrypted with; `aws/secretsmanager` if unset. */\n\tkmsKeyId?: string;\n}\n\n/** The most a Secrets Manager secret holds: 64 KB. */\nexport const SECRETS_MANAGER_SECRET_LIMIT = 64 * 1024;\n\n/** The secret a stage's secrets are kept in. */\nexport function secretsManagerSecretName(\n\tproject: string,\n\tstage: string,\n): string {\n\treturn `gkm/${project}/${stage}/secrets`;\n}\n\nexport class SecretsManagerSecretsStore implements SecretsStore {\n\treadonly name = 'secrets-manager';\n\n\tprivate client?: SecretsManagerClient;\n\n\tconstructor(private readonly options: SecretsManagerStoreOptions) {}\n\n\tprivate async secretsManager(): Promise<SecretsManagerClient> {\n\t\tif (this.client) return this.client;\n\t\tthis.client = new SecretsManagerClient(await awsClientConfig(this.options));\n\t\treturn this.client;\n\t}\n\n\tprivate secretName(stage: string): string {\n\t\treturn secretsManagerSecretName(this.options.project, stage);\n\t}\n\n\t/** Where a call for `stage` is, for an error saying it has no credentials. */\n\tprivate context(stage: string, access: 'read' | 'write') {\n\t\treturn { stage, store: this.name, profile: this.options.profile, access };\n\t}\n\n\t/**\n\t * @throws {StageSecretsUnreadable} when there are no AWS credentials to\n\t * read it with, or they have expired\n\t */\n\tasync read(stage: string): Promise<StageSecrets | null> {\n\t\tconst client = await this.secretsManager();\n\n\t\ttry {\n\t\t\tconst { SecretString } = await withStageCredentials(\n\t\t\t\tthis.context(stage, 'read'),\n\t\t\t\t() =>\n\t\t\t\t\tclient.send(\n\t\t\t\t\t\tnew GetSecretValueCommand({ SecretId: this.secretName(stage) }),\n\t\t\t\t\t),\n\t\t\t);\n\t\t\treturn SecretString ? (JSON.parse(SecretString) as StageSecrets) : null;\n\t\t} catch (error) {\n\t\t\tif (error instanceof ResourceNotFoundException) return null;\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * @throws {StageSecretsUnreadable} when there are no AWS credentials to\n\t * write it with, or they have expired\n\t */\n\tasync write(stage: string, secrets: StageSecrets): Promise<void> {\n\t\tconst value = serializeWithin(\n\t\t\tstage,\n\t\t\tthis.name,\n\t\t\tsecrets,\n\t\t\tSECRETS_MANAGER_SECRET_LIMIT,\n\t\t);\n\t\tconst client = await this.secretsManager();\n\t\tconst name = this.secretName(stage);\n\n\t\tawait withStageCredentials(this.context(stage, 'write'), () =>\n\t\t\tthis.put(client, stage, name, value),\n\t\t);\n\t}\n\n\t/** Put the secret, creating it on the stage's first write. */\n\tprivate async put(\n\t\tclient: SecretsManagerClient,\n\t\tstage: string,\n\t\tname: string,\n\t\tvalue: string,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tawait client.send(\n\t\t\t\tnew PutSecretValueCommand({ SecretId: name, SecretString: value }),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof ResourceNotFoundException)) throw error;\n\t\t\t// The stage's first write: the secret does not exist yet.\n\t\t\tawait client.send(\n\t\t\t\tnew CreateSecretCommand({\n\t\t\t\t\tName: name,\n\t\t\t\t\tSecretString: value,\n\t\t\t\t\tDescription: `gkm secrets for ${this.options.project}/${stage}`,\n\t\t\t\t\t...(this.options.kmsKeyId ? { KmsKeyId: this.options.kmsKeyId } : {}),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,+BAA+B;;AAG5C,SAAgB,yBACf,SACA,OACS;CACT,OAAO,OAAO,QAAQ,GAAG,MAAM;AAChC;AAEA,IAAa,6BAAb,MAAgE;CAKlC;CAJ7B,OAAgB;CAEhB;CAEA,YAAY,SAAsD;EAArC,KAAA,UAAA;CAAsC;CAEnE,MAAc,iBAAgD;EAC7D,IAAI,KAAK,QAAQ,OAAO,KAAK;EAC7B,KAAK,SAAS,IAAI,qBAAqB,MAAM,gBAAgB,KAAK,OAAO,CAAC;EAC1E,OAAO,KAAK;CACb;CAEA,WAAmB,OAAuB;EACzC,OAAO,yBAAyB,KAAK,QAAQ,SAAS,KAAK;CAC5D;;CAGA,QAAgB,OAAe,QAA0B;EACxD,OAAO;GAAE;GAAO,OAAO,KAAK;GAAM,SAAS,KAAK,QAAQ;GAAS;EAAO;CACzE;;;;;CAMA,MAAM,KAAK,OAA6C;EACvD,MAAM,SAAS,MAAM,KAAK,eAAe;EAEzC,IAAI;GACH,MAAM,EAAE,iBAAiB,MAAM,qBAC9B,KAAK,QAAQ,OAAO,MAAM,SAEzB,OAAO,KACN,IAAI,sBAAsB,EAAE,UAAU,KAAK,WAAW,KAAK,EAAE,CAAC,CAC/D,CACF;GACA,OAAO,eAAgB,KAAK,MAAM,YAAY,IAAqB;EACpE,SAAS,OAAO;GACf,IAAI,iBAAiB,2BAA2B,OAAO;GACvD,MAAM;EACP;CACD;;;;;CAMA,MAAM,MAAM,OAAe,SAAsC;EAChE,MAAM,QAAQ,gBACb,OACA,KAAK,MACL,SACA,4BACD;EACA,MAAM,SAAS,MAAM,KAAK,eAAe;EACzC,MAAM,OAAO,KAAK,WAAW,KAAK;EAElC,MAAM,qBAAqB,KAAK,QAAQ,OAAO,OAAO,SACrD,KAAK,IAAI,QAAQ,OAAO,MAAM,KAAK,CACpC;CACD;;CAGA,MAAc,IACb,QACA,OACA,MACA,OACgB;EAChB,IAAI;GACH,MAAM,OAAO,KACZ,IAAI,sBAAsB;IAAE,UAAU;IAAM,cAAc;GAAM,CAAC,CAClE;EACD,SAAS,OAAO;GACf,IAAI,EAAE,iBAAiB,4BAA4B,MAAM;GAEzD,MAAM,OAAO,KACZ,IAAI,oBAAoB;IACvB,MAAM;IACN,cAAc;IACd,aAAa,mBAAmB,KAAK,QAAQ,QAAQ,GAAG;IACxD,GAAI,KAAK,QAAQ,WAAW,EAAE,UAAU,KAAK,QAAQ,SAAS,IAAI,CAAC;GACpE,CAAC,CACF;EACD;CACD;AACD"}
1
+ {"version":3,"file":"secretsManager-CQORubp9.mjs","names":[],"sources":["../src/secrets/secretsManager.ts"],"sourcesContent":["/**\n * A stage's secrets in AWS Secrets Manager, in the stage's own AWS account.\n *\n * One secret per stage, `gkm/<project>/<stage>/secrets` — the SSM store's\n * parameter name without its leading `/` — holding the same JSON. It is\n * encrypted with the account's `aws/secretsmanager` key unless `kmsKeyId`\n * names another. Which account it is in is whichever credentials are active,\n * exactly as for the SSM store.\n *\n * Chosen over SSM for size (64 KB rather than 8 KB) and for Secrets Manager's\n * own versioning, at a monthly price per secret.\n */\n\nimport {\n\tCreateSecretCommand,\n\tGetSecretValueCommand,\n\tPutSecretValueCommand,\n\tResourceNotFoundException,\n\tSecretsManagerClient,\n} from '@aws-sdk/client-secrets-manager';\nimport {\n\ttype AwsStoreOptions,\n\tawsClientConfig,\n\tserializeWithin,\n\twithStageCredentials,\n} from './awsStore.js';\nimport type { SecretsStore } from './store.js';\nimport type { StageSecrets } from './types.js';\n\nexport interface SecretsManagerStoreOptions extends AwsStoreOptions {\n\t/** The KMS key a new secret is encrypted with; `aws/secretsmanager` if unset. */\n\tkmsKeyId?: string;\n}\n\n/** The most a Secrets Manager secret holds: 64 KB. */\nexport const SECRETS_MANAGER_SECRET_LIMIT = 64 * 1024;\n\n/** The secret a stage's secrets are kept in. */\nexport function secretsManagerSecretName(\n\tproject: string,\n\tstage: string,\n): string {\n\treturn `gkm/${project}/${stage}/secrets`;\n}\n\nexport class SecretsManagerSecretsStore implements SecretsStore {\n\treadonly name = 'secrets-manager';\n\n\tprivate client?: SecretsManagerClient;\n\n\tconstructor(private readonly options: SecretsManagerStoreOptions) {}\n\n\tprivate async secretsManager(): Promise<SecretsManagerClient> {\n\t\tif (this.client) return this.client;\n\t\tthis.client = new SecretsManagerClient(await awsClientConfig(this.options));\n\t\treturn this.client;\n\t}\n\n\tprivate secretName(stage: string): string {\n\t\treturn secretsManagerSecretName(this.options.project, stage);\n\t}\n\n\t/** Where a call for `stage` is, for an error saying it has no credentials. */\n\tprivate context(stage: string, access: 'read' | 'write') {\n\t\treturn { stage, store: this.name, profile: this.options.profile, access };\n\t}\n\n\t/**\n\t * @throws {StageSecretsUnreadable} when there are no AWS credentials to\n\t * read it with, or they have expired\n\t */\n\tasync read(stage: string): Promise<StageSecrets | null> {\n\t\tconst client = await this.secretsManager();\n\n\t\ttry {\n\t\t\tconst { SecretString } = await withStageCredentials(\n\t\t\t\tthis.context(stage, 'read'),\n\t\t\t\t() =>\n\t\t\t\t\tclient.send(\n\t\t\t\t\t\tnew GetSecretValueCommand({ SecretId: this.secretName(stage) }),\n\t\t\t\t\t),\n\t\t\t);\n\t\t\treturn SecretString ? (JSON.parse(SecretString) as StageSecrets) : null;\n\t\t} catch (error) {\n\t\t\tif (error instanceof ResourceNotFoundException) return null;\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * @throws {StageSecretsUnreadable} when there are no AWS credentials to\n\t * write it with, or they have expired\n\t */\n\tasync write(stage: string, secrets: StageSecrets): Promise<void> {\n\t\tconst value = serializeWithin(\n\t\t\tstage,\n\t\t\tthis.name,\n\t\t\tsecrets,\n\t\t\tSECRETS_MANAGER_SECRET_LIMIT,\n\t\t);\n\t\tconst client = await this.secretsManager();\n\t\tconst name = this.secretName(stage);\n\n\t\tawait withStageCredentials(this.context(stage, 'write'), () =>\n\t\t\tthis.put(client, stage, name, value),\n\t\t);\n\t}\n\n\t/** Put the secret, creating it on the stage's first write. */\n\tprivate async put(\n\t\tclient: SecretsManagerClient,\n\t\tstage: string,\n\t\tname: string,\n\t\tvalue: string,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tawait client.send(\n\t\t\t\tnew PutSecretValueCommand({ SecretId: name, SecretString: value }),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof ResourceNotFoundException)) throw error;\n\t\t\t// The stage's first write: the secret does not exist yet.\n\t\t\tawait client.send(\n\t\t\t\tnew CreateSecretCommand({\n\t\t\t\t\tName: name,\n\t\t\t\t\tSecretString: value,\n\t\t\t\t\tDescription: `gkm secrets for ${this.options.project}/${stage}`,\n\t\t\t\t\t...(this.options.kmsKeyId ? { KmsK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