@geekmidas/cli 10.0.0-alpha.164 → 10.0.0-alpha.166

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 (230) hide show
  1. package/dist/{GoDaddyProvider-DSzYpSc3.cjs → GoDaddyProvider-DClFHezd.cjs} +2 -2
  2. package/dist/{GoDaddyProvider-DSzYpSc3.cjs.map → GoDaddyProvider-DClFHezd.cjs.map} +1 -1
  3. package/dist/{GoDaddyProvider-BrZ7WtmP.mjs → GoDaddyProvider-mnY-cdD2.mjs} +2 -2
  4. package/dist/{GoDaddyProvider-BrZ7WtmP.mjs.map → GoDaddyProvider-mnY-cdD2.mjs.map} +1 -1
  5. package/dist/{HostingerProvider-D7N8GbQm.mjs → HostingerProvider-39eSGyBa.mjs} +2 -2
  6. package/dist/{HostingerProvider-D7N8GbQm.mjs.map → HostingerProvider-39eSGyBa.mjs.map} +1 -1
  7. package/dist/{HostingerProvider-DQusFkZJ.cjs → HostingerProvider-BMyz2LnZ.cjs} +2 -2
  8. package/dist/{HostingerProvider-DQusFkZJ.cjs.map → HostingerProvider-BMyz2LnZ.cjs.map} +1 -1
  9. package/dist/{LegacyStateStore-B2vZVXVe.mjs → LegacyStateStore-B2TBaSMq.mjs} +3 -3
  10. package/dist/{LegacyStateStore-B2vZVXVe.mjs.map → LegacyStateStore-B2TBaSMq.mjs.map} +1 -1
  11. package/dist/{LegacyStateStore-CxQkI3fQ.cjs → LegacyStateStore-BJY7ntQk.cjs} +3 -3
  12. package/dist/{LegacyStateStore-CxQkI3fQ.cjs.map → LegacyStateStore-BJY7ntQk.cjs.map} +1 -1
  13. package/dist/{LocalStateStore-ff4XiebR.mjs → LocalStateStore-8LFd-aMA.mjs} +2 -2
  14. package/dist/{LocalStateStore-ff4XiebR.mjs.map → LocalStateStore-8LFd-aMA.mjs.map} +1 -1
  15. package/dist/{LocalStateStore-CrrjFgMc.cjs → LocalStateStore-BvoEjPi5.cjs} +2 -2
  16. package/dist/{LocalStateStore-CrrjFgMc.cjs.map → LocalStateStore-BvoEjPi5.cjs.map} +1 -1
  17. package/dist/{S3StateStore-62sFppnE.mjs → S3StateStore-DMzsqfSa.mjs} +4 -4
  18. package/dist/{S3StateStore-62sFppnE.mjs.map → S3StateStore-DMzsqfSa.mjs.map} +1 -1
  19. package/dist/{S3StateStore-EnatbBd3.cjs → S3StateStore-eeA5NXRa.cjs} +4 -4
  20. package/dist/{S3StateStore-EnatbBd3.cjs.map → S3StateStore-eeA5NXRa.cjs.map} +1 -1
  21. package/dist/{SSMStateStore-CYPYh1c7.cjs → SSMStateStore-BUv-du0T.cjs} +2 -2
  22. package/dist/{SSMStateStore-CYPYh1c7.cjs.map → SSMStateStore-BUv-du0T.cjs.map} +1 -1
  23. package/dist/{SSMStateStore-BON4jyRR.mjs → SSMStateStore-CE2DTAtT.mjs} +2 -2
  24. package/dist/{SSMStateStore-BON4jyRR.mjs.map → SSMStateStore-CE2DTAtT.mjs.map} +1 -1
  25. package/dist/{add-CzoX8swL.mjs → add-BgCYGJpE.mjs} +6 -6
  26. package/dist/{add-CzoX8swL.mjs.map → add-BgCYGJpE.mjs.map} +1 -1
  27. package/dist/{add-D65M2URP.cjs → add-Dp0KQNkQ.cjs} +7 -7
  28. package/dist/{add-D65M2URP.cjs.map → add-Dp0KQNkQ.cjs.map} +1 -1
  29. package/dist/{apps-Dquc1K9N.mjs → apps-CJTOIaz3.mjs} +4 -5
  30. package/dist/{apps-Dquc1K9N.mjs.map → apps-CJTOIaz3.mjs.map} +1 -1
  31. package/dist/{apps-DY82zCeA.cjs → apps-DkMR-qvD.cjs} +22 -23
  32. package/dist/{apps-DY82zCeA.cjs.map → apps-DkMR-qvD.cjs.map} +1 -1
  33. package/dist/{bundler-wtMYRk9K.cjs → bundler-CA7KimJ0.cjs} +6 -6
  34. package/dist/{bundler-wtMYRk9K.cjs.map → bundler-CA7KimJ0.cjs.map} +1 -1
  35. package/dist/{bundler-9RpLU2H3.mjs → bundler-Dt1ffXl6.mjs} +6 -6
  36. package/dist/{bundler-9RpLU2H3.mjs.map → bundler-Dt1ffXl6.mjs.map} +1 -1
  37. package/dist/{cli-D0Tu6u1G.mjs → cli-C-fdEb8N.mjs} +5 -5
  38. package/dist/{cli-D0Tu6u1G.mjs.map → cli-C-fdEb8N.mjs.map} +1 -1
  39. package/dist/{cli-CgZuiNWv.cjs → cli-CY1Cp8yN.cjs} +5 -5
  40. package/dist/{cli-CgZuiNWv.cjs.map → cli-CY1Cp8yN.cjs.map} +1 -1
  41. package/dist/{compose-DgBUpgXh.cjs → compose-BIm9yNH7.cjs} +6 -6
  42. package/dist/{compose-DgBUpgXh.cjs.map → compose-BIm9yNH7.cjs.map} +1 -1
  43. package/dist/{compose-pbLaJlts.mjs → compose-CZGeE6QJ.mjs} +6 -6
  44. package/dist/{compose-pbLaJlts.mjs.map → compose-CZGeE6QJ.mjs.map} +1 -1
  45. package/dist/{compose-kEjxTamg.cjs → compose-SmuCWWUh.cjs} +22 -10
  46. package/dist/compose-SmuCWWUh.cjs.map +1 -0
  47. package/dist/{compose-BfTrMiAk.mjs → compose-tX6YTa1U.mjs} +22 -10
  48. package/dist/compose-tX6YTa1U.mjs.map +1 -0
  49. package/dist/{config-DNoWqavN.d.cts → config-B8gSu59v.d.mts} +3 -3
  50. package/dist/{config-BxSSAzVi.d.mts.map → config-B8gSu59v.d.mts.map} +1 -1
  51. package/dist/{config-BxSSAzVi.d.mts → config-u5XdE1Cq.d.cts} +3 -3
  52. package/dist/{config-DNoWqavN.d.cts.map → config-u5XdE1Cq.d.cts.map} +1 -1
  53. package/dist/config.cjs +457 -19
  54. package/dist/config.cjs.map +1 -0
  55. package/dist/config.d.cts +3 -3
  56. package/dist/config.d.mts +3 -3
  57. package/dist/config.mjs +440 -2
  58. package/dist/config.mjs.map +1 -0
  59. package/dist/{credentials-Bel6afW2.cjs → credentials-CS3Dr-pv.cjs} +6 -6
  60. package/dist/{credentials-Bel6afW2.cjs.map → credentials-CS3Dr-pv.cjs.map} +1 -1
  61. package/dist/{credentials-BgtOz5ec.mjs → credentials-V3WgiKmZ.mjs} +6 -6
  62. package/dist/{credentials-BgtOz5ec.mjs.map → credentials-V3WgiKmZ.mjs.map} +1 -1
  63. package/dist/deploy/public.cjs +13 -13
  64. package/dist/deploy/public.d.cts +4 -4
  65. package/dist/deploy/public.d.mts +4 -4
  66. package/dist/deploy/public.mjs +13 -13
  67. package/dist/{deploy-C4V-nsOF.cjs → deploy--ia-CGMv.cjs} +174 -68
  68. package/dist/deploy--ia-CGMv.cjs.map +1 -0
  69. package/dist/{deploy-D-5ib-ah.mjs → deploy-BWFFSN5p.mjs} +166 -60
  70. package/dist/deploy-BWFFSN5p.mjs.map +1 -0
  71. package/dist/{destroy-DuQqz53a.cjs → destroy-CrxF8Dlk.cjs} +12 -12
  72. package/dist/{destroy-DuQqz53a.cjs.map → destroy-CrxF8Dlk.cjs.map} +1 -1
  73. package/dist/{destroy-CYQCEn4A.mjs → destroy-ZNiKL3--.mjs} +12 -12
  74. package/dist/{destroy-CYQCEn4A.mjs.map → destroy-ZNiKL3--.mjs.map} +1 -1
  75. package/dist/{docker-BMReDeMB.cjs → docker-BtUjo-J_.cjs} +9 -8
  76. package/dist/{docker-BMReDeMB.cjs.map → docker-BtUjo-J_.cjs.map} +1 -1
  77. package/dist/{docker-BEsTfsFc.mjs → docker-DhmU416x.mjs} +6 -5
  78. package/dist/{docker-BEsTfsFc.mjs.map → docker-DhmU416x.mjs.map} +1 -1
  79. package/dist/{dokploy-BuYCnz9U.mjs → dokploy-BszAUbbA.mjs} +2 -2
  80. package/dist/{dokploy-BuYCnz9U.mjs.map → dokploy-BszAUbbA.mjs.map} +1 -1
  81. package/dist/{dokploy-BpPAgZ0u.cjs → dokploy-ComPiFLl.cjs} +2 -2
  82. package/dist/{dokploy-BpPAgZ0u.cjs.map → dokploy-ComPiFLl.cjs.map} +1 -1
  83. package/dist/{eas-DjVtUdb4.mjs → eas-DQudP2g2.mjs} +3 -3
  84. package/dist/{eas-DjVtUdb4.mjs.map → eas-DQudP2g2.mjs.map} +1 -1
  85. package/dist/{eas-H-6ixmsY.cjs → eas-zxVAWY6c.cjs} +6 -6
  86. package/dist/{eas-H-6ixmsY.cjs.map → eas-zxVAWY6c.cjs.map} +1 -1
  87. package/dist/{encryption-CR4aMkSK.mjs → encryption-BCaweYBJ.mjs} +4 -4
  88. package/dist/{encryption-CR4aMkSK.mjs.map → encryption-BCaweYBJ.mjs.map} +1 -1
  89. package/dist/{encryption-BvCsBp2p.cjs → encryption-CU5O0Y61.cjs} +4 -4
  90. package/dist/{encryption-BvCsBp2p.cjs.map → encryption-CU5O0Y61.cjs.map} +1 -1
  91. package/dist/{engine-upEpdhEF.mjs → engine-BzeCK6e8.mjs} +10 -11
  92. package/dist/{engine-upEpdhEF.mjs.map → engine-BzeCK6e8.mjs.map} +1 -1
  93. package/dist/{engine-CV2wqRFl.cjs → engine-xrlcbr1g.cjs} +11 -12
  94. package/dist/{engine-CV2wqRFl.cjs.map → engine-xrlcbr1g.cjs.map} +1 -1
  95. package/dist/{github-D2l7aqFx.mjs → github-CHClpJZS.mjs} +116 -72
  96. package/dist/github-CHClpJZS.mjs.map +1 -0
  97. package/dist/{github-BDOLgdMp.cjs → github-Jcrqfzg0.cjs} +116 -72
  98. package/dist/github-Jcrqfzg0.cjs.map +1 -0
  99. package/dist/{googlePlay-DJ2Kv0UX.mjs → googlePlay-Dk_pnif9.mjs} +5 -5
  100. package/dist/{googlePlay-DJ2Kv0UX.mjs.map → googlePlay-Dk_pnif9.mjs.map} +1 -1
  101. package/dist/{googlePlay-B3FR1VGL.cjs → googlePlay-e_tIBr4n.cjs} +5 -5
  102. package/dist/{googlePlay-B3FR1VGL.cjs.map → googlePlay-e_tIBr4n.cjs.map} +1 -1
  103. package/dist/{iam-BVPpX76R.cjs → iam-B6WLUf_x.cjs} +2 -2
  104. package/dist/{iam-BVPpX76R.cjs.map → iam-B6WLUf_x.cjs.map} +1 -1
  105. package/dist/{iam-q9ALh-Y5.mjs → iam-BKfO7u14.mjs} +2 -2
  106. package/dist/{iam-q9ALh-Y5.mjs.map → iam-BKfO7u14.mjs.map} +1 -1
  107. package/dist/{index-Dy4ojz5P.d.cts → index-1H93w_H6.d.cts} +2 -2
  108. package/dist/{index-BC1BLv9Q.d.mts.map → index-1H93w_H6.d.cts.map} +1 -1
  109. package/dist/{index-BC1BLv9Q.d.mts → index-DFZ0SMwN.d.mts} +2 -2
  110. package/dist/{index-Dy4ojz5P.d.cts.map → index-DFZ0SMwN.d.mts.map} +1 -1
  111. package/dist/index.cjs +71 -71
  112. package/dist/index.cjs.map +1 -1
  113. package/dist/index.mjs +65 -65
  114. package/dist/index.mjs.map +1 -1
  115. package/dist/{local-COaqGFDc.mjs → local-DUi3f-WB.mjs} +2 -2
  116. package/dist/{local-COaqGFDc.mjs.map → local-DUi3f-WB.mjs.map} +1 -1
  117. package/dist/{local-DhAnAhXn.cjs → local-Dc2h2Ex3.cjs} +2 -2
  118. package/dist/{local-DhAnAhXn.cjs.map → local-Dc2h2Ex3.cjs.map} +1 -1
  119. package/dist/{migrate-CusdrYsn.cjs → migrate-BU4eyd7z.cjs} +6 -6
  120. package/dist/{migrate-CusdrYsn.cjs.map → migrate-BU4eyd7z.cjs.map} +1 -1
  121. package/dist/{migrate-Nt9NOr1s.mjs → migrate-BxFCXc7M.mjs} +6 -6
  122. package/dist/{migrate-Nt9NOr1s.mjs.map → migrate-BxFCXc7M.mjs.map} +1 -1
  123. package/dist/{migrate-Hjvo9j_J.cjs → migrate-CIjcBr96.cjs} +4 -4
  124. package/dist/{migrate-Hjvo9j_J.cjs.map → migrate-CIjcBr96.cjs.map} +1 -1
  125. package/dist/{migrate-CpT7qBZE.mjs → migrate-CbpeVxEW.mjs} +4 -4
  126. package/dist/{migrate-CpT7qBZE.mjs.map → migrate-CbpeVxEW.mjs.map} +1 -1
  127. package/dist/{notes-CZvLIjfg.cjs → notes-DJyFkK13.cjs} +7 -8
  128. package/dist/{notes-CZvLIjfg.cjs.map → notes-DJyFkK13.cjs.map} +1 -1
  129. package/dist/{notes-B-tgKkvp.mjs → notes-TDHMzdVt.mjs} +3 -4
  130. package/dist/{notes-B-tgKkvp.mjs.map → notes-TDHMzdVt.mjs.map} +1 -1
  131. package/dist/openapi.cjs +3 -3
  132. package/dist/openapi.cjs.map +1 -1
  133. package/dist/openapi.d.cts +1 -1
  134. package/dist/openapi.d.mts +1 -1
  135. package/dist/openapi.mjs +2 -2
  136. package/dist/{projectBucket-DNAOBIYZ.mjs → projectBucket-BPzx0b0t.mjs} +2 -2
  137. package/dist/{projectBucket-DNAOBIYZ.mjs.map → projectBucket-BPzx0b0t.mjs.map} +1 -1
  138. package/dist/{projectBucket-XyxlpATc.cjs → projectBucket-CoskwJC5.cjs} +2 -2
  139. package/dist/{projectBucket-XyxlpATc.cjs.map → projectBucket-CoskwJC5.cjs.map} +1 -1
  140. package/dist/{publish-DmBXVNlk.cjs → publish-DB3-zkpm.cjs} +2 -2
  141. package/dist/{publish-DmBXVNlk.cjs.map → publish-DB3-zkpm.cjs.map} +1 -1
  142. package/dist/{publish-CwjRq8Ye.mjs → publish-LZ1eb-MI.mjs} +2 -2
  143. package/dist/{publish-CwjRq8Ye.mjs.map → publish-LZ1eb-MI.mjs.map} +1 -1
  144. package/dist/reconcile/public.d.cts +1 -1
  145. package/dist/reconcile/public.d.mts +1 -1
  146. package/dist/{resolve-BuqA14hD.cjs → resolve-B5_tOTJG.cjs} +4 -4
  147. package/dist/{resolve-BuqA14hD.cjs.map → resolve-B5_tOTJG.cjs.map} +1 -1
  148. package/dist/{resolve-vOUrXSHP.mjs → resolve-jez3Y1S0.mjs} +4 -4
  149. package/dist/{resolve-vOUrXSHP.mjs.map → resolve-jez3Y1S0.mjs.map} +1 -1
  150. package/dist/{rollback-CiyKH1HK.cjs → rollback-BNo1bCLO.cjs} +8 -8
  151. package/dist/{rollback-CiyKH1HK.cjs.map → rollback-BNo1bCLO.cjs.map} +1 -1
  152. package/dist/{rollback-glkFgz6-.mjs → rollback-BtOfxwo-.mjs} +8 -8
  153. package/dist/{rollback-glkFgz6-.mjs.map → rollback-BtOfxwo-.mjs.map} +1 -1
  154. package/dist/{runtime-MZ5Pqgan.d.mts → runtime-CKOkIrw0.d.cts} +2 -2
  155. package/dist/{runtime-BySbkdBz.d.cts.map → runtime-CKOkIrw0.d.cts.map} +1 -1
  156. package/dist/{runtime-BySbkdBz.d.cts → runtime-Cdvv8SfU.d.mts} +2 -2
  157. package/dist/{runtime-MZ5Pqgan.d.mts.map → runtime-Cdvv8SfU.d.mts.map} +1 -1
  158. package/dist/{s3-BZbRcH8T.mjs → s3-Bf_75vVl.mjs} +3 -3
  159. package/dist/{s3-BZbRcH8T.mjs.map → s3-Bf_75vVl.mjs.map} +1 -1
  160. package/dist/{s3-C0EBuF8n.cjs → s3-BlPwyu1L.cjs} +3 -3
  161. package/dist/{s3-C0EBuF8n.cjs.map → s3-BlPwyu1L.cjs.map} +1 -1
  162. package/dist/{seeds-D7q1zKCJ.cjs → seeds-Bc3niNVb.cjs} +95 -82
  163. package/dist/seeds-Bc3niNVb.cjs.map +1 -0
  164. package/dist/{seeds-y1rzXlAc.mjs → seeds-Ccn0Ru2T.mjs} +84 -83
  165. package/dist/seeds-Ccn0Ru2T.mjs.map +1 -0
  166. package/dist/{serverSetup-Dlj7JQW-.mjs → serverSetup-D0Zor2i4.mjs} +8 -8
  167. package/dist/{serverSetup-Dlj7JQW-.mjs.map → serverSetup-D0Zor2i4.mjs.map} +1 -1
  168. package/dist/{serverSetup-n1Znminh.cjs → serverSetup-D30vVD6t.cjs} +8 -8
  169. package/dist/{serverSetup-n1Znminh.cjs.map → serverSetup-D30vVD6t.cjs.map} +1 -1
  170. package/dist/{sniffer-DDAxYDqU.cjs → sniffer-Bw00z3I8.cjs} +8 -8
  171. package/dist/{sniffer-DDAxYDqU.cjs.map → sniffer-Bw00z3I8.cjs.map} +1 -1
  172. package/dist/{sniffer-BgzTs_Zt.mjs → sniffer-DdPDiNmc.mjs} +8 -8
  173. package/dist/{sniffer-BgzTs_Zt.mjs.map → sniffer-DdPDiNmc.mjs.map} +1 -1
  174. package/dist/{snsSubscriptions-CCyxCMoc.mjs → snsSubscriptions-DBxVTR6Y.mjs} +3 -3
  175. package/dist/{snsSubscriptions-CCyxCMoc.mjs.map → snsSubscriptions-DBxVTR6Y.mjs.map} +1 -1
  176. package/dist/{snsSubscriptions-Dr5ghfa5.cjs → snsSubscriptions-g7apv_fy.cjs} +3 -3
  177. package/dist/{snsSubscriptions-Dr5ghfa5.cjs.map → snsSubscriptions-g7apv_fy.cjs.map} +1 -1
  178. package/dist/{sst-DBkHn3mA.cjs → sst-CEs0bMxj.cjs} +6 -6
  179. package/dist/{sst-DBkHn3mA.cjs.map → sst-CEs0bMxj.cjs.map} +1 -1
  180. package/dist/{sst-CV5TemXa.mjs → sst-DJ22YDEq.mjs} +5 -5
  181. package/dist/{sst-CV5TemXa.mjs.map → sst-DJ22YDEq.mjs.map} +1 -1
  182. package/dist/{stack-Dku1pOA2.cjs → stack-BmG-lKgD.cjs} +12 -13
  183. package/dist/{stack-Dku1pOA2.cjs.map → stack-BmG-lKgD.cjs.map} +1 -1
  184. package/dist/{stack-r97Ao-uG.mjs → stack-Ds9jjpE1.mjs} +7 -8
  185. package/dist/{stack-r97Ao-uG.mjs.map → stack-Ds9jjpE1.mjs.map} +1 -1
  186. package/dist/{stage-Deb-7Ohk.mjs → stage-D9dfV1Ey.mjs} +7 -7
  187. package/dist/{stage-Deb-7Ohk.mjs.map → stage-D9dfV1Ey.mjs.map} +1 -1
  188. package/dist/{stage-Du8I-UIa.cjs → stage-kGc9L3yB.cjs} +7 -7
  189. package/dist/{stage-Du8I-UIa.cjs.map → stage-kGc9L3yB.cjs.map} +1 -1
  190. package/dist/{stages-CW7qtiJ2.mjs → stages-BL22BLJS.mjs} +3 -3
  191. package/dist/{stages-CW7qtiJ2.mjs.map → stages-BL22BLJS.mjs.map} +1 -1
  192. package/dist/{stages-CtqmEJJW.cjs → stages-CN53nNOK.cjs} +3 -3
  193. package/dist/{stages-CtqmEJJW.cjs.map → stages-CN53nNOK.cjs.map} +1 -1
  194. package/dist/target/public.cjs +1 -1
  195. package/dist/target/public.d.cts +2 -2
  196. package/dist/target/public.d.mts +2 -2
  197. package/dist/target/public.mjs +1 -1
  198. package/dist/{terminal-BEa0E3pz.mjs → terminal-C0A7S7fB.mjs} +2 -2
  199. package/dist/{terminal-BEa0E3pz.mjs.map → terminal-C0A7S7fB.mjs.map} +1 -1
  200. package/dist/{terminal-BXpp9kBr.cjs → terminal-DVlIWcUb.cjs} +2 -2
  201. package/dist/{terminal-BXpp9kBr.cjs.map → terminal-DVlIWcUb.cjs.map} +1 -1
  202. package/dist/{types-BsfPHUFZ.d.cts → types-DEmuMHsS.d.cts} +9 -1
  203. package/dist/types-DEmuMHsS.d.cts.map +1 -0
  204. package/dist/{types-BXboFkn9.d.mts → types-g_S0_RAi.d.mts} +9 -1
  205. package/dist/types-g_S0_RAi.d.mts.map +1 -0
  206. package/dist/workspace/index.cjs +1 -1
  207. package/dist/workspace/index.d.cts +2 -2
  208. package/dist/workspace/index.d.mts +2 -2
  209. package/dist/workspace/index.mjs +1 -1
  210. package/dist/{workspace-D5Vm2qcy.mjs → workspace-D4hzz6Xb.mjs} +331 -3
  211. package/dist/workspace-D4hzz6Xb.mjs.map +1 -0
  212. package/dist/{workspace-VhzmoxOv.cjs → workspace-DPSdiv-b.cjs} +371 -1
  213. package/dist/workspace-DPSdiv-b.cjs.map +1 -0
  214. package/package.json +15 -15
  215. package/dist/compose-BfTrMiAk.mjs.map +0 -1
  216. package/dist/compose-kEjxTamg.cjs.map +0 -1
  217. package/dist/config-CXj-9eRo.cjs +0 -890
  218. package/dist/config-CXj-9eRo.cjs.map +0 -1
  219. package/dist/config-Di0oJwM9.mjs +0 -759
  220. package/dist/config-Di0oJwM9.mjs.map +0 -1
  221. package/dist/deploy-C4V-nsOF.cjs.map +0 -1
  222. package/dist/deploy-D-5ib-ah.mjs.map +0 -1
  223. package/dist/github-BDOLgdMp.cjs.map +0 -1
  224. package/dist/github-D2l7aqFx.mjs.map +0 -1
  225. package/dist/seeds-D7q1zKCJ.cjs.map +0 -1
  226. package/dist/seeds-y1rzXlAc.mjs.map +0 -1
  227. package/dist/types-BXboFkn9.d.mts.map +0 -1
  228. package/dist/types-BsfPHUFZ.d.cts.map +0 -1
  229. package/dist/workspace-D5Vm2qcy.mjs.map +0 -1
  230. package/dist/workspace-VhzmoxOv.cjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"github-BDOLgdMp.cjs","names":["GkmError","projectBucketName","deployIdentity","PROJECT_BUCKET_CREATE_ACTIONS","s3SecretsLocation","s3SecretsKey","secretsParameterName","secretsManagerSecretName","stageProvider","bucketName","iamUserName","IAM_USER_PATH","emailUserName","stageBackups","backupsUserName","PROJECT_BUCKET_LIFECYCLE_ACTIONS","stageDnsDomains","execFileSync","ListOpenIDConnectProvidersCommand","CreateOpenIDConnectProviderCommand","GetRoleCommand","UpdateAssumeRolePolicyCommand","ListRoleTagsCommand","CreateRoleCommand","DetachRolePolicyCommand","DeleteRolePolicyCommand","AttachRolePolicyCommand","TagRoleCommand","PutRolePolicyCommand","UntagRoleCommand","ListAttachedRolePoliciesCommand","IAMClient","loadWorkspaceConfig","discover","constructGlobs","readKey","keystoreProject","getKeyPath","isRemoteStore","secretsStoreFor","GkmError"],"sources":["../src/deploy/githubOidc.ts","../src/deploy/githubPolicy.ts","../src/deploy/github.ts"],"sourcesContent":["/**\n * The `sub` GitHub puts in a deploy job's OIDC token — what the deploy role's\n * trust policy has to match exactly.\n *\n * It is not always `repo:<owner>/<name>:environment:<stage>`. A repository\n * (or its organisation) decides the format, and says which through\n * `GET /repos/{owner}/{repo}/actions/oidc/customization/sub`:\n *\n * - the default: `repo:<owner>/<name>:environment:<stage>`;\n * - the immutable subject — the default for repositories created after\n * 15 July 2026, opt-in before — puts the owner's and the repository's ids in\n * the `repo` segment: `repo:<owner>@<ownerId>/<name>@<repoId>:environment:<stage>`.\n * The API hands that segment back as `sub_claim_prefix`;\n * - a custom template (`use_default: false`) builds the `sub` from\n * `include_claim_keys`, in order, each as `<key>:<value>` joined by `:`,\n * where `context` is `environment:<stage>` in an environment job.\n *\n * A `:` inside a value is sent as `%3A`.\n *\n * See https://docs.github.com/en/actions/reference/security/oidc.\n */\n\nimport { GkmError } from '../errors';\nimport type { Gh } from './github.js';\n\n/** `GET /repos/{owner}/{repo}/actions/oidc/customization/sub`. */\nexport interface OidcSubjectCustomization {\n\tuse_default: boolean;\n\tinclude_claim_keys?: string[];\n\tuse_immutable_subject?: boolean;\n\t/** The `repo` segment of the subject, as GitHub will send it. */\n\tsub_claim_prefix?: string;\n}\n\n/** What `GET /repos/{owner}/{repo}` says that a subject may include. */\nexport interface RepoFacts {\n\townerId: number;\n\trepoId: number;\n\tvisibility: string;\n}\n\n/**\n * Template keys whose values are known for a repository's environment job\n * before the job runs. Anything else — `job_workflow_ref`, `ref`, `sha`,\n * `run_id`, `workflow`, `actor`, a custom property — depends on the run.\n */\nexport const SUPPORTED_CLAIM_KEYS = [\n\t'repo',\n\t'context',\n\t'environment',\n\t'repository',\n\t'repository_owner',\n\t'repository_owner_id',\n\t'repository_id',\n\t'repository_visibility',\n] as const;\n\nconst NEEDS_FACTS = new Set([\n\t'repository_owner_id',\n\t'repository_id',\n\t'repository_visibility',\n]);\n\n/** A `:` inside a claim value is sent as `%3A`. */\nfunction claim(value: string): string {\n\treturn value.replaceAll(':', '%3A');\n}\n\n/** Which kind of subject the repository uses, for the output. */\nexport type OidcSubjectKind = 'default' | 'immutable' | 'custom' | 'assumed';\n\n/** Whether {@link oidcSubject} needs the repository's ids or visibility. */\nexport function needsRepoFacts(\n\tcustomization: OidcSubjectCustomization,\n): boolean {\n\tconst immutableWithoutPrefix =\n\t\tcustomization.use_immutable_subject === true &&\n\t\t!customization.sub_claim_prefix;\n\tif (customization.use_default) return immutableWithoutPrefix;\n\n\tconst keys = customization.include_claim_keys ?? [];\n\treturn keys.some(\n\t\t(key) => NEEDS_FACTS.has(key) || (key === 'repo' && immutableWithoutPrefix),\n\t);\n}\n\n/**\n * The exact `sub` of a job in `repo`'s `stage` environment.\n *\n * @throws OidcSubjectNotSupported when a custom template includes a claim\n * whose value depends on the run, so no one subject can be trusted.\n */\nexport function oidcSubject(\n\trepo: string,\n\tstage: string,\n\tcustomization: OidcSubjectCustomization,\n\tfacts?: RepoFacts,\n): { subject: string; kind: OidcSubjectKind } {\n\tconst [owner = '', name = ''] = repo.split('/');\n\tconst environment = `environment:${claim(stage)}`;\n\n\tconst repoSegment = (): string => {\n\t\tif (customization.sub_claim_prefix) return customization.sub_claim_prefix;\n\t\tif (customization.use_immutable_subject) {\n\t\t\tif (!facts) throw new RepoFactsRequired(repo);\n\t\t\treturn `repo:${owner}@${facts.ownerId}/${name}@${facts.repoId}`;\n\t\t}\n\t\treturn `repo:${repo}`;\n\t};\n\tconst immutable =\n\t\tcustomization.use_immutable_subject === true ||\n\t\tcustomization.sub_claim_prefix !== undefined;\n\n\tif (customization.use_default) {\n\t\treturn {\n\t\t\tsubject: `${repoSegment()}:${environment}`,\n\t\t\tkind: immutable ? 'immutable' : 'default',\n\t\t};\n\t}\n\n\tconst keys = customization.include_claim_keys ?? [];\n\tconst unsupported = keys.filter(\n\t\t(key) => !(SUPPORTED_CLAIM_KEYS as readonly string[]).includes(key),\n\t);\n\tif (keys.length === 0 || unsupported.length > 0) {\n\t\tthrow new OidcSubjectNotSupported(repo, keys, unsupported);\n\t}\n\tif (keys.some((key) => NEEDS_FACTS.has(key)) && !facts) {\n\t\tthrow new RepoFactsRequired(repo);\n\t}\n\n\tconst parts = keys.map((key) => {\n\t\tswitch (key) {\n\t\t\tcase 'repo':\n\t\t\t\treturn repoSegment();\n\t\t\tcase 'context':\n\t\t\tcase 'environment':\n\t\t\t\treturn environment;\n\t\t\tcase 'repository':\n\t\t\t\treturn `repository:${claim(repo)}`;\n\t\t\tcase 'repository_owner':\n\t\t\t\treturn `repository_owner:${claim(owner)}`;\n\t\t\tcase 'repository_owner_id':\n\t\t\t\treturn `repository_owner_id:${facts!.ownerId}`;\n\t\t\tcase 'repository_id':\n\t\t\t\treturn `repository_id:${facts!.repoId}`;\n\t\t\tdefault:\n\t\t\t\treturn `repository_visibility:${claim(facts!.visibility)}`;\n\t\t}\n\t});\n\treturn { subject: parts.join(':'), kind: 'custom' };\n}\n\n/** What {@link resolveOidcSubject} found. */\nexport interface ResolvedOidcSubject {\n\tsubject: string;\n\tkind: OidcSubjectKind;\n\t/** Set when the format could not be read and the default was assumed. */\n\twarning?: string;\n}\n\n/** The endpoint a repository's subject format is read from. */\nexport function customizationEndpoint(repo: string): string {\n\treturn `repos/${repo}/actions/oidc/customization/sub`;\n}\n\n/**\n * The `sub` GitHub will send for `repo`'s `stage` environment, read from the\n * repository's OIDC settings through `gh`.\n *\n * A repository on a custom template that names no keys of its own uses its\n * organisation's, read from `orgs/{owner}/actions/oidc/customization/sub`.\n * When the settings cannot be read at all — no permission, or a GitHub\n * Enterprise Server without the endpoint — the default format is assumed, with\n * a warning saying where to check it.\n */\nexport function resolveOidcSubject(\n\tgh: Gh,\n\trepo: string,\n\tstage: string,\n): ResolvedOidcSubject {\n\tconst endpoint = customizationEndpoint(repo);\n\tlet customization: OidcSubjectCustomization;\n\ttry {\n\t\tcustomization = JSON.parse(gh(['api', endpoint]));\n\t} catch {\n\t\treturn {\n\t\t\tsubject: `repo:${repo}:environment:${claim(stage)}`,\n\t\t\tkind: 'assumed',\n\t\t\twarning: `Could not read ${endpoint}, so the default subject format is assumed. Check it with: gh api ${endpoint} — a repository on the immutable subject or a custom template sends a different sub, and the role would not be assumable.`,\n\t\t};\n\t}\n\n\tif (\n\t\t!customization.use_default &&\n\t\t(customization.include_claim_keys ?? []).length === 0\n\t) {\n\t\t// The repository follows its organisation's template.\n\t\tconst [owner = ''] = repo.split('/');\n\t\tconst orgEndpoint = `orgs/${owner}/actions/oidc/customization/sub`;\n\t\tlet org: { include_claim_keys?: string[]; use_immutable_subject?: boolean };\n\t\ttry {\n\t\t\torg = JSON.parse(gh(['api', orgEndpoint]));\n\t\t} catch {\n\t\t\tthrow new OrgOidcTemplateUnreadable(repo, orgEndpoint);\n\t\t}\n\t\tcustomization = {\n\t\t\t...customization,\n\t\t\tinclude_claim_keys: org.include_claim_keys ?? [],\n\t\t\tuse_immutable_subject:\n\t\t\t\tcustomization.use_immutable_subject ?? org.use_immutable_subject,\n\t\t};\n\t}\n\n\tconst facts = needsRepoFacts(customization)\n\t\t? readRepoFacts(gh, repo)\n\t\t: undefined;\n\treturn oidcSubject(repo, stage, customization, facts);\n}\n\nfunction readRepoFacts(gh: Gh, repo: string): RepoFacts {\n\tconst raw = JSON.parse(gh(['api', `repos/${repo}`])) as {\n\t\tid: number;\n\t\towner: { id: number };\n\t\tvisibility: string;\n\t};\n\treturn {\n\t\townerId: raw.owner.id,\n\t\trepoId: raw.id,\n\t\tvisibility: raw.visibility,\n\t};\n}\n\n/**\n * The repository's custom subject template includes a claim whose value\n * depends on the run — or names none — so no one subject can be trusted.\n */\nexport class OidcSubjectNotSupported extends GkmError {\n\tconstructor(\n\t\treadonly repo: string,\n\t\treadonly includeClaimKeys: string[],\n\t\treadonly unsupportedKeys: string[],\n\t) {\n\t\tsuper(\n\t\t\t`${repo} builds its OIDC subject from a custom template, ${JSON.stringify(includeClaimKeys)}, and ${\n\t\t\t\tunsupportedKeys.length > 0\n\t\t\t\t\t? `${unsupportedKeys.join(', ')} depend${unsupportedKeys.length === 1 ? 's' : ''} on the run`\n\t\t\t\t\t: 'it names no claims'\n\t\t\t}, so the deploy role cannot trust one exact subject. Set the repository back to the default subject — gh api --method PUT ${customizationEndpoint(repo)} -F use_default=true — (or keep the immutable one by also passing -F use_immutable_subject=true), or use a template built only from ${SUPPORTED_CLAIM_KEYS.join(', ')}; then run this again.`,\n\t\t);\n\t\tthis.name = 'OidcSubjectNotSupported';\n\t}\n}\n\n/** The subject needs the repository's ids, and none were read. */\nexport class RepoFactsRequired extends GkmError {\n\tconstructor(readonly repo: string) {\n\t\tsuper(\n\t\t\t`The OIDC subject of ${repo} includes its owner and repository ids; read them with gh api repos/${repo} and pass them in.`,\n\t\t);\n\t\tthis.name = 'RepoFactsRequired';\n\t}\n}\n\n/**\n * The repository uses its organisation's subject template, and that template\n * could not be read — so what GitHub sends is unknown, and is not guessed.\n */\nexport class OrgOidcTemplateUnreadable extends GkmError {\n\tconstructor(\n\t\treadonly repo: string,\n\t\treadonly endpoint: string,\n\t) {\n\t\tsuper(\n\t\t\t`${repo} uses its organisation's OIDC subject template, and ${endpoint} could not be read. Run this as an organisation owner (gh auth refresh -s admin:org), or set the repository back to the default subject with gh api --method PUT ${customizationEndpoint(repo)} -F use_default=true; then run this again.`,\n\t\t);\n\t\tthis.name = 'OrgOidcTemplateUnreadable';\n\t}\n}\n","/**\n * What the deploy role may do in the stage's account.\n *\n * An SST stage creates its own stack, which is most of AWS, so its role gets\n * `AdministratorAccess`. A stage deployed with the `compose` target builds and\n * runs containers on a server; from AWS its deploy job needs only the stage's\n * secrets — read, and written back when a deploy generates a new one: the one\n * object in the project bucket, or the SSM parameter or Secrets Manager secret\n * — and,\n * when the deploy state is kept in AWS, the stage's state, and, when the\n * stage's domain is in Route53, the records of its hosted zone, and, when an\n * `s3` provider backs its buckets, those buckets and the IAM user each is\n * reached with — by the names the provider gives them — and, when it runs\n * Postgres, the project bucket its backups go to and the backups user. So a\n * compose stage gets an inline policy naming exactly those resources and\n * nothing else.\n *\n * `--policy-arn` replaces either.\n */\n\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport { stageBackups } from '../backups/config.js';\nimport { backupsUserName } from '../backups/provision.js';\nimport { stageDnsDomains } from '../compose/dns.js';\nimport { stageProvider } from '../providers/config.js';\nimport {\n\tPROJECT_BUCKET_CREATE_ACTIONS,\n\tPROJECT_BUCKET_LIFECYCLE_ACTIONS,\n\tprojectBucketName,\n} from '../providers/projectBucket.js';\nimport {\n\tbucketName,\n\tIAM_USER_PATH,\n\tiamUserName,\n\tSUFFIX_LENGTH,\n} from '../providers/s3/naming.js';\nimport { emailUserName } from '../providers/ses/config.js';\nimport { secretsParameterName } from '../secrets/aws.js';\nimport { s3SecretsKey, s3SecretsLocation } from '../secrets/providers.js';\nimport { secretsManagerSecretName } from '../secrets/secretsManager.js';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\nimport { deployIdentity } from './identity.js';\n\n/**\n * What SST needs to create a stack is most of AWS, so this is the default\n * outside compose — said out loud in the output, and replaceable with\n * `--policy-arn`.\n */\nexport const DEFAULT_POLICY_ARN = 'arn:aws:iam::aws:policy/AdministratorAccess';\n\n/** The name of the inline policy a compose stage's role is given. */\nexport const SCOPED_POLICY_NAME = 'gkm-deploy';\n\n/** One statement of an IAM policy document. */\nexport interface PolicyStatement {\n\tSid: string;\n\tEffect: 'Allow';\n\tAction: string[];\n\tResource: string | string[];\n\tCondition?: Record<string, Record<string, string>>;\n}\n\n/** What the role is given. */\nexport type DeployAccess =\n\t| {\n\t\t\tkind: 'managed';\n\t\t\tpolicyArn: string;\n\t\t\t/** Why, for the output. */\n\t\t\treason: string;\n\t }\n\t| {\n\t\t\tkind: 'scoped';\n\t\t\t/** The statements, in the account the role is in. */\n\t\t\tstatements(account: string): PolicyStatement[];\n\t\t\t/** What each statement is for, for the output. */\n\t\t\tdescribe: string[];\n\t };\n\n/** Every target the stage's apps deploy through. */\nexport function deployTargets(workspace: NormalizedWorkspace): string[] {\n\tconst targets = new Set<string>([workspace.deploy?.default ?? 'dokploy']);\n\tfor (const app of Object.values(workspace.apps)) {\n\t\ttargets.add(app.resolvedDeployTarget);\n\t}\n\treturn [...targets].sort();\n}\n\n/**\n * The access the stage's deploy role is given: `--policy-arn` when passed,\n * the scoped policy for a stage only the compose target deploys, and\n * `AdministratorAccess` otherwise.\n */\nexport function deployAccess(\n\tworkspace: NormalizedWorkspace,\n\tstage: string,\n\tpolicyArn?: string,\n\t/** The stage's constructs: its buckets, and whether it runs Postgres. */\n\tmanifest: ConstructManifest = {},\n): DeployAccess {\n\tconst buckets = Object.entries(manifest)\n\t\t.filter(([, d]) => d.kind === 'objects')\n\t\t.map(([id]) => id);\n\tif (policyArn) {\n\t\treturn { kind: 'managed', policyArn, reason: '--policy-arn' };\n\t}\n\n\tconst targets = deployTargets(workspace);\n\tif (targets.length !== 1 || targets[0] !== 'compose') {\n\t\treturn {\n\t\t\tkind: 'managed',\n\t\t\tpolicyArn: DEFAULT_POLICY_ARN,\n\t\t\treason: `the ${targets.join(', ')} target${targets.length === 1 ? '' : 's'} deploy${targets.length === 1 ? 's' : ''} infrastructure; --policy-arn to narrow`,\n\t\t};\n\t}\n\n\tconst project = workspace.name;\n\tconst store = workspace.secrets.store ?? 'file';\n\tconst state = workspace.state;\n\tconst custom =\n\t\t(typeof store === 'object' && typeof store.provider === 'object') ||\n\t\t(state !== undefined && typeof state.provider === 'object');\n\tif (custom) {\n\t\treturn {\n\t\t\tkind: 'managed',\n\t\t\tpolicyArn: DEFAULT_POLICY_ARN,\n\t\t\treason: `a custom ${typeof store === 'object' && typeof store.provider === 'object' ? 'secrets store' : 'state provider'} cannot be scoped; --policy-arn to narrow`,\n\t\t};\n\t}\n\n\tconst describe: string[] = [];\n\tconst build: ((account: string) => PolicyStatement[])[] = [];\n\n\t// The project bucket's name is fixed by the account, so the role is given\n\t// exactly it, and the actions that create it for whichever run is first.\n\tconst projectBucketIn = (account: string) =>\n\t\tprojectBucketName(deployIdentity(workspace, stage).scope, account);\n\tconst projectBucketStatement = (account: string): PolicyStatement => ({\n\t\tSid: 'ProjectBucket',\n\t\tEffect: 'Allow',\n\t\tAction: [...PROJECT_BUCKET_CREATE_ACTIONS],\n\t\tResource: `arn:aws:s3:::${projectBucketIn(account)}`,\n\t});\n\t// Whether the state's statements already cover the secrets' bucket.\n\tconst stateInSecretsBucket =\n\t\ttypeof store === 'object' &&\n\t\tstore.provider === 's3' &&\n\t\tstate?.provider === 's3' &&\n\t\tstate.bucket === (store as { bucket?: string }).bucket;\n\n\tif (typeof store === 'object' && store.provider === 's3') {\n\t\tconst location = s3SecretsLocation(store, state);\n\t\tconst key = s3SecretsKey(location.prefix, project, stage);\n\t\tconst named = location.bucket;\n\t\tconst bucketIn = (account: string) => named ?? projectBucketIn(account);\n\t\tdescribe.push(\n\t\t\tnamed\n\t\t\t\t? `read and update s3://${named}/${key}`\n\t\t\t\t: `read and update ${key} in the project bucket ${projectBucketIn('<account>')}${stateInSecretsBucket ? '' : ', creating it'}`,\n\t\t);\n\t\tbuild.push((account) => [\n\t\t\t{\n\t\t\t\tSid: 'StageSecrets',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: ['s3:GetObject', 's3:PutObject'],\n\t\t\t\tResource: `arn:aws:s3:::${bucketIn(account)}/${key}`,\n\t\t\t},\n\t\t\t// The state's statements give these when it is in the same bucket.\n\t\t\t...(stateInSecretsBucket\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// HeadBucket, and secrets not written yet a 404, not a 403.\n\t\t\t\t\t\t\tSid: 'StageSecretsBucket',\n\t\t\t\t\t\t\tEffect: 'Allow' as const,\n\t\t\t\t\t\t\tAction: ['s3:ListBucket'],\n\t\t\t\t\t\t\tResource: `arn:aws:s3:::${bucketIn(account)}`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t...(named ? [] : [projectBucketStatement(account)]),\n\t\t\t\t\t]),\n\t\t]);\n\t} else if (typeof store === 'object' && store.provider === 'ssm') {\n\t\tconst { region } = store;\n\t\tconst name = secretsParameterName(project, stage);\n\t\tdescribe.push(`read and update ${name} (SSM, ${region})`);\n\t\tbuild.push((account) => [\n\t\t\t{\n\t\t\t\tSid: 'StageSecrets',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: ['ssm:GetParameter', 'ssm:PutParameter'],\n\t\t\t\tResource: `arn:aws:ssm:${region}:${account}:parameter${name}`,\n\t\t\t},\n\t\t]);\n\t} else if (\n\t\ttypeof store === 'object' &&\n\t\tstore.provider === 'secrets-manager'\n\t) {\n\t\tconst { region, kmsKeyId } = store as { region: string; kmsKeyId?: string };\n\t\tconst name = secretsManagerSecretName(project, stage);\n\t\tdescribe.push(`read and update ${name} (Secrets Manager, ${region})`);\n\t\tbuild.push((account) => {\n\t\t\tconst statements: PolicyStatement[] = [\n\t\t\t\t{\n\t\t\t\t\tSid: 'StageSecrets',\n\t\t\t\t\tEffect: 'Allow',\n\t\t\t\t\tAction: [\n\t\t\t\t\t\t'secretsmanager:GetSecretValue',\n\t\t\t\t\t\t'secretsmanager:PutSecretValue',\n\t\t\t\t\t\t'secretsmanager:CreateSecret',\n\t\t\t\t\t],\n\t\t\t\t\t// Secrets Manager appends six random characters to a secret's ARN.\n\t\t\t\t\tResource: `arn:aws:secretsmanager:${region}:${account}:secret:${name}-??????`,\n\t\t\t\t},\n\t\t\t];\n\t\t\tif (kmsKeyId) {\n\t\t\t\tstatements.push({\n\t\t\t\t\tSid: 'StageSecretsKey',\n\t\t\t\t\tEffect: 'Allow',\n\t\t\t\t\tAction: ['kms:Decrypt', 'kms:GenerateDataKey'],\n\t\t\t\t\tResource: kmsKeyId.startsWith('arn:') ? kmsKeyId : '*',\n\t\t\t\t\tCondition: {\n\t\t\t\t\t\tStringEquals: {\n\t\t\t\t\t\t\t'kms:ViaService': `secretsmanager.${region}.amazonaws.com`,\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\treturn statements;\n\t\t});\n\t}\n\n\tif (state?.provider === 'ssm') {\n\t\tconst { region } = state;\n\t\tconst path = `/gkm/${project}/${stage}/`;\n\t\tdescribe.push(\n\t\t\t`read and write the deploy state under ${path} (SSM, ${region})`,\n\t\t);\n\t\tbuild.push((account) => [\n\t\t\t{\n\t\t\t\tSid: 'StageState',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: ['ssm:GetParameter', 'ssm:PutParameter', 'ssm:DeleteParameter'],\n\t\t\t\tResource: `arn:aws:ssm:${region}:${account}:parameter${path}*`,\n\t\t\t},\n\t\t]);\n\t} else if (state?.provider === 's3') {\n\t\tconst prefix = (state.prefix ?? 'gkm').replace(/\\/+$/, '');\n\t\tconst path = `${prefix ? `${prefix}/` : ''}${project}/${stage}/`;\n\t\tconst named = state.bucket;\n\t\t// No bucket named: the project bucket, which the first deploy creates.\n\t\tconst bucketIn = (account: string) => named ?? projectBucketIn(account);\n\t\tdescribe.push(\n\t\t\tnamed\n\t\t\t\t? `read and write the deploy state under s3://${named}/${path}`\n\t\t\t\t: `create the project bucket ${projectBucketIn('<account>')}, and read and write the deploy state under ${path} in it`,\n\t\t);\n\t\tbuild.push((account) => [\n\t\t\t...stateBucketStatements(bucketIn(account), path),\n\t\t\t...(named ? [] : [projectBucketStatement(account)]),\n\t\t]);\n\t}\n\n\t// The deploy creates each bucket an s3 provider backs, and the IAM user\n\t// and key it is reached with: by their names — the good one, or the good\n\t// one with a clash's six-character suffix — and nothing else.\n\tconst objects = stageProvider(workspace, 'objects', stage);\n\tif (objects.mode === 'provider' && objects.name === 's3' && buckets.length) {\n\t\tconst { scope } = deployIdentity(workspace, stage);\n\t\tconst names = [...buckets].sort().map((id) => ({\n\t\t\tbucket: bucketName({ scope, stage, id }),\n\t\t\tuser: iamUserName({ scope, stage, id }),\n\t\t}));\n\t\tconst suffix = '?'.repeat(SUFFIX_LENGTH - 1);\n\t\tdescribe.push(\n\t\t\t`create and configure the buckets ${names.map((n) => n.bucket).join(', ')}, their IAM users, and — for a bucket a subscriber watches — its events topic, dead-letter queue and subscriptions (S3, IAM, SNS, SQS)`,\n\t\t);\n\t\tbuild.push((account) => [\n\t\t\t{\n\t\t\t\tSid: 'StageBuckets',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t's3:CreateBucket',\n\t\t\t\t\t's3:ListBucket',\n\t\t\t\t\t's3:GetBucketTagging',\n\t\t\t\t\t's3:PutBucketTagging',\n\t\t\t\t\t's3:GetBucketPublicAccessBlock',\n\t\t\t\t\t's3:PutBucketPublicAccessBlock',\n\t\t\t\t\t's3:GetBucketPolicy',\n\t\t\t\t\t's3:PutBucketPolicy',\n\t\t\t\t\t's3:GetEncryptionConfiguration',\n\t\t\t\t\t's3:PutEncryptionConfiguration',\n\t\t\t\t\t's3:GetBucketVersioning',\n\t\t\t\t\t's3:PutBucketVersioning',\n\t\t\t\t\t's3:GetBucketCORS',\n\t\t\t\t\t's3:PutBucketCORS',\n\t\t\t\t\t's3:GetBucketNotification',\n\t\t\t\t\t's3:PutBucketNotification',\n\t\t\t\t\t// A construct's `expire`, and removing it: S3 authorises\n\t\t\t\t\t// DeleteBucketLifecycle as PutLifecycleConfiguration.\n\t\t\t\t\t's3:GetLifecycleConfiguration',\n\t\t\t\t\t's3:PutLifecycleConfiguration',\n\t\t\t\t],\n\t\t\t\tResource: names.flatMap((n) => [\n\t\t\t\t\t`arn:aws:s3:::${n.bucket}`,\n\t\t\t\t\t`arn:aws:s3:::${n.bucket}-${suffix}`,\n\t\t\t\t]),\n\t\t\t},\n\t\t\t// A watched bucket's events: its topic and the subscriptions to it —\n\t\t\t// in whichever region the bucket is — and its dead-letter queue.\n\t\t\t{\n\t\t\t\tSid: 'StageBucketTopics',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t'sns:CreateTopic',\n\t\t\t\t\t'sns:TagResource',\n\t\t\t\t\t'sns:GetTopicAttributes',\n\t\t\t\t\t'sns:SetTopicAttributes',\n\t\t\t\t\t'sns:Subscribe',\n\t\t\t\t\t'sns:Unsubscribe',\n\t\t\t\t\t'sns:ListSubscriptionsByTopic',\n\t\t\t\t\t'sns:GetSubscriptionAttributes',\n\t\t\t\t\t'sns:SetSubscriptionAttributes',\n\t\t\t\t],\n\t\t\t\tResource: names.flatMap((n) =>\n\t\t\t\t\t[`${n.bucket}-events`, `${n.bucket}-${suffix}-events`].flatMap(\n\t\t\t\t\t\t(topic) => [\n\t\t\t\t\t\t\t`arn:aws:sns:*:${account}:${topic}`,\n\t\t\t\t\t\t\t`arn:aws:sns:*:${account}:${topic}:*`,\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\t{\n\t\t\t\tSid: 'StageBucketDeadLetters',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t'sqs:CreateQueue',\n\t\t\t\t\t'sqs:TagQueue',\n\t\t\t\t\t'sqs:GetQueueUrl',\n\t\t\t\t\t'sqs:GetQueueAttributes',\n\t\t\t\t\t'sqs:SetQueueAttributes',\n\t\t\t\t],\n\t\t\t\tResource: names.flatMap((n) => [\n\t\t\t\t\t`arn:aws:sqs:*:${account}:${n.bucket}-events-dlq`,\n\t\t\t\t\t`arn:aws:sqs:*:${account}:${n.bucket}-${suffix}-events-dlq`,\n\t\t\t\t]),\n\t\t\t},\n\t\t\t{\n\t\t\t\tSid: 'StageBucketUsers',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t'iam:GetUser',\n\t\t\t\t\t'iam:CreateUser',\n\t\t\t\t\t'iam:TagUser',\n\t\t\t\t\t'iam:ListUserTags',\n\t\t\t\t\t'iam:GetUserPolicy',\n\t\t\t\t\t'iam:PutUserPolicy',\n\t\t\t\t\t'iam:ListAccessKeys',\n\t\t\t\t\t'iam:CreateAccessKey',\n\t\t\t\t\t'iam:DeleteAccessKey',\n\t\t\t\t],\n\t\t\t\tResource: names.map(\n\t\t\t\t\t(n) => `arn:aws:iam::${account}:user${IAM_USER_PATH}${n.user}`,\n\t\t\t\t),\n\t\t\t},\n\t\t]);\n\n\t\t// Each file server behind a CDN: its certificate, its origin access\n\t\t// control, its response headers policies and its distribution. Neither\n\t\t// ACM nor CloudFront scopes creating these to a name, so they are on\n\t\t// every resource of the account; nothing here deletes.\n\t\tconst served = Object.values(manifest).some(\n\t\t\t(d) => d.kind === 'file-server',\n\t\t);\n\t\tif (served && (objects.config as { cdn?: boolean }).cdn !== false) {\n\t\t\tdescribe.push(\n\t\t\t\t'create the file servers’ certificates and CloudFront distributions (ACM, CloudFront)',\n\t\t\t);\n\t\t\tbuild.push(() => [\n\t\t\t\t{\n\t\t\t\t\tSid: 'StageFileServerCertificates',\n\t\t\t\t\tEffect: 'Allow',\n\t\t\t\t\tAction: [\n\t\t\t\t\t\t'acm:RequestCertificate',\n\t\t\t\t\t\t'acm:DescribeCertificate',\n\t\t\t\t\t\t'acm:ListCertificates',\n\t\t\t\t\t\t'acm:AddTagsToCertificate',\n\t\t\t\t\t],\n\t\t\t\t\tResource: '*',\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tSid: 'StageFileServerCdn',\n\t\t\t\t\tEffect: 'Allow',\n\t\t\t\t\tAction: [\n\t\t\t\t\t\t'cloudfront:CreateDistribution',\n\t\t\t\t\t\t'cloudfront:CreateDistributionWithTags',\n\t\t\t\t\t\t'cloudfront:GetDistribution',\n\t\t\t\t\t\t'cloudfront:GetDistributionConfig',\n\t\t\t\t\t\t'cloudfront:UpdateDistribution',\n\t\t\t\t\t\t'cloudfront:ListDistributions',\n\t\t\t\t\t\t'cloudfront:TagResource',\n\t\t\t\t\t\t'cloudfront:CreateOriginAccessControl',\n\t\t\t\t\t\t'cloudfront:GetOriginAccessControl',\n\t\t\t\t\t\t'cloudfront:ListOriginAccessControls',\n\t\t\t\t\t\t'cloudfront:CreateResponseHeadersPolicy',\n\t\t\t\t\t\t'cloudfront:GetResponseHeadersPolicy',\n\t\t\t\t\t\t'cloudfront:GetResponseHeadersPolicyConfig',\n\t\t\t\t\t\t'cloudfront:UpdateResponseHeadersPolicy',\n\t\t\t\t\t\t'cloudfront:ListResponseHeadersPolicies',\n\t\t\t\t\t],\n\t\t\t\t\tResource: '*',\n\t\t\t\t},\n\t\t\t]);\n\t\t}\n\t}\n\n\t// The deploy creates each mail construct's sender when an ses provider\n\t// sends its mail: the identity, verified by DKIM — SES scopes none of\n\t// these to a name — and each construct's IAM user and key, by name.\n\tconst emails = Object.entries(manifest)\n\t\t.filter(([, d]) => d.kind === 'email')\n\t\t.map(([id]) => id)\n\t\t.sort();\n\tconst email = stageProvider(workspace, 'email', stage);\n\tif (email.mode === 'provider' && email.name === 'ses' && emails.length) {\n\t\tconst { scope } = deployIdentity(workspace, stage);\n\t\tconst users = emails.map((id) => emailUserName(scope, stage, id));\n\t\tdescribe.push(\n\t\t\t`verify the sending domain in SES and create the mail users ${users.join(', ')} and their keys (SES, IAM)`,\n\t\t);\n\t\tbuild.push((account) => [\n\t\t\t{\n\t\t\t\tSid: 'StageMailIdentity',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t'ses:GetIdentityDkimAttributes',\n\t\t\t\t\t'ses:VerifyDomainDkim',\n\t\t\t\t\t'ses:SetIdentityDkimEnabled',\n\t\t\t\t\t'ses:GetSendQuota',\n\t\t\t\t],\n\t\t\t\tResource: '*',\n\t\t\t},\n\t\t\t{\n\t\t\t\tSid: 'StageMailUsers',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t'iam:GetUser',\n\t\t\t\t\t'iam:CreateUser',\n\t\t\t\t\t'iam:TagUser',\n\t\t\t\t\t'iam:ListUserTags',\n\t\t\t\t\t'iam:GetUserPolicy',\n\t\t\t\t\t'iam:PutUserPolicy',\n\t\t\t\t\t'iam:ListAccessKeys',\n\t\t\t\t\t'iam:CreateAccessKey',\n\t\t\t\t\t'iam:DeleteAccessKey',\n\t\t\t\t],\n\t\t\t\tResource: users.map(\n\t\t\t\t\t(user) => `arn:aws:iam::${account}:user${IAM_USER_PATH}${user}`,\n\t\t\t\t),\n\t\t\t},\n\t\t]);\n\t}\n\n\t// The stage's backups: the deploy creates the project bucket if it is not\n\t// there, keeps its lifecycle, and creates the backups user and its key.\n\t// The role never reads the backups — `gkm backup:list` and `:restore`\n\t// run with a person's own credentials.\n\tif (stageBackups(workspace, manifest, stage).mode === 'on') {\n\t\tconst { scope } = deployIdentity(workspace, stage);\n\t\tconst user = backupsUserName(scope, stage);\n\t\tconst bucketIn = (account: string) => projectBucketName(scope, account);\n\t\tdescribe.push(\n\t\t\t`create the project bucket ${bucketIn('<account>')} and keep its lifecycle, and create the backups user ${user} and its key (S3, IAM)`,\n\t\t);\n\t\tbuild.push((account) => [\n\t\t\t{\n\t\t\t\tSid: 'StageBackupsBucket',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t's3:ListBucket',\n\t\t\t\t\t...new Set([\n\t\t\t\t\t\t...PROJECT_BUCKET_CREATE_ACTIONS,\n\t\t\t\t\t\t...PROJECT_BUCKET_LIFECYCLE_ACTIONS,\n\t\t\t\t\t]),\n\t\t\t\t],\n\t\t\t\tResource: `arn:aws:s3:::${bucketIn(account)}`,\n\t\t\t},\n\t\t\t{\n\t\t\t\tSid: 'StageBackupsUser',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t'iam:GetUser',\n\t\t\t\t\t'iam:CreateUser',\n\t\t\t\t\t'iam:TagUser',\n\t\t\t\t\t'iam:ListUserTags',\n\t\t\t\t\t'iam:GetUserPolicy',\n\t\t\t\t\t'iam:PutUserPolicy',\n\t\t\t\t\t'iam:ListAccessKeys',\n\t\t\t\t\t'iam:CreateAccessKey',\n\t\t\t\t\t'iam:DeleteAccessKey',\n\t\t\t\t],\n\t\t\t\tResource: `arn:aws:iam::${account}:user${IAM_USER_PATH}${user}`,\n\t\t\t},\n\t\t]);\n\t}\n\n\t// The deploy writes the stage's hosts' records: in Route53, only that\n\t// zone's — and, with no hostedZoneId to name it, the zone is looked up\n\t// by name, which IAM cannot scope.\n\tfor (const { domain, config } of stageDnsDomains(\n\t\tstage,\n\t\tworkspace.domains,\n\t\tworkspace.dns,\n\t)) {\n\t\tif (config.provider !== 'route53') continue;\n\t\tconst zoneId = (config as { hostedZoneId?: string }).hostedZoneId?.replace(\n\t\t\t/^\\/?hostedzone\\//,\n\t\t\t'',\n\t\t);\n\t\tdescribe.push(\n\t\t\t`write the A, AAAA and CNAME records of ${domain} (Route53${zoneId ? `, ${zoneId}` : ''})`,\n\t\t);\n\t\tbuild.push(() => [\n\t\t\t{\n\t\t\t\tSid: 'StageDnsRecords',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t'route53:ChangeResourceRecordSets',\n\t\t\t\t\t'route53:ListResourceRecordSets',\n\t\t\t\t],\n\t\t\t\tResource: `arn:aws:route53:::hostedzone/${zoneId ?? '*'}`,\n\t\t\t},\n\t\t\t{\n\t\t\t\tSid: 'StageDnsChanges',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: ['route53:GetChange'],\n\t\t\t\tResource: 'arn:aws:route53:::change/*',\n\t\t\t},\n\t\t\t...(zoneId\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSid: 'StageDnsZones',\n\t\t\t\t\t\t\tEffect: 'Allow' as const,\n\t\t\t\t\t\t\tAction: ['route53:ListHostedZonesByName'],\n\t\t\t\t\t\t\tResource: '*',\n\t\t\t\t\t\t},\n\t\t\t\t\t]),\n\t\t]);\n\t}\n\n\treturn {\n\t\tkind: 'scoped',\n\t\tstatements: (account) => build.flatMap((statements) => statements(account)),\n\t\tdescribe,\n\t};\n}\n\n/**\n * Reading and writing one stage's deploy state in `bucket`, as the deploy\n * role is given it.\n */\nexport function stateBucketStatements(\n\tbucket: string,\n\tpath: string,\n): PolicyStatement[] {\n\treturn [\n\t\t{\n\t\t\tSid: 'StageState',\n\t\t\tEffect: 'Allow',\n\t\t\tAction: ['s3:GetObject', 's3:PutObject', 's3:DeleteObject'],\n\t\t\tResource: `arn:aws:s3:::${bucket}/${path}*`,\n\t\t},\n\t\t// HeadBucket, and a state not written yet a 404 rather than a 403.\n\t\t{\n\t\t\tSid: 'StageStateBucket',\n\t\t\tEffect: 'Allow',\n\t\t\tAction: ['s3:ListBucket'],\n\t\t\tResource: `arn:aws:s3:::${bucket}`,\n\t\t},\n\t];\n}\n\n/** The scoped access as a policy document, or null when it allows nothing. */\nexport function scopedPolicyDocument(\n\tstatements: PolicyStatement[],\n): string | null {\n\tif (statements.length === 0) return null;\n\treturn JSON.stringify({ Version: '2012-10-17', Statement: statements });\n}\n\n/** The account an IAM ARN is in: `arn:aws:iam::<account>:…`. */\nexport function accountOf(arn: string): string {\n\treturn arn.split(':')[4] ?? '';\n}\n","/**\n * `gkm deploy:github` — let GitHub Actions deploy one stage, with no keys.\n *\n * A stage usually lives in its own AWS account — staging in one, production in\n * another — so this runs once per stage, with that account's profile:\n *\n * gkm deploy:github --stage staging --profile acme-dev\n * gkm deploy:github --stage prod --profile acme-prod\n *\n * In the stage's account it makes sure GitHub's OIDC provider exists, and a\n * role that only this repository's `<stage>` environment can assume. On\n * GitHub it creates that environment and gives it what the generated deploy\n * workflow reads: `AWS_ROLE_ARN`, and — when the stage's secrets are kept in\n * the local file — its key as `GKM_SECRETS_KEY`. With `secrets.store` set to\n * S3, SSM or Secrets Manager the deploy job reads them with the role instead, so\n * no key is handed to GitHub, and this checks the stage's store in the same\n * account, with the same profile. Re-running it converges rather than duplicating.\n *\n * The role trusts the exact `sub` GitHub sends for the environment, read from\n * the repository's OIDC subject settings (`githubOidc.ts`) — the default, the\n * immutable subject with the owner's and repository's ids, or a custom\n * template. A re-run rewrites an existing role's trust to it, so running this\n * again repairs a role that trusted the wrong format. What the role may do is\n * `githubPolicy.ts`: `AdministratorAccess` for SST, and for a compose stage\n * only its own secrets (and deploy state, when that is in AWS).\n */\n\nimport { execFileSync } from 'node:child_process';\nimport {\n\tAttachRolePolicyCommand,\n\tCreateOpenIDConnectProviderCommand,\n\tCreateRoleCommand,\n\tDeleteRolePolicyCommand,\n\tDetachRolePolicyCommand,\n\tGetRoleCommand,\n\tIAMClient,\n\ttype IAMClientConfig,\n\tListAttachedRolePoliciesCommand,\n\tListOpenIDConnectProvidersCommand,\n\tListRoleTagsCommand,\n\tPutRolePolicyCommand,\n\tTagRoleCommand,\n\tUntagRoleCommand,\n\tUpdateAssumeRolePolicyCommand,\n} from '@aws-sdk/client-iam';\nimport { loadWorkspaceConfig } from '../config.js';\nimport { GkmError } from '../errors';\nimport { discover } from '../reconcile/discover.js';\nimport { constructGlobs } from '../reconcile/workspace.js';\nimport { getKeyPath, keystoreProject, readKey } from '../secrets/keystore.js';\nimport { isRemoteStore, secretsStoreFor } from '../secrets/store.js';\nimport { assertDeployedStage } from '../workspace/stages.js';\nimport { resolveOidcSubject } from './githubOidc.js';\nimport {\n\taccountOf,\n\tdeployAccess,\n\tSCOPED_POLICY_NAME,\n\tscopedPolicyDocument,\n} from './githubPolicy.js';\n\nexport { DEFAULT_POLICY_ARN, SCOPED_POLICY_NAME } from './githubPolicy.js';\n\nconst logger = console;\n\nconst GITHUB_OIDC_HOST = 'token.actions.githubusercontent.com';\nconst AUDIENCE = 'sts.amazonaws.com';\n\n/**\n * The tag recording which managed policy gkm attached to the role — so a\n * re-run detaches only what gkm put there, never a policy someone else did.\n */\nexport const POLICY_TAG = 'gkm:policy-arn';\n\nexport interface DeployGithubOptions {\n\tstage: string;\n\t/** The AWS profile for the stage's account. */\n\tprofile?: string;\n\t/** `owner/name`; defaults to the repository `gh` sees here. */\n\trepo?: string;\n\t/** The policy the deploy role gets, in place of the default. */\n\tpolicyArn?: string;\n\tdryRun?: boolean;\n}\n\n/** Runs `gh` with the given arguments and optional stdin, returning stdout. */\nexport type Gh = (args: string[], input?: string) => string;\n\n/** The system's `gh`. */\nexport const ghCli: Gh = (args, input) =>\n\texecFileSync('gh', args, {\n\t\tencoding: 'utf-8',\n\t\t// stderr captured, so a read that fails (a 404) is not printed as noise.\n\t\tstdio: ['pipe', 'pipe', 'pipe'],\n\t\t...(input === undefined ? {} : { input }),\n\t}).trim();\n\n/** The role a stage deploys as: `<project>-github-<stage>`, within IAM's 64. */\nexport function roleName(project: string, stage: string): string {\n\treturn `${project}-github-${stage}`\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9+=,.@_-]/g, '-')\n\t\t.slice(0, 64);\n}\n\n/**\n * Who may assume the role: a workflow job whose OIDC token carries exactly\n * `subject` — the repository's `<stage>` environment, in the format the\n * repository sends (see `githubOidc.ts`), and nothing else. Not another\n * branch's job, not another environment's: that is what keeps a staging\n * deploy from using the production role.\n */\nexport function trustPolicy(providerArn: string, subject: string): string {\n\treturn JSON.stringify({\n\t\tVersion: '2012-10-17',\n\t\tStatement: [\n\t\t\t{\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tPrincipal: { Federated: providerArn },\n\t\t\t\tAction: 'sts:AssumeRoleWithWebIdentity',\n\t\t\t\tCondition: {\n\t\t\t\t\tStringEquals: {\n\t\t\t\t\t\t[`${GITHUB_OIDC_HOST}:aud`]: AUDIENCE,\n\t\t\t\t\t\t[`${GITHUB_OIDC_HOST}:sub`]: subject,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t});\n}\n\n/**\n * The subject a trust policy trusts, or undefined when it names none. IAM\n * hands documents back URL-encoded.\n */\nexport function trustedSubject(\n\tdocument: string | undefined,\n): string | undefined {\n\tif (!document) return undefined;\n\tlet parsed: {\n\t\tStatement?: { Condition?: Record<string, Record<string, unknown>> }[];\n\t};\n\ttry {\n\t\tparsed = JSON.parse(safeDecode(document));\n\t} catch {\n\t\treturn undefined;\n\t}\n\tfor (const statement of parsed.Statement ?? []) {\n\t\tfor (const operator of Object.values(statement.Condition ?? {})) {\n\t\t\tconst value = operator[`${GITHUB_OIDC_HOST}:sub`];\n\t\t\tif (typeof value === 'string') return value;\n\t\t\tif (Array.isArray(value)) return value.join(', ');\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction safeDecode(value: string): string {\n\ttry {\n\t\treturn decodeURIComponent(value);\n\t} catch {\n\t\treturn value;\n\t}\n}\n\n/** GitHub's OIDC provider in this account, created if it is not there. */\nexport async function ensureOidcProvider(iam: IAMClient): Promise<string> {\n\tconst { OpenIDConnectProviderList = [] } = await iam.send(\n\t\tnew ListOpenIDConnectProvidersCommand({}),\n\t);\n\tconst existing = OpenIDConnectProviderList.find((p) =>\n\t\tp.Arn?.endsWith(`oidc-provider/${GITHUB_OIDC_HOST}`),\n\t)?.Arn;\n\tif (existing) return existing;\n\n\tconst created = await iam.send(\n\t\tnew CreateOpenIDConnectProviderCommand({\n\t\t\tUrl: `https://${GITHUB_OIDC_HOST}`,\n\t\t\tClientIDList: [AUDIENCE],\n\t\t}),\n\t);\n\treturn created.OpenIDConnectProviderArn!;\n}\n\n/**\n * What the role is given: a managed policy, attached; or an inline policy\n * document — null for none at all.\n */\nexport type RoleAccess = { managed: string } | { inline: string | null };\n\n/** What {@link ensureRole} did. */\nexport interface RoleOutcome {\n\tarn: string;\n\tcreated: boolean;\n\t/** The subject the role trusted before, when it existed. */\n\tpreviousSubject?: string;\n\t/** Managed policies gkm had attached and detached now. */\n\tdetached: string[];\n\t/**\n\t * Managed policies still attached that the role no longer needs, which gkm\n\t * did not record attaching — left alone, for a person to detach.\n\t */\n\tleftAttached: string[];\n}\n\nfunction isNoSuchEntity(error: unknown): boolean {\n\treturn (error as { name?: string }).name === 'NoSuchEntityException';\n}\n\n/**\n * The deploy role, created or brought back to this trust and access.\n *\n * Converges: re-running rewrites the trust, and moves the role from one access\n * to another — detaching a managed policy only when the role's\n * {@link POLICY_TAG} says gkm attached it.\n */\nexport async function ensureRole(\n\tiam: IAMClient,\n\tname: string,\n\ttrust: string,\n\taccess: RoleAccess,\n): Promise<RoleOutcome> {\n\tlet arn: string;\n\tlet created = false;\n\tlet previousSubject: string | undefined;\n\tlet recorded: string | undefined;\n\ttry {\n\t\tconst { Role } = await iam.send(new GetRoleCommand({ RoleName: name }));\n\t\tpreviousSubject = trustedSubject(Role!.AssumeRolePolicyDocument);\n\t\tawait iam.send(\n\t\t\tnew UpdateAssumeRolePolicyCommand({\n\t\t\t\tRoleName: name,\n\t\t\t\tPolicyDocument: trust,\n\t\t\t}),\n\t\t);\n\t\tarn = Role!.Arn!;\n\t\tconst { Tags = [] } = await iam.send(\n\t\t\tnew ListRoleTagsCommand({ RoleName: name }),\n\t\t);\n\t\trecorded = Tags.find((tag) => tag.Key === POLICY_TAG)?.Value;\n\t} catch (error) {\n\t\tif (!isNoSuchEntity(error)) throw error;\n\t\tconst { Role } = await iam.send(\n\t\t\tnew CreateRoleCommand({\n\t\t\t\tRoleName: name,\n\t\t\t\tAssumeRolePolicyDocument: trust,\n\t\t\t\tDescription: 'Deploys from GitHub Actions (gkm deploy:github)',\n\t\t\t\t// SST deploys can run long; the default hour is tight.\n\t\t\t\tMaxSessionDuration: 3600 * 2,\n\t\t\t}),\n\t\t);\n\t\tarn = Role!.Arn!;\n\t\tcreated = true;\n\t}\n\n\tconst detached: string[] = [];\n\tconst leftAttached: string[] = [];\n\tconst detach = async (policyArn: string) => {\n\t\ttry {\n\t\t\tawait iam.send(\n\t\t\t\tnew DetachRolePolicyCommand({ RoleName: name, PolicyArn: policyArn }),\n\t\t\t);\n\t\t\tdetached.push(policyArn);\n\t\t} catch (error) {\n\t\t\t// Already gone — by hand, or a run that stopped halfway.\n\t\t\tif (!isNoSuchEntity(error)) throw error;\n\t\t}\n\t};\n\tconst deleteInline = async () => {\n\t\ttry {\n\t\t\tawait iam.send(\n\t\t\t\tnew DeleteRolePolicyCommand({\n\t\t\t\t\tRoleName: name,\n\t\t\t\t\tPolicyName: SCOPED_POLICY_NAME,\n\t\t\t\t}),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (!isNoSuchEntity(error)) throw error;\n\t\t}\n\t};\n\n\tif ('managed' in access) {\n\t\t// Attaching an attached policy is a no-op, so this converges too.\n\t\tawait iam.send(\n\t\t\tnew AttachRolePolicyCommand({\n\t\t\t\tRoleName: name,\n\t\t\t\tPolicyArn: access.managed,\n\t\t\t}),\n\t\t);\n\t\tif (recorded && recorded !== access.managed) await detach(recorded);\n\t\tif (recorded !== access.managed) {\n\t\t\tawait iam.send(\n\t\t\t\tnew TagRoleCommand({\n\t\t\t\t\tRoleName: name,\n\t\t\t\t\tTags: [{ Key: POLICY_TAG, Value: access.managed }],\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tif (!created) await deleteInline();\n\t\treturn { arn, created, previousSubject, detached, leftAttached };\n\t}\n\n\tif (access.inline) {\n\t\tawait iam.send(\n\t\t\tnew PutRolePolicyCommand({\n\t\t\t\tRoleName: name,\n\t\t\t\tPolicyName: SCOPED_POLICY_NAME,\n\t\t\t\tPolicyDocument: access.inline,\n\t\t\t}),\n\t\t);\n\t} else if (!created) {\n\t\tawait deleteInline();\n\t}\n\tif (created) return { arn, created, previousSubject, detached, leftAttached };\n\n\tif (recorded) {\n\t\tawait detach(recorded);\n\t\tawait iam.send(\n\t\t\tnew UntagRoleCommand({ RoleName: name, TagKeys: [POLICY_TAG] }),\n\t\t);\n\t}\n\t// A role from before gkm recorded what it attached: what is attached may\n\t// be gkm's or someone's own, so it is named, not detached.\n\tconst { AttachedPolicies = [] } = await iam.send(\n\t\tnew ListAttachedRolePoliciesCommand({ RoleName: name }),\n\t);\n\tfor (const policy of AttachedPolicies) {\n\t\tif (policy.PolicyArn && !detached.includes(policy.PolicyArn)) {\n\t\t\tleftAttached.push(policy.PolicyArn);\n\t\t}\n\t}\n\treturn { arn, created, previousSubject, detached, leftAttached };\n}\n\n/**\n * An IAM client for the stage's account.\n *\n * `fromIni` for a named profile, deliberately: it resolves exactly that\n * profile — keys, assume-role, `credential_process` or SSO, whichever\n * ~/.aws/config says — and never falls back to AWS_* in the environment. The\n * provider chain checks the environment first, so exported staging keys would\n * quietly win over `--profile prod` and the production role would land in the\n * staging account.\n */\nexport async function iamFor(\n\tprofile?: string,\n\tendpoint?: string,\n): Promise<IAMClient> {\n\tconst config: IAMClientConfig = { region: 'us-east-1' };\n\tif (profile) {\n\t\tconst { fromIni } = await import('@aws-sdk/credential-providers');\n\t\tconfig.credentials = fromIni({ profile });\n\t}\n\tif (endpoint) {\n\t\tconfig.endpoint = endpoint;\n\t\tconfig.credentials = { accessKeyId: 'test', secretAccessKey: 'test' };\n\t}\n\treturn new IAMClient(config);\n}\n\nexport async function deployGithubCommand(\n\toptions: DeployGithubOptions,\n\tdeps: { iam?: IAMClient; gh?: Gh; cwd?: string } = {},\n): Promise<{ roleArn?: string; repo: string; subject: string }> {\n\tconst gh = deps.gh ?? ghCli;\n\tconst { workspace } = await loadWorkspaceConfig(deps.cwd);\n\tassertDeployedStage(workspace.stages, options.stage);\n\n\tconst repo =\n\t\toptions.repo ??\n\t\tgh(['repo', 'view', '--json', 'nameWithOwner', '-q', '.nameWithOwner']);\n\tconst role = roleName(workspace.name, options.stage);\n\t// The exact subject GitHub will send — read from the repository's OIDC\n\t// settings, before anything is changed, so a format no role can trust\n\t// fails here.\n\tconst oidc = resolveOidcSubject(gh, repo, options.stage);\n\t// The buckets an s3 provider creates are named after their constructs,\n\t// and a stage with a database is backed up: the role is scoped to\n\t// exactly those.\n\tconst manifest = await discover({\n\t\tpatterns: constructGlobs(workspace),\n\t\tcwd: workspace.root,\n\t});\n\tconst access = deployAccess(\n\t\tworkspace,\n\t\toptions.stage,\n\t\toptions.policyArn,\n\t\tmanifest,\n\t);\n\t// Read through the keystore so a key still at the place keys used to be kept\n\t// is found, and copied to where it is kept now.\n\tconst key = await readKey(options.stage, keystoreProject(workspace));\n\tconst keyPath = getKeyPath(options.stage, keystoreProject(workspace));\n\tconst hasKey = key !== null;\n\t// A stage whose secrets are in a store is read from there by the deploy job,\n\t// with the role; it needs no key on GitHub.\n\tconst remote = isRemoteStore(workspace, options.stage);\n\t// Read from the stage's own store, with the same credentials the role is\n\t// created with: what the deploy job will find there.\n\tconst store = await secretsStoreFor(workspace, options.stage, {\n\t\t...(options.profile ? { profile: options.profile } : {}),\n\t});\n\tconst hasSecrets = remote && (await store.read(options.stage)) !== null;\n\tconst via = options.profile\n\t\t? `profile \"${options.profile}\"`\n\t\t: 'the default credentials';\n\n\tlogger.log(`\\n🔐 GitHub → AWS for stage \"${options.stage}\"\\n`);\n\tlogger.log(` Repository: ${repo}`);\n\tlogger.log(` AWS profile: ${options.profile ?? '(default credentials)'}`);\n\tlogger.log(` Role: ${role}`);\n\tif (access.kind === 'managed') {\n\t\tlogger.log(` Policy: ${access.policyArn} (${access.reason})`);\n\t} else if (access.describe.length > 0) {\n\t\tlogger.log(\n\t\t\t` Policy: inline \"${SCOPED_POLICY_NAME}\", scoped to the compose deploy — only:`,\n\t\t);\n\t\tfor (const line of access.describe) logger.log(` ${line}`);\n\t} else {\n\t\tlogger.log(\n\t\t\t' Policy: none — a compose deploy with file secrets and local state reads nothing from AWS',\n\t\t);\n\t}\n\tlogger.log(\n\t\t` Trusted by: ${oidc.subject} only (${SUBJECT_KINDS[oidc.kind]})`,\n\t);\n\tif (oidc.warning) logger.log(` ⚠ ${oidc.warning}`);\n\tif (remote) {\n\t\tlogger.log(\n\t\t\t` Secrets: ${hasSecrets ? `in the store (${store.name}), read with ${via}` : `none in the store yet — gkm secrets:set <KEY> '…' --stage ${options.stage}`}`,\n\t\t);\n\t} else {\n\t\tlogger.log(\n\t\t\t` Secrets key: ${hasKey ? keyPath : `none at ${keyPath} — run gkm secrets:init --stage ${options.stage} first`}`,\n\t\t);\n\t}\n\n\tif (options.dryRun) {\n\t\tif (access.kind === 'scoped') {\n\t\t\tconst document = scopedPolicyDocument(access.statements('<account>'));\n\t\t\tif (document) {\n\t\t\t\tlogger.log(\n\t\t\t\t\t`\\n Inline policy:\\n${JSON.stringify(JSON.parse(document), null, 2).replace(/^/gm, ' ')}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tlogger.log('\\n --dry-run: nothing changed.\\n');\n\t\treturn { repo, subject: oidc.subject };\n\t}\n\n\tconst iam = deps.iam ?? (await iamFor(options.profile));\n\tconst providerArn = await ensureOidcProvider(iam).catch((error) => {\n\t\t// The first AWS call is where an expired SSO login surfaces; the SDK's\n\t\t// message does not say which profile, and this command knows.\n\t\tif (/SSO session/i.test(String(error?.message)) && options.profile) {\n\t\t\tthrow new SsoSessionExpired(options.profile);\n\t\t}\n\t\tthrow error;\n\t});\n\tconst outcome = await ensureRole(\n\t\tiam,\n\t\trole,\n\t\ttrustPolicy(providerArn, oidc.subject),\n\t\taccess.kind === 'managed'\n\t\t\t? { managed: access.policyArn }\n\t\t\t: {\n\t\t\t\t\tinline: scopedPolicyDocument(\n\t\t\t\t\t\taccess.statements(accountOf(providerArn)),\n\t\t\t\t\t),\n\t\t\t\t},\n\t);\n\tconst roleArn = outcome.arn;\n\tlogger.log(`\\n ✓ AWS: ${roleArn}${outcome.created ? ' (created)' : ''}`);\n\tif (!outcome.created) {\n\t\tlogger.log(\n\t\t\toutcome.previousSubject === oidc.subject\n\t\t\t\t? ` ✓ Trust: unchanged, ${oidc.subject}`\n\t\t\t\t: ` ✓ Trust: ${outcome.previousSubject ?? '(no subject)'} → ${oidc.subject}`,\n\t\t);\n\t}\n\tfor (const detached of outcome.detached) {\n\t\tlogger.log(` ✓ Detached ${detached} (attached by gkm, no longer needed)`);\n\t}\n\tif (access.kind === 'scoped') {\n\t\tfor (const attached of outcome.leftAttached) {\n\t\t\tlogger.log(\n\t\t\t\t` ⚠ ${attached} is still attached to ${role}. gkm has no record of attaching it, so it is left; the compose deploy does not need it. Detach it with: aws iam detach-role-policy --role-name ${role} --policy-arn ${attached}${options.profile ? ` --profile ${options.profile}` : ''}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// The environment the generated deploy workflow runs the stage in.\n\tgh(['api', '--method', 'PUT', `repos/${repo}/environments/${options.stage}`]);\n\tgh([\n\t\t'variable',\n\t\t'set',\n\t\t'AWS_ROLE_ARN',\n\t\t'--env',\n\t\toptions.stage,\n\t\t'--repo',\n\t\trepo,\n\t\t'--body',\n\t\troleArn,\n\t]);\n\tlogger.log(` ✓ GitHub: environment \"${options.stage}\", AWS_ROLE_ARN`);\n\n\tif (remote) {\n\t\t// Nothing to send: the deploy job reads the stage's store itself.\n\t\tif (!hasSecrets) {\n\t\t\tlogger.log(\n\t\t\t\t` ⚠ The \"${options.stage}\" store holds no secrets yet; set them with gkm secrets:set <KEY> '…' --stage ${options.stage}${options.profile ? ` (AWS_PROFILE=${options.profile})` : ''}.`,\n\t\t\t);\n\t\t}\n\t} else if (hasKey) {\n\t\t// Through stdin, so the key is never an argument a process list shows.\n\t\tgh(\n\t\t\t[\n\t\t\t\t'secret',\n\t\t\t\t'set',\n\t\t\t\t'GKM_SECRETS_KEY',\n\t\t\t\t'--env',\n\t\t\t\toptions.stage,\n\t\t\t\t'--repo',\n\t\t\t\trepo,\n\t\t\t],\n\t\t\tkey!,\n\t\t);\n\t\tlogger.log(' ✓ GitHub: GKM_SECRETS_KEY');\n\t} else {\n\t\tlogger.log(\n\t\t\t` ⚠ No secrets key for \"${options.stage}\"; run gkm secrets:init --stage ${options.stage}, then this again.`,\n\t\t);\n\t}\n\n\tlogger.log(\n\t\t`\\n Protect it: add required reviewers to the \"${options.stage}\" environment in the repository settings.\\n`,\n\t);\n\treturn { roleArn, repo, subject: oidc.subject };\n}\n\nconst SUBJECT_KINDS = {\n\tdefault: \"the repository's default subject\",\n\timmutable: \"the repository's immutable subject\",\n\tcustom: \"the repository's custom subject template\",\n\tassumed: 'assumed: the default format',\n} as const;\n\n/** The profile's SSO login has lapsed; the fix is one command away. */\nexport class SsoSessionExpired extends GkmError {\n\tconstructor(readonly profile: string) {\n\t\tsuper(\n\t\t\t`The SSO session for profile \"${profile}\" has expired or is invalid. Run: aws sso login --profile ${profile}`,\n\t\t);\n\t\tthis.name = 'SsoSessionExpired';\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAa,uBAAuB;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AAEA,MAAM,8BAAc,IAAI,IAAI;CAC3B;CACA;CACA;AACD,CAAC;;AAGD,SAAS,MAAM,OAAuB;CACrC,OAAO,MAAM,WAAW,KAAK,KAAK;AAC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S,UACnB,KAAK,MAAM,YAAY,QAAQ,cAC9B,OAAO,IACN,OAAO,SAAS,wBAAwB,KAAK,kJAAkJ,KAAK,gBAAgB,WAAW,QAAQ,UAAU,cAAc,QAAQ,YAAY,IACpR;CAKF,GAAG;EAAC;EAAO;EAAY;EAAO,SAAS,KAAK,gBAAgB,QAAQ;CAAO,CAAC;CAC5E,GAAG;EACF;EACA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA;EACA;CACD,CAAC;CACD,OAAO,IAAI,4BAA4B,QAAQ,MAAM,gBAAgB;CAErE,IAAI,QAEC;MAAA,CAAC,YACJ,OAAO,IACN,YAAY,QAAQ,MAAM,gFAAgF,QAAQ,QAAQ,QAAQ,UAAU,iBAAiB,QAAQ,QAAQ,KAAK,GAAG,EACtL;CAAA,OAEK,IAAI,QAAQ;EAElB,GACC;GACC;GACA;GACA;GACA;GACA,QAAQ;GACR;GACA;EACD,GACA,GACD;EACA,OAAO,IAAI,6BAA6B;CACzC,OACC,OAAO,IACN,2BAA2B,QAAQ,MAAM,kCAAkC,QAAQ,MAAM,mBAC1F;CAGD,OAAO,IACN,kDAAkD,QAAQ,MAAM,4CACjE;CACA,OAAO;EAAE;EAAS;EAAM,SAAS,KAAK;CAAQ;AAC/C;AAEA,MAAM,gBAAgB;CACrB,SAAS;CACT,WAAW;CACX,QAAQ;CACR,SAAS;AACV;;AAGA,IAAa,oBAAb,cAAuCC,eAAAA,SAAS;CAC1B;CAArB,YAAY,SAA0B;EACrC,MACC,gCAAgC,QAAQ,4DAA4D,SACrG;EAHoB,KAAA,UAAA;EAIpB,KAAK,OAAO;CACb;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"github-D2l7aqFx.mjs","names":[],"sources":["../src/deploy/githubOidc.ts","../src/deploy/githubPolicy.ts","../src/deploy/github.ts"],"sourcesContent":["/**\n * The `sub` GitHub puts in a deploy job's OIDC token — what the deploy role's\n * trust policy has to match exactly.\n *\n * It is not always `repo:<owner>/<name>:environment:<stage>`. A repository\n * (or its organisation) decides the format, and says which through\n * `GET /repos/{owner}/{repo}/actions/oidc/customization/sub`:\n *\n * - the default: `repo:<owner>/<name>:environment:<stage>`;\n * - the immutable subject — the default for repositories created after\n * 15 July 2026, opt-in before — puts the owner's and the repository's ids in\n * the `repo` segment: `repo:<owner>@<ownerId>/<name>@<repoId>:environment:<stage>`.\n * The API hands that segment back as `sub_claim_prefix`;\n * - a custom template (`use_default: false`) builds the `sub` from\n * `include_claim_keys`, in order, each as `<key>:<value>` joined by `:`,\n * where `context` is `environment:<stage>` in an environment job.\n *\n * A `:` inside a value is sent as `%3A`.\n *\n * See https://docs.github.com/en/actions/reference/security/oidc.\n */\n\nimport { GkmError } from '../errors';\nimport type { Gh } from './github.js';\n\n/** `GET /repos/{owner}/{repo}/actions/oidc/customization/sub`. */\nexport interface OidcSubjectCustomization {\n\tuse_default: boolean;\n\tinclude_claim_keys?: string[];\n\tuse_immutable_subject?: boolean;\n\t/** The `repo` segment of the subject, as GitHub will send it. */\n\tsub_claim_prefix?: string;\n}\n\n/** What `GET /repos/{owner}/{repo}` says that a subject may include. */\nexport interface RepoFacts {\n\townerId: number;\n\trepoId: number;\n\tvisibility: string;\n}\n\n/**\n * Template keys whose values are known for a repository's environment job\n * before the job runs. Anything else — `job_workflow_ref`, `ref`, `sha`,\n * `run_id`, `workflow`, `actor`, a custom property — depends on the run.\n */\nexport const SUPPORTED_CLAIM_KEYS = [\n\t'repo',\n\t'context',\n\t'environment',\n\t'repository',\n\t'repository_owner',\n\t'repository_owner_id',\n\t'repository_id',\n\t'repository_visibility',\n] as const;\n\nconst NEEDS_FACTS = new Set([\n\t'repository_owner_id',\n\t'repository_id',\n\t'repository_visibility',\n]);\n\n/** A `:` inside a claim value is sent as `%3A`. */\nfunction claim(value: string): string {\n\treturn value.replaceAll(':', '%3A');\n}\n\n/** Which kind of subject the repository uses, for the output. */\nexport type OidcSubjectKind = 'default' | 'immutable' | 'custom' | 'assumed';\n\n/** Whether {@link oidcSubject} needs the repository's ids or visibility. */\nexport function needsRepoFacts(\n\tcustomization: OidcSubjectCustomization,\n): boolean {\n\tconst immutableWithoutPrefix =\n\t\tcustomization.use_immutable_subject === true &&\n\t\t!customization.sub_claim_prefix;\n\tif (customization.use_default) return immutableWithoutPrefix;\n\n\tconst keys = customization.include_claim_keys ?? [];\n\treturn keys.some(\n\t\t(key) => NEEDS_FACTS.has(key) || (key === 'repo' && immutableWithoutPrefix),\n\t);\n}\n\n/**\n * The exact `sub` of a job in `repo`'s `stage` environment.\n *\n * @throws OidcSubjectNotSupported when a custom template includes a claim\n * whose value depends on the run, so no one subject can be trusted.\n */\nexport function oidcSubject(\n\trepo: string,\n\tstage: string,\n\tcustomization: OidcSubjectCustomization,\n\tfacts?: RepoFacts,\n): { subject: string; kind: OidcSubjectKind } {\n\tconst [owner = '', name = ''] = repo.split('/');\n\tconst environment = `environment:${claim(stage)}`;\n\n\tconst repoSegment = (): string => {\n\t\tif (customization.sub_claim_prefix) return customization.sub_claim_prefix;\n\t\tif (customization.use_immutable_subject) {\n\t\t\tif (!facts) throw new RepoFactsRequired(repo);\n\t\t\treturn `repo:${owner}@${facts.ownerId}/${name}@${facts.repoId}`;\n\t\t}\n\t\treturn `repo:${repo}`;\n\t};\n\tconst immutable =\n\t\tcustomization.use_immutable_subject === true ||\n\t\tcustomization.sub_claim_prefix !== undefined;\n\n\tif (customization.use_default) {\n\t\treturn {\n\t\t\tsubject: `${repoSegment()}:${environment}`,\n\t\t\tkind: immutable ? 'immutable' : 'default',\n\t\t};\n\t}\n\n\tconst keys = customization.include_claim_keys ?? [];\n\tconst unsupported = keys.filter(\n\t\t(key) => !(SUPPORTED_CLAIM_KEYS as readonly string[]).includes(key),\n\t);\n\tif (keys.length === 0 || unsupported.length > 0) {\n\t\tthrow new OidcSubjectNotSupported(repo, keys, unsupported);\n\t}\n\tif (keys.some((key) => NEEDS_FACTS.has(key)) && !facts) {\n\t\tthrow new RepoFactsRequired(repo);\n\t}\n\n\tconst parts = keys.map((key) => {\n\t\tswitch (key) {\n\t\t\tcase 'repo':\n\t\t\t\treturn repoSegment();\n\t\t\tcase 'context':\n\t\t\tcase 'environment':\n\t\t\t\treturn environment;\n\t\t\tcase 'repository':\n\t\t\t\treturn `repository:${claim(repo)}`;\n\t\t\tcase 'repository_owner':\n\t\t\t\treturn `repository_owner:${claim(owner)}`;\n\t\t\tcase 'repository_owner_id':\n\t\t\t\treturn `repository_owner_id:${facts!.ownerId}`;\n\t\t\tcase 'repository_id':\n\t\t\t\treturn `repository_id:${facts!.repoId}`;\n\t\t\tdefault:\n\t\t\t\treturn `repository_visibility:${claim(facts!.visibility)}`;\n\t\t}\n\t});\n\treturn { subject: parts.join(':'), kind: 'custom' };\n}\n\n/** What {@link resolveOidcSubject} found. */\nexport interface ResolvedOidcSubject {\n\tsubject: string;\n\tkind: OidcSubjectKind;\n\t/** Set when the format could not be read and the default was assumed. */\n\twarning?: string;\n}\n\n/** The endpoint a repository's subject format is read from. */\nexport function customizationEndpoint(repo: string): string {\n\treturn `repos/${repo}/actions/oidc/customization/sub`;\n}\n\n/**\n * The `sub` GitHub will send for `repo`'s `stage` environment, read from the\n * repository's OIDC settings through `gh`.\n *\n * A repository on a custom template that names no keys of its own uses its\n * organisation's, read from `orgs/{owner}/actions/oidc/customization/sub`.\n * When the settings cannot be read at all — no permission, or a GitHub\n * Enterprise Server without the endpoint — the default format is assumed, with\n * a warning saying where to check it.\n */\nexport function resolveOidcSubject(\n\tgh: Gh,\n\trepo: string,\n\tstage: string,\n): ResolvedOidcSubject {\n\tconst endpoint = customizationEndpoint(repo);\n\tlet customization: OidcSubjectCustomization;\n\ttry {\n\t\tcustomization = JSON.parse(gh(['api', endpoint]));\n\t} catch {\n\t\treturn {\n\t\t\tsubject: `repo:${repo}:environment:${claim(stage)}`,\n\t\t\tkind: 'assumed',\n\t\t\twarning: `Could not read ${endpoint}, so the default subject format is assumed. Check it with: gh api ${endpoint} — a repository on the immutable subject or a custom template sends a different sub, and the role would not be assumable.`,\n\t\t};\n\t}\n\n\tif (\n\t\t!customization.use_default &&\n\t\t(customization.include_claim_keys ?? []).length === 0\n\t) {\n\t\t// The repository follows its organisation's template.\n\t\tconst [owner = ''] = repo.split('/');\n\t\tconst orgEndpoint = `orgs/${owner}/actions/oidc/customization/sub`;\n\t\tlet org: { include_claim_keys?: string[]; use_immutable_subject?: boolean };\n\t\ttry {\n\t\t\torg = JSON.parse(gh(['api', orgEndpoint]));\n\t\t} catch {\n\t\t\tthrow new OrgOidcTemplateUnreadable(repo, orgEndpoint);\n\t\t}\n\t\tcustomization = {\n\t\t\t...customization,\n\t\t\tinclude_claim_keys: org.include_claim_keys ?? [],\n\t\t\tuse_immutable_subject:\n\t\t\t\tcustomization.use_immutable_subject ?? org.use_immutable_subject,\n\t\t};\n\t}\n\n\tconst facts = needsRepoFacts(customization)\n\t\t? readRepoFacts(gh, repo)\n\t\t: undefined;\n\treturn oidcSubject(repo, stage, customization, facts);\n}\n\nfunction readRepoFacts(gh: Gh, repo: string): RepoFacts {\n\tconst raw = JSON.parse(gh(['api', `repos/${repo}`])) as {\n\t\tid: number;\n\t\towner: { id: number };\n\t\tvisibility: string;\n\t};\n\treturn {\n\t\townerId: raw.owner.id,\n\t\trepoId: raw.id,\n\t\tvisibility: raw.visibility,\n\t};\n}\n\n/**\n * The repository's custom subject template includes a claim whose value\n * depends on the run — or names none — so no one subject can be trusted.\n */\nexport class OidcSubjectNotSupported extends GkmError {\n\tconstructor(\n\t\treadonly repo: string,\n\t\treadonly includeClaimKeys: string[],\n\t\treadonly unsupportedKeys: string[],\n\t) {\n\t\tsuper(\n\t\t\t`${repo} builds its OIDC subject from a custom template, ${JSON.stringify(includeClaimKeys)}, and ${\n\t\t\t\tunsupportedKeys.length > 0\n\t\t\t\t\t? `${unsupportedKeys.join(', ')} depend${unsupportedKeys.length === 1 ? 's' : ''} on the run`\n\t\t\t\t\t: 'it names no claims'\n\t\t\t}, so the deploy role cannot trust one exact subject. Set the repository back to the default subject — gh api --method PUT ${customizationEndpoint(repo)} -F use_default=true — (or keep the immutable one by also passing -F use_immutable_subject=true), or use a template built only from ${SUPPORTED_CLAIM_KEYS.join(', ')}; then run this again.`,\n\t\t);\n\t\tthis.name = 'OidcSubjectNotSupported';\n\t}\n}\n\n/** The subject needs the repository's ids, and none were read. */\nexport class RepoFactsRequired extends GkmError {\n\tconstructor(readonly repo: string) {\n\t\tsuper(\n\t\t\t`The OIDC subject of ${repo} includes its owner and repository ids; read them with gh api repos/${repo} and pass them in.`,\n\t\t);\n\t\tthis.name = 'RepoFactsRequired';\n\t}\n}\n\n/**\n * The repository uses its organisation's subject template, and that template\n * could not be read — so what GitHub sends is unknown, and is not guessed.\n */\nexport class OrgOidcTemplateUnreadable extends GkmError {\n\tconstructor(\n\t\treadonly repo: string,\n\t\treadonly endpoint: string,\n\t) {\n\t\tsuper(\n\t\t\t`${repo} uses its organisation's OIDC subject template, and ${endpoint} could not be read. Run this as an organisation owner (gh auth refresh -s admin:org), or set the repository back to the default subject with gh api --method PUT ${customizationEndpoint(repo)} -F use_default=true; then run this again.`,\n\t\t);\n\t\tthis.name = 'OrgOidcTemplateUnreadable';\n\t}\n}\n","/**\n * What the deploy role may do in the stage's account.\n *\n * An SST stage creates its own stack, which is most of AWS, so its role gets\n * `AdministratorAccess`. A stage deployed with the `compose` target builds and\n * runs containers on a server; from AWS its deploy job needs only the stage's\n * secrets — read, and written back when a deploy generates a new one: the one\n * object in the project bucket, or the SSM parameter or Secrets Manager secret\n * — and,\n * when the deploy state is kept in AWS, the stage's state, and, when the\n * stage's domain is in Route53, the records of its hosted zone, and, when an\n * `s3` provider backs its buckets, those buckets and the IAM user each is\n * reached with — by the names the provider gives them — and, when it runs\n * Postgres, the project bucket its backups go to and the backups user. So a\n * compose stage gets an inline policy naming exactly those resources and\n * nothing else.\n *\n * `--policy-arn` replaces either.\n */\n\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport { stageBackups } from '../backups/config.js';\nimport { backupsUserName } from '../backups/provision.js';\nimport { stageDnsDomains } from '../compose/dns.js';\nimport { stageProvider } from '../providers/config.js';\nimport {\n\tPROJECT_BUCKET_CREATE_ACTIONS,\n\tPROJECT_BUCKET_LIFECYCLE_ACTIONS,\n\tprojectBucketName,\n} from '../providers/projectBucket.js';\nimport {\n\tbucketName,\n\tIAM_USER_PATH,\n\tiamUserName,\n\tSUFFIX_LENGTH,\n} from '../providers/s3/naming.js';\nimport { emailUserName } from '../providers/ses/config.js';\nimport { secretsParameterName } from '../secrets/aws.js';\nimport { s3SecretsKey, s3SecretsLocation } from '../secrets/providers.js';\nimport { secretsManagerSecretName } from '../secrets/secretsManager.js';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\nimport { deployIdentity } from './identity.js';\n\n/**\n * What SST needs to create a stack is most of AWS, so this is the default\n * outside compose — said out loud in the output, and replaceable with\n * `--policy-arn`.\n */\nexport const DEFAULT_POLICY_ARN = 'arn:aws:iam::aws:policy/AdministratorAccess';\n\n/** The name of the inline policy a compose stage's role is given. */\nexport const SCOPED_POLICY_NAME = 'gkm-deploy';\n\n/** One statement of an IAM policy document. */\nexport interface PolicyStatement {\n\tSid: string;\n\tEffect: 'Allow';\n\tAction: string[];\n\tResource: string | string[];\n\tCondition?: Record<string, Record<string, string>>;\n}\n\n/** What the role is given. */\nexport type DeployAccess =\n\t| {\n\t\t\tkind: 'managed';\n\t\t\tpolicyArn: string;\n\t\t\t/** Why, for the output. */\n\t\t\treason: string;\n\t }\n\t| {\n\t\t\tkind: 'scoped';\n\t\t\t/** The statements, in the account the role is in. */\n\t\t\tstatements(account: string): PolicyStatement[];\n\t\t\t/** What each statement is for, for the output. */\n\t\t\tdescribe: string[];\n\t };\n\n/** Every target the stage's apps deploy through. */\nexport function deployTargets(workspace: NormalizedWorkspace): string[] {\n\tconst targets = new Set<string>([workspace.deploy?.default ?? 'dokploy']);\n\tfor (const app of Object.values(workspace.apps)) {\n\t\ttargets.add(app.resolvedDeployTarget);\n\t}\n\treturn [...targets].sort();\n}\n\n/**\n * The access the stage's deploy role is given: `--policy-arn` when passed,\n * the scoped policy for a stage only the compose target deploys, and\n * `AdministratorAccess` otherwise.\n */\nexport function deployAccess(\n\tworkspace: NormalizedWorkspace,\n\tstage: string,\n\tpolicyArn?: string,\n\t/** The stage's constructs: its buckets, and whether it runs Postgres. */\n\tmanifest: ConstructManifest = {},\n): DeployAccess {\n\tconst buckets = Object.entries(manifest)\n\t\t.filter(([, d]) => d.kind === 'objects')\n\t\t.map(([id]) => id);\n\tif (policyArn) {\n\t\treturn { kind: 'managed', policyArn, reason: '--policy-arn' };\n\t}\n\n\tconst targets = deployTargets(workspace);\n\tif (targets.length !== 1 || targets[0] !== 'compose') {\n\t\treturn {\n\t\t\tkind: 'managed',\n\t\t\tpolicyArn: DEFAULT_POLICY_ARN,\n\t\t\treason: `the ${targets.join(', ')} target${targets.length === 1 ? '' : 's'} deploy${targets.length === 1 ? 's' : ''} infrastructure; --policy-arn to narrow`,\n\t\t};\n\t}\n\n\tconst project = workspace.name;\n\tconst store = workspace.secrets.store ?? 'file';\n\tconst state = workspace.state;\n\tconst custom =\n\t\t(typeof store === 'object' && typeof store.provider === 'object') ||\n\t\t(state !== undefined && typeof state.provider === 'object');\n\tif (custom) {\n\t\treturn {\n\t\t\tkind: 'managed',\n\t\t\tpolicyArn: DEFAULT_POLICY_ARN,\n\t\t\treason: `a custom ${typeof store === 'object' && typeof store.provider === 'object' ? 'secrets store' : 'state provider'} cannot be scoped; --policy-arn to narrow`,\n\t\t};\n\t}\n\n\tconst describe: string[] = [];\n\tconst build: ((account: string) => PolicyStatement[])[] = [];\n\n\t// The project bucket's name is fixed by the account, so the role is given\n\t// exactly it, and the actions that create it for whichever run is first.\n\tconst projectBucketIn = (account: string) =>\n\t\tprojectBucketName(deployIdentity(workspace, stage).scope, account);\n\tconst projectBucketStatement = (account: string): PolicyStatement => ({\n\t\tSid: 'ProjectBucket',\n\t\tEffect: 'Allow',\n\t\tAction: [...PROJECT_BUCKET_CREATE_ACTIONS],\n\t\tResource: `arn:aws:s3:::${projectBucketIn(account)}`,\n\t});\n\t// Whether the state's statements already cover the secrets' bucket.\n\tconst stateInSecretsBucket =\n\t\ttypeof store === 'object' &&\n\t\tstore.provider === 's3' &&\n\t\tstate?.provider === 's3' &&\n\t\tstate.bucket === (store as { bucket?: string }).bucket;\n\n\tif (typeof store === 'object' && store.provider === 's3') {\n\t\tconst location = s3SecretsLocation(store, state);\n\t\tconst key = s3SecretsKey(location.prefix, project, stage);\n\t\tconst named = location.bucket;\n\t\tconst bucketIn = (account: string) => named ?? projectBucketIn(account);\n\t\tdescribe.push(\n\t\t\tnamed\n\t\t\t\t? `read and update s3://${named}/${key}`\n\t\t\t\t: `read and update ${key} in the project bucket ${projectBucketIn('<account>')}${stateInSecretsBucket ? '' : ', creating it'}`,\n\t\t);\n\t\tbuild.push((account) => [\n\t\t\t{\n\t\t\t\tSid: 'StageSecrets',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: ['s3:GetObject', 's3:PutObject'],\n\t\t\t\tResource: `arn:aws:s3:::${bucketIn(account)}/${key}`,\n\t\t\t},\n\t\t\t// The state's statements give these when it is in the same bucket.\n\t\t\t...(stateInSecretsBucket\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// HeadBucket, and secrets not written yet a 404, not a 403.\n\t\t\t\t\t\t\tSid: 'StageSecretsBucket',\n\t\t\t\t\t\t\tEffect: 'Allow' as const,\n\t\t\t\t\t\t\tAction: ['s3:ListBucket'],\n\t\t\t\t\t\t\tResource: `arn:aws:s3:::${bucketIn(account)}`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t...(named ? [] : [projectBucketStatement(account)]),\n\t\t\t\t\t]),\n\t\t]);\n\t} else if (typeof store === 'object' && store.provider === 'ssm') {\n\t\tconst { region } = store;\n\t\tconst name = secretsParameterName(project, stage);\n\t\tdescribe.push(`read and update ${name} (SSM, ${region})`);\n\t\tbuild.push((account) => [\n\t\t\t{\n\t\t\t\tSid: 'StageSecrets',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: ['ssm:GetParameter', 'ssm:PutParameter'],\n\t\t\t\tResource: `arn:aws:ssm:${region}:${account}:parameter${name}`,\n\t\t\t},\n\t\t]);\n\t} else if (\n\t\ttypeof store === 'object' &&\n\t\tstore.provider === 'secrets-manager'\n\t) {\n\t\tconst { region, kmsKeyId } = store as { region: string; kmsKeyId?: string };\n\t\tconst name = secretsManagerSecretName(project, stage);\n\t\tdescribe.push(`read and update ${name} (Secrets Manager, ${region})`);\n\t\tbuild.push((account) => {\n\t\t\tconst statements: PolicyStatement[] = [\n\t\t\t\t{\n\t\t\t\t\tSid: 'StageSecrets',\n\t\t\t\t\tEffect: 'Allow',\n\t\t\t\t\tAction: [\n\t\t\t\t\t\t'secretsmanager:GetSecretValue',\n\t\t\t\t\t\t'secretsmanager:PutSecretValue',\n\t\t\t\t\t\t'secretsmanager:CreateSecret',\n\t\t\t\t\t],\n\t\t\t\t\t// Secrets Manager appends six random characters to a secret's ARN.\n\t\t\t\t\tResource: `arn:aws:secretsmanager:${region}:${account}:secret:${name}-??????`,\n\t\t\t\t},\n\t\t\t];\n\t\t\tif (kmsKeyId) {\n\t\t\t\tstatements.push({\n\t\t\t\t\tSid: 'StageSecretsKey',\n\t\t\t\t\tEffect: 'Allow',\n\t\t\t\t\tAction: ['kms:Decrypt', 'kms:GenerateDataKey'],\n\t\t\t\t\tResource: kmsKeyId.startsWith('arn:') ? kmsKeyId : '*',\n\t\t\t\t\tCondition: {\n\t\t\t\t\t\tStringEquals: {\n\t\t\t\t\t\t\t'kms:ViaService': `secretsmanager.${region}.amazonaws.com`,\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\treturn statements;\n\t\t});\n\t}\n\n\tif (state?.provider === 'ssm') {\n\t\tconst { region } = state;\n\t\tconst path = `/gkm/${project}/${stage}/`;\n\t\tdescribe.push(\n\t\t\t`read and write the deploy state under ${path} (SSM, ${region})`,\n\t\t);\n\t\tbuild.push((account) => [\n\t\t\t{\n\t\t\t\tSid: 'StageState',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: ['ssm:GetParameter', 'ssm:PutParameter', 'ssm:DeleteParameter'],\n\t\t\t\tResource: `arn:aws:ssm:${region}:${account}:parameter${path}*`,\n\t\t\t},\n\t\t]);\n\t} else if (state?.provider === 's3') {\n\t\tconst prefix = (state.prefix ?? 'gkm').replace(/\\/+$/, '');\n\t\tconst path = `${prefix ? `${prefix}/` : ''}${project}/${stage}/`;\n\t\tconst named = state.bucket;\n\t\t// No bucket named: the project bucket, which the first deploy creates.\n\t\tconst bucketIn = (account: string) => named ?? projectBucketIn(account);\n\t\tdescribe.push(\n\t\t\tnamed\n\t\t\t\t? `read and write the deploy state under s3://${named}/${path}`\n\t\t\t\t: `create the project bucket ${projectBucketIn('<account>')}, and read and write the deploy state under ${path} in it`,\n\t\t);\n\t\tbuild.push((account) => [\n\t\t\t...stateBucketStatements(bucketIn(account), path),\n\t\t\t...(named ? [] : [projectBucketStatement(account)]),\n\t\t]);\n\t}\n\n\t// The deploy creates each bucket an s3 provider backs, and the IAM user\n\t// and key it is reached with: by their names — the good one, or the good\n\t// one with a clash's six-character suffix — and nothing else.\n\tconst objects = stageProvider(workspace, 'objects', stage);\n\tif (objects.mode === 'provider' && objects.name === 's3' && buckets.length) {\n\t\tconst { scope } = deployIdentity(workspace, stage);\n\t\tconst names = [...buckets].sort().map((id) => ({\n\t\t\tbucket: bucketName({ scope, stage, id }),\n\t\t\tuser: iamUserName({ scope, stage, id }),\n\t\t}));\n\t\tconst suffix = '?'.repeat(SUFFIX_LENGTH - 1);\n\t\tdescribe.push(\n\t\t\t`create and configure the buckets ${names.map((n) => n.bucket).join(', ')}, their IAM users, and — for a bucket a subscriber watches — its events topic, dead-letter queue and subscriptions (S3, IAM, SNS, SQS)`,\n\t\t);\n\t\tbuild.push((account) => [\n\t\t\t{\n\t\t\t\tSid: 'StageBuckets',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t's3:CreateBucket',\n\t\t\t\t\t's3:ListBucket',\n\t\t\t\t\t's3:GetBucketTagging',\n\t\t\t\t\t's3:PutBucketTagging',\n\t\t\t\t\t's3:GetBucketPublicAccessBlock',\n\t\t\t\t\t's3:PutBucketPublicAccessBlock',\n\t\t\t\t\t's3:GetBucketPolicy',\n\t\t\t\t\t's3:PutBucketPolicy',\n\t\t\t\t\t's3:GetEncryptionConfiguration',\n\t\t\t\t\t's3:PutEncryptionConfiguration',\n\t\t\t\t\t's3:GetBucketVersioning',\n\t\t\t\t\t's3:PutBucketVersioning',\n\t\t\t\t\t's3:GetBucketCORS',\n\t\t\t\t\t's3:PutBucketCORS',\n\t\t\t\t\t's3:GetBucketNotification',\n\t\t\t\t\t's3:PutBucketNotification',\n\t\t\t\t\t// A construct's `expire`, and removing it: S3 authorises\n\t\t\t\t\t// DeleteBucketLifecycle as PutLifecycleConfiguration.\n\t\t\t\t\t's3:GetLifecycleConfiguration',\n\t\t\t\t\t's3:PutLifecycleConfiguration',\n\t\t\t\t],\n\t\t\t\tResource: names.flatMap((n) => [\n\t\t\t\t\t`arn:aws:s3:::${n.bucket}`,\n\t\t\t\t\t`arn:aws:s3:::${n.bucket}-${suffix}`,\n\t\t\t\t]),\n\t\t\t},\n\t\t\t// A watched bucket's events: its topic and the subscriptions to it —\n\t\t\t// in whichever region the bucket is — and its dead-letter queue.\n\t\t\t{\n\t\t\t\tSid: 'StageBucketTopics',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t'sns:CreateTopic',\n\t\t\t\t\t'sns:TagResource',\n\t\t\t\t\t'sns:GetTopicAttributes',\n\t\t\t\t\t'sns:SetTopicAttributes',\n\t\t\t\t\t'sns:Subscribe',\n\t\t\t\t\t'sns:Unsubscribe',\n\t\t\t\t\t'sns:ListSubscriptionsByTopic',\n\t\t\t\t\t'sns:GetSubscriptionAttributes',\n\t\t\t\t\t'sns:SetSubscriptionAttributes',\n\t\t\t\t],\n\t\t\t\tResource: names.flatMap((n) =>\n\t\t\t\t\t[`${n.bucket}-events`, `${n.bucket}-${suffix}-events`].flatMap(\n\t\t\t\t\t\t(topic) => [\n\t\t\t\t\t\t\t`arn:aws:sns:*:${account}:${topic}`,\n\t\t\t\t\t\t\t`arn:aws:sns:*:${account}:${topic}:*`,\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\t{\n\t\t\t\tSid: 'StageBucketDeadLetters',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t'sqs:CreateQueue',\n\t\t\t\t\t'sqs:TagQueue',\n\t\t\t\t\t'sqs:GetQueueUrl',\n\t\t\t\t\t'sqs:GetQueueAttributes',\n\t\t\t\t\t'sqs:SetQueueAttributes',\n\t\t\t\t],\n\t\t\t\tResource: names.flatMap((n) => [\n\t\t\t\t\t`arn:aws:sqs:*:${account}:${n.bucket}-events-dlq`,\n\t\t\t\t\t`arn:aws:sqs:*:${account}:${n.bucket}-${suffix}-events-dlq`,\n\t\t\t\t]),\n\t\t\t},\n\t\t\t{\n\t\t\t\tSid: 'StageBucketUsers',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t'iam:GetUser',\n\t\t\t\t\t'iam:CreateUser',\n\t\t\t\t\t'iam:TagUser',\n\t\t\t\t\t'iam:ListUserTags',\n\t\t\t\t\t'iam:GetUserPolicy',\n\t\t\t\t\t'iam:PutUserPolicy',\n\t\t\t\t\t'iam:ListAccessKeys',\n\t\t\t\t\t'iam:CreateAccessKey',\n\t\t\t\t\t'iam:DeleteAccessKey',\n\t\t\t\t],\n\t\t\t\tResource: names.map(\n\t\t\t\t\t(n) => `arn:aws:iam::${account}:user${IAM_USER_PATH}${n.user}`,\n\t\t\t\t),\n\t\t\t},\n\t\t]);\n\n\t\t// Each file server behind a CDN: its certificate, its origin access\n\t\t// control, its response headers policies and its distribution. Neither\n\t\t// ACM nor CloudFront scopes creating these to a name, so they are on\n\t\t// every resource of the account; nothing here deletes.\n\t\tconst served = Object.values(manifest).some(\n\t\t\t(d) => d.kind === 'file-server',\n\t\t);\n\t\tif (served && (objects.config as { cdn?: boolean }).cdn !== false) {\n\t\t\tdescribe.push(\n\t\t\t\t'create the file servers’ certificates and CloudFront distributions (ACM, CloudFront)',\n\t\t\t);\n\t\t\tbuild.push(() => [\n\t\t\t\t{\n\t\t\t\t\tSid: 'StageFileServerCertificates',\n\t\t\t\t\tEffect: 'Allow',\n\t\t\t\t\tAction: [\n\t\t\t\t\t\t'acm:RequestCertificate',\n\t\t\t\t\t\t'acm:DescribeCertificate',\n\t\t\t\t\t\t'acm:ListCertificates',\n\t\t\t\t\t\t'acm:AddTagsToCertificate',\n\t\t\t\t\t],\n\t\t\t\t\tResource: '*',\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tSid: 'StageFileServerCdn',\n\t\t\t\t\tEffect: 'Allow',\n\t\t\t\t\tAction: [\n\t\t\t\t\t\t'cloudfront:CreateDistribution',\n\t\t\t\t\t\t'cloudfront:CreateDistributionWithTags',\n\t\t\t\t\t\t'cloudfront:GetDistribution',\n\t\t\t\t\t\t'cloudfront:GetDistributionConfig',\n\t\t\t\t\t\t'cloudfront:UpdateDistribution',\n\t\t\t\t\t\t'cloudfront:ListDistributions',\n\t\t\t\t\t\t'cloudfront:TagResource',\n\t\t\t\t\t\t'cloudfront:CreateOriginAccessControl',\n\t\t\t\t\t\t'cloudfront:GetOriginAccessControl',\n\t\t\t\t\t\t'cloudfront:ListOriginAccessControls',\n\t\t\t\t\t\t'cloudfront:CreateResponseHeadersPolicy',\n\t\t\t\t\t\t'cloudfront:GetResponseHeadersPolicy',\n\t\t\t\t\t\t'cloudfront:GetResponseHeadersPolicyConfig',\n\t\t\t\t\t\t'cloudfront:UpdateResponseHeadersPolicy',\n\t\t\t\t\t\t'cloudfront:ListResponseHeadersPolicies',\n\t\t\t\t\t],\n\t\t\t\t\tResource: '*',\n\t\t\t\t},\n\t\t\t]);\n\t\t}\n\t}\n\n\t// The deploy creates each mail construct's sender when an ses provider\n\t// sends its mail: the identity, verified by DKIM — SES scopes none of\n\t// these to a name — and each construct's IAM user and key, by name.\n\tconst emails = Object.entries(manifest)\n\t\t.filter(([, d]) => d.kind === 'email')\n\t\t.map(([id]) => id)\n\t\t.sort();\n\tconst email = stageProvider(workspace, 'email', stage);\n\tif (email.mode === 'provider' && email.name === 'ses' && emails.length) {\n\t\tconst { scope } = deployIdentity(workspace, stage);\n\t\tconst users = emails.map((id) => emailUserName(scope, stage, id));\n\t\tdescribe.push(\n\t\t\t`verify the sending domain in SES and create the mail users ${users.join(', ')} and their keys (SES, IAM)`,\n\t\t);\n\t\tbuild.push((account) => [\n\t\t\t{\n\t\t\t\tSid: 'StageMailIdentity',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t'ses:GetIdentityDkimAttributes',\n\t\t\t\t\t'ses:VerifyDomainDkim',\n\t\t\t\t\t'ses:SetIdentityDkimEnabled',\n\t\t\t\t\t'ses:GetSendQuota',\n\t\t\t\t],\n\t\t\t\tResource: '*',\n\t\t\t},\n\t\t\t{\n\t\t\t\tSid: 'StageMailUsers',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t'iam:GetUser',\n\t\t\t\t\t'iam:CreateUser',\n\t\t\t\t\t'iam:TagUser',\n\t\t\t\t\t'iam:ListUserTags',\n\t\t\t\t\t'iam:GetUserPolicy',\n\t\t\t\t\t'iam:PutUserPolicy',\n\t\t\t\t\t'iam:ListAccessKeys',\n\t\t\t\t\t'iam:CreateAccessKey',\n\t\t\t\t\t'iam:DeleteAccessKey',\n\t\t\t\t],\n\t\t\t\tResource: users.map(\n\t\t\t\t\t(user) => `arn:aws:iam::${account}:user${IAM_USER_PATH}${user}`,\n\t\t\t\t),\n\t\t\t},\n\t\t]);\n\t}\n\n\t// The stage's backups: the deploy creates the project bucket if it is not\n\t// there, keeps its lifecycle, and creates the backups user and its key.\n\t// The role never reads the backups — `gkm backup:list` and `:restore`\n\t// run with a person's own credentials.\n\tif (stageBackups(workspace, manifest, stage).mode === 'on') {\n\t\tconst { scope } = deployIdentity(workspace, stage);\n\t\tconst user = backupsUserName(scope, stage);\n\t\tconst bucketIn = (account: string) => projectBucketName(scope, account);\n\t\tdescribe.push(\n\t\t\t`create the project bucket ${bucketIn('<account>')} and keep its lifecycle, and create the backups user ${user} and its key (S3, IAM)`,\n\t\t);\n\t\tbuild.push((account) => [\n\t\t\t{\n\t\t\t\tSid: 'StageBackupsBucket',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t's3:ListBucket',\n\t\t\t\t\t...new Set([\n\t\t\t\t\t\t...PROJECT_BUCKET_CREATE_ACTIONS,\n\t\t\t\t\t\t...PROJECT_BUCKET_LIFECYCLE_ACTIONS,\n\t\t\t\t\t]),\n\t\t\t\t],\n\t\t\t\tResource: `arn:aws:s3:::${bucketIn(account)}`,\n\t\t\t},\n\t\t\t{\n\t\t\t\tSid: 'StageBackupsUser',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t'iam:GetUser',\n\t\t\t\t\t'iam:CreateUser',\n\t\t\t\t\t'iam:TagUser',\n\t\t\t\t\t'iam:ListUserTags',\n\t\t\t\t\t'iam:GetUserPolicy',\n\t\t\t\t\t'iam:PutUserPolicy',\n\t\t\t\t\t'iam:ListAccessKeys',\n\t\t\t\t\t'iam:CreateAccessKey',\n\t\t\t\t\t'iam:DeleteAccessKey',\n\t\t\t\t],\n\t\t\t\tResource: `arn:aws:iam::${account}:user${IAM_USER_PATH}${user}`,\n\t\t\t},\n\t\t]);\n\t}\n\n\t// The deploy writes the stage's hosts' records: in Route53, only that\n\t// zone's — and, with no hostedZoneId to name it, the zone is looked up\n\t// by name, which IAM cannot scope.\n\tfor (const { domain, config } of stageDnsDomains(\n\t\tstage,\n\t\tworkspace.domains,\n\t\tworkspace.dns,\n\t)) {\n\t\tif (config.provider !== 'route53') continue;\n\t\tconst zoneId = (config as { hostedZoneId?: string }).hostedZoneId?.replace(\n\t\t\t/^\\/?hostedzone\\//,\n\t\t\t'',\n\t\t);\n\t\tdescribe.push(\n\t\t\t`write the A, AAAA and CNAME records of ${domain} (Route53${zoneId ? `, ${zoneId}` : ''})`,\n\t\t);\n\t\tbuild.push(() => [\n\t\t\t{\n\t\t\t\tSid: 'StageDnsRecords',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t'route53:ChangeResourceRecordSets',\n\t\t\t\t\t'route53:ListResourceRecordSets',\n\t\t\t\t],\n\t\t\t\tResource: `arn:aws:route53:::hostedzone/${zoneId ?? '*'}`,\n\t\t\t},\n\t\t\t{\n\t\t\t\tSid: 'StageDnsChanges',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: ['route53:GetChange'],\n\t\t\t\tResource: 'arn:aws:route53:::change/*',\n\t\t\t},\n\t\t\t...(zoneId\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSid: 'StageDnsZones',\n\t\t\t\t\t\t\tEffect: 'Allow' as const,\n\t\t\t\t\t\t\tAction: ['route53:ListHostedZonesByName'],\n\t\t\t\t\t\t\tResource: '*',\n\t\t\t\t\t\t},\n\t\t\t\t\t]),\n\t\t]);\n\t}\n\n\treturn {\n\t\tkind: 'scoped',\n\t\tstatements: (account) => build.flatMap((statements) => statements(account)),\n\t\tdescribe,\n\t};\n}\n\n/**\n * Reading and writing one stage's deploy state in `bucket`, as the deploy\n * role is given it.\n */\nexport function stateBucketStatements(\n\tbucket: string,\n\tpath: string,\n): PolicyStatement[] {\n\treturn [\n\t\t{\n\t\t\tSid: 'StageState',\n\t\t\tEffect: 'Allow',\n\t\t\tAction: ['s3:GetObject', 's3:PutObject', 's3:DeleteObject'],\n\t\t\tResource: `arn:aws:s3:::${bucket}/${path}*`,\n\t\t},\n\t\t// HeadBucket, and a state not written yet a 404 rather than a 403.\n\t\t{\n\t\t\tSid: 'StageStateBucket',\n\t\t\tEffect: 'Allow',\n\t\t\tAction: ['s3:ListBucket'],\n\t\t\tResource: `arn:aws:s3:::${bucket}`,\n\t\t},\n\t];\n}\n\n/** The scoped access as a policy document, or null when it allows nothing. */\nexport function scopedPolicyDocument(\n\tstatements: PolicyStatement[],\n): string | null {\n\tif (statements.length === 0) return null;\n\treturn JSON.stringify({ Version: '2012-10-17', Statement: statements });\n}\n\n/** The account an IAM ARN is in: `arn:aws:iam::<account>:…`. */\nexport function accountOf(arn: string): string {\n\treturn arn.split(':')[4] ?? '';\n}\n","/**\n * `gkm deploy:github` — let GitHub Actions deploy one stage, with no keys.\n *\n * A stage usually lives in its own AWS account — staging in one, production in\n * another — so this runs once per stage, with that account's profile:\n *\n * gkm deploy:github --stage staging --profile acme-dev\n * gkm deploy:github --stage prod --profile acme-prod\n *\n * In the stage's account it makes sure GitHub's OIDC provider exists, and a\n * role that only this repository's `<stage>` environment can assume. On\n * GitHub it creates that environment and gives it what the generated deploy\n * workflow reads: `AWS_ROLE_ARN`, and — when the stage's secrets are kept in\n * the local file — its key as `GKM_SECRETS_KEY`. With `secrets.store` set to\n * S3, SSM or Secrets Manager the deploy job reads them with the role instead, so\n * no key is handed to GitHub, and this checks the stage's store in the same\n * account, with the same profile. Re-running it converges rather than duplicating.\n *\n * The role trusts the exact `sub` GitHub sends for the environment, read from\n * the repository's OIDC subject settings (`githubOidc.ts`) — the default, the\n * immutable subject with the owner's and repository's ids, or a custom\n * template. A re-run rewrites an existing role's trust to it, so running this\n * again repairs a role that trusted the wrong format. What the role may do is\n * `githubPolicy.ts`: `AdministratorAccess` for SST, and for a compose stage\n * only its own secrets (and deploy state, when that is in AWS).\n */\n\nimport { execFileSync } from 'node:child_process';\nimport {\n\tAttachRolePolicyCommand,\n\tCreateOpenIDConnectProviderCommand,\n\tCreateRoleCommand,\n\tDeleteRolePolicyCommand,\n\tDetachRolePolicyCommand,\n\tGetRoleCommand,\n\tIAMClient,\n\ttype IAMClientConfig,\n\tListAttachedRolePoliciesCommand,\n\tListOpenIDConnectProvidersCommand,\n\tListRoleTagsCommand,\n\tPutRolePolicyCommand,\n\tTagRoleCommand,\n\tUntagRoleCommand,\n\tUpdateAssumeRolePolicyCommand,\n} from '@aws-sdk/client-iam';\nimport { loadWorkspaceConfig } from '../config.js';\nimport { GkmError } from '../errors';\nimport { discover } from '../reconcile/discover.js';\nimport { constructGlobs } from '../reconcile/workspace.js';\nimport { getKeyPath, keystoreProject, readKey } from '../secrets/keystore.js';\nimport { isRemoteStore, secretsStoreFor } from '../secrets/store.js';\nimport { assertDeployedStage } from '../workspace/stages.js';\nimport { resolveOidcSubject } from './githubOidc.js';\nimport {\n\taccountOf,\n\tdeployAccess,\n\tSCOPED_POLICY_NAME,\n\tscopedPolicyDocument,\n} from './githubPolicy.js';\n\nexport { DEFAULT_POLICY_ARN, SCOPED_POLICY_NAME } from './githubPolicy.js';\n\nconst logger = console;\n\nconst GITHUB_OIDC_HOST = 'token.actions.githubusercontent.com';\nconst AUDIENCE = 'sts.amazonaws.com';\n\n/**\n * The tag recording which managed policy gkm attached to the role — so a\n * re-run detaches only what gkm put there, never a policy someone else did.\n */\nexport const POLICY_TAG = 'gkm:policy-arn';\n\nexport interface DeployGithubOptions {\n\tstage: string;\n\t/** The AWS profile for the stage's account. */\n\tprofile?: string;\n\t/** `owner/name`; defaults to the repository `gh` sees here. */\n\trepo?: string;\n\t/** The policy the deploy role gets, in place of the default. */\n\tpolicyArn?: string;\n\tdryRun?: boolean;\n}\n\n/** Runs `gh` with the given arguments and optional stdin, returning stdout. */\nexport type Gh = (args: string[], input?: string) => string;\n\n/** The system's `gh`. */\nexport const ghCli: Gh = (args, input) =>\n\texecFileSync('gh', args, {\n\t\tencoding: 'utf-8',\n\t\t// stderr captured, so a read that fails (a 404) is not printed as noise.\n\t\tstdio: ['pipe', 'pipe', 'pipe'],\n\t\t...(input === undefined ? {} : { input }),\n\t}).trim();\n\n/** The role a stage deploys as: `<project>-github-<stage>`, within IAM's 64. */\nexport function roleName(project: string, stage: string): string {\n\treturn `${project}-github-${stage}`\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9+=,.@_-]/g, '-')\n\t\t.slice(0, 64);\n}\n\n/**\n * Who may assume the role: a workflow job whose OIDC token carries exactly\n * `subject` — the repository's `<stage>` environment, in the format the\n * repository sends (see `githubOidc.ts`), and nothing else. Not another\n * branch's job, not another environment's: that is what keeps a staging\n * deploy from using the production role.\n */\nexport function trustPolicy(providerArn: string, subject: string): string {\n\treturn JSON.stringify({\n\t\tVersion: '2012-10-17',\n\t\tStatement: [\n\t\t\t{\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tPrincipal: { Federated: providerArn },\n\t\t\t\tAction: 'sts:AssumeRoleWithWebIdentity',\n\t\t\t\tCondition: {\n\t\t\t\t\tStringEquals: {\n\t\t\t\t\t\t[`${GITHUB_OIDC_HOST}:aud`]: AUDIENCE,\n\t\t\t\t\t\t[`${GITHUB_OIDC_HOST}:sub`]: subject,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t});\n}\n\n/**\n * The subject a trust policy trusts, or undefined when it names none. IAM\n * hands documents back URL-encoded.\n */\nexport function trustedSubject(\n\tdocument: string | undefined,\n): string | undefined {\n\tif (!document) return undefined;\n\tlet parsed: {\n\t\tStatement?: { Condition?: Record<string, Record<string, unknown>> }[];\n\t};\n\ttry {\n\t\tparsed = JSON.parse(safeDecode(document));\n\t} catch {\n\t\treturn undefined;\n\t}\n\tfor (const statement of parsed.Statement ?? []) {\n\t\tfor (const operator of Object.values(statement.Condition ?? {})) {\n\t\t\tconst value = operator[`${GITHUB_OIDC_HOST}:sub`];\n\t\t\tif (typeof value === 'string') return value;\n\t\t\tif (Array.isArray(value)) return value.join(', ');\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction safeDecode(value: string): string {\n\ttry {\n\t\treturn decodeURIComponent(value);\n\t} catch {\n\t\treturn value;\n\t}\n}\n\n/** GitHub's OIDC provider in this account, created if it is not there. */\nexport async function ensureOidcProvider(iam: IAMClient): Promise<string> {\n\tconst { OpenIDConnectProviderList = [] } = await iam.send(\n\t\tnew ListOpenIDConnectProvidersCommand({}),\n\t);\n\tconst existing = OpenIDConnectProviderList.find((p) =>\n\t\tp.Arn?.endsWith(`oidc-provider/${GITHUB_OIDC_HOST}`),\n\t)?.Arn;\n\tif (existing) return existing;\n\n\tconst created = await iam.send(\n\t\tnew CreateOpenIDConnectProviderCommand({\n\t\t\tUrl: `https://${GITHUB_OIDC_HOST}`,\n\t\t\tClientIDList: [AUDIENCE],\n\t\t}),\n\t);\n\treturn created.OpenIDConnectProviderArn!;\n}\n\n/**\n * What the role is given: a managed policy, attached; or an inline policy\n * document — null for none at all.\n */\nexport type RoleAccess = { managed: string } | { inline: string | null };\n\n/** What {@link ensureRole} did. */\nexport interface RoleOutcome {\n\tarn: string;\n\tcreated: boolean;\n\t/** The subject the role trusted before, when it existed. */\n\tpreviousSubject?: string;\n\t/** Managed policies gkm had attached and detached now. */\n\tdetached: string[];\n\t/**\n\t * Managed policies still attached that the role no longer needs, which gkm\n\t * did not record attaching — left alone, for a person to detach.\n\t */\n\tleftAttached: string[];\n}\n\nfunction isNoSuchEntity(error: unknown): boolean {\n\treturn (error as { name?: string }).name === 'NoSuchEntityException';\n}\n\n/**\n * The deploy role, created or brought back to this trust and access.\n *\n * Converges: re-running rewrites the trust, and moves the role from one access\n * to another — detaching a managed policy only when the role's\n * {@link POLICY_TAG} says gkm attached it.\n */\nexport async function ensureRole(\n\tiam: IAMClient,\n\tname: string,\n\ttrust: string,\n\taccess: RoleAccess,\n): Promise<RoleOutcome> {\n\tlet arn: string;\n\tlet created = false;\n\tlet previousSubject: string | undefined;\n\tlet recorded: string | undefined;\n\ttry {\n\t\tconst { Role } = await iam.send(new GetRoleCommand({ RoleName: name }));\n\t\tpreviousSubject = trustedSubject(Role!.AssumeRolePolicyDocument);\n\t\tawait iam.send(\n\t\t\tnew UpdateAssumeRolePolicyCommand({\n\t\t\t\tRoleName: name,\n\t\t\t\tPolicyDocument: trust,\n\t\t\t}),\n\t\t);\n\t\tarn = Role!.Arn!;\n\t\tconst { Tags = [] } = await iam.send(\n\t\t\tnew ListRoleTagsCommand({ RoleName: name }),\n\t\t);\n\t\trecorded = Tags.find((tag) => tag.Key === POLICY_TAG)?.Value;\n\t} catch (error) {\n\t\tif (!isNoSuchEntity(error)) throw error;\n\t\tconst { Role } = await iam.send(\n\t\t\tnew CreateRoleCommand({\n\t\t\t\tRoleName: name,\n\t\t\t\tAssumeRolePolicyDocument: trust,\n\t\t\t\tDescription: 'Deploys from GitHub Actions (gkm deploy:github)',\n\t\t\t\t// SST deploys can run long; the default hour is tight.\n\t\t\t\tMaxSessionDuration: 3600 * 2,\n\t\t\t}),\n\t\t);\n\t\tarn = Role!.Arn!;\n\t\tcreated = true;\n\t}\n\n\tconst detached: string[] = [];\n\tconst leftAttached: string[] = [];\n\tconst detach = async (policyArn: string) => {\n\t\ttry {\n\t\t\tawait iam.send(\n\t\t\t\tnew DetachRolePolicyCommand({ RoleName: name, PolicyArn: policyArn }),\n\t\t\t);\n\t\t\tdetached.push(policyArn);\n\t\t} catch (error) {\n\t\t\t// Already gone — by hand, or a run that stopped halfway.\n\t\t\tif (!isNoSuchEntity(error)) throw error;\n\t\t}\n\t};\n\tconst deleteInline = async () => {\n\t\ttry {\n\t\t\tawait iam.send(\n\t\t\t\tnew DeleteRolePolicyCommand({\n\t\t\t\t\tRoleName: name,\n\t\t\t\t\tPolicyName: SCOPED_POLICY_NAME,\n\t\t\t\t}),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (!isNoSuchEntity(error)) throw error;\n\t\t}\n\t};\n\n\tif ('managed' in access) {\n\t\t// Attaching an attached policy is a no-op, so this converges too.\n\t\tawait iam.send(\n\t\t\tnew AttachRolePolicyCommand({\n\t\t\t\tRoleName: name,\n\t\t\t\tPolicyArn: access.managed,\n\t\t\t}),\n\t\t);\n\t\tif (recorded && recorded !== access.managed) await detach(recorded);\n\t\tif (recorded !== access.managed) {\n\t\t\tawait iam.send(\n\t\t\t\tnew TagRoleCommand({\n\t\t\t\t\tRoleName: name,\n\t\t\t\t\tTags: [{ Key: POLICY_TAG, Value: access.managed }],\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tif (!created) await deleteInline();\n\t\treturn { arn, created, previousSubject, detached, leftAttached };\n\t}\n\n\tif (access.inline) {\n\t\tawait iam.send(\n\t\t\tnew PutRolePolicyCommand({\n\t\t\t\tRoleName: name,\n\t\t\t\tPolicyName: SCOPED_POLICY_NAME,\n\t\t\t\tPolicyDocument: access.inline,\n\t\t\t}),\n\t\t);\n\t} else if (!created) {\n\t\tawait deleteInline();\n\t}\n\tif (created) return { arn, created, previousSubject, detached, leftAttached };\n\n\tif (recorded) {\n\t\tawait detach(recorded);\n\t\tawait iam.send(\n\t\t\tnew UntagRoleCommand({ RoleName: name, TagKeys: [POLICY_TAG] }),\n\t\t);\n\t}\n\t// A role from before gkm recorded what it attached: what is attached may\n\t// be gkm's or someone's own, so it is named, not detached.\n\tconst { AttachedPolicies = [] } = await iam.send(\n\t\tnew ListAttachedRolePoliciesCommand({ RoleName: name }),\n\t);\n\tfor (const policy of AttachedPolicies) {\n\t\tif (policy.PolicyArn && !detached.includes(policy.PolicyArn)) {\n\t\t\tleftAttached.push(policy.PolicyArn);\n\t\t}\n\t}\n\treturn { arn, created, previousSubject, detached, leftAttached };\n}\n\n/**\n * An IAM client for the stage's account.\n *\n * `fromIni` for a named profile, deliberately: it resolves exactly that\n * profile — keys, assume-role, `credential_process` or SSO, whichever\n * ~/.aws/config says — and never falls back to AWS_* in the environment. The\n * provider chain checks the environment first, so exported staging keys would\n * quietly win over `--profile prod` and the production role would land in the\n * staging account.\n */\nexport async function iamFor(\n\tprofile?: string,\n\tendpoint?: string,\n): Promise<IAMClient> {\n\tconst config: IAMClientConfig = { region: 'us-east-1' };\n\tif (profile) {\n\t\tconst { fromIni } = await import('@aws-sdk/credential-providers');\n\t\tconfig.credentials = fromIni({ profile });\n\t}\n\tif (endpoint) {\n\t\tconfig.endpoint = endpoint;\n\t\tconfig.credentials = { accessKeyId: 'test', secretAccessKey: 'test' };\n\t}\n\treturn new IAMClient(config);\n}\n\nexport async function deployGithubCommand(\n\toptions: DeployGithubOptions,\n\tdeps: { iam?: IAMClient; gh?: Gh; cwd?: string } = {},\n): Promise<{ roleArn?: string; repo: string; subject: string }> {\n\tconst gh = deps.gh ?? ghCli;\n\tconst { workspace } = await loadWorkspaceConfig(deps.cwd);\n\tassertDeployedStage(workspace.stages, options.stage);\n\n\tconst repo =\n\t\toptions.repo ??\n\t\tgh(['repo', 'view', '--json', 'nameWithOwner', '-q', '.nameWithOwner']);\n\tconst role = roleName(workspace.name, options.stage);\n\t// The exact subject GitHub will send — read from the repository's OIDC\n\t// settings, before anything is changed, so a format no role can trust\n\t// fails here.\n\tconst oidc = resolveOidcSubject(gh, repo, options.stage);\n\t// The buckets an s3 provider creates are named after their constructs,\n\t// and a stage with a database is backed up: the role is scoped to\n\t// exactly those.\n\tconst manifest = await discover({\n\t\tpatterns: constructGlobs(workspace),\n\t\tcwd: workspace.root,\n\t});\n\tconst access = deployAccess(\n\t\tworkspace,\n\t\toptions.stage,\n\t\toptions.policyArn,\n\t\tmanifest,\n\t);\n\t// Read through the keystore so a key still at the place keys used to be kept\n\t// is found, and copied to where it is kept now.\n\tconst key = await readKey(options.stage, keystoreProject(workspace));\n\tconst keyPath = getKeyPath(options.stage, keystoreProject(workspace));\n\tconst hasKey = key !== null;\n\t// A stage whose secrets are in a store is read from there by the deploy job,\n\t// with the role; it needs no key on GitHub.\n\tconst remote = isRemoteStore(workspace, options.stage);\n\t// Read from the stage's own store, with the same credentials the role is\n\t// created with: what the deploy job will find there.\n\tconst store = await secretsStoreFor(workspace, options.stage, {\n\t\t...(options.profile ? { profile: options.profile } : {}),\n\t});\n\tconst hasSecrets = remote && (await store.read(options.stage)) !== null;\n\tconst via = options.profile\n\t\t? `profile \"${options.profile}\"`\n\t\t: 'the default credentials';\n\n\tlogger.log(`\\n🔐 GitHub → AWS for stage \"${options.stage}\"\\n`);\n\tlogger.log(` Repository: ${repo}`);\n\tlogger.log(` AWS profile: ${options.profile ?? '(default credentials)'}`);\n\tlogger.log(` Role: ${role}`);\n\tif (access.kind === 'managed') {\n\t\tlogger.log(` Policy: ${access.policyArn} (${access.reason})`);\n\t} else if (access.describe.length > 0) {\n\t\tlogger.log(\n\t\t\t` Policy: inline \"${SCOPED_POLICY_NAME}\", scoped to the compose deploy — only:`,\n\t\t);\n\t\tfor (const line of access.describe) logger.log(` ${line}`);\n\t} else {\n\t\tlogger.log(\n\t\t\t' Policy: none — a compose deploy with file secrets and local state reads nothing from AWS',\n\t\t);\n\t}\n\tlogger.log(\n\t\t` Trusted by: ${oidc.subject} only (${SUBJECT_KINDS[oidc.kind]})`,\n\t);\n\tif (oidc.warning) logger.log(` ⚠ ${oidc.warning}`);\n\tif (remote) {\n\t\tlogger.log(\n\t\t\t` Secrets: ${hasSecrets ? `in the store (${store.name}), read with ${via}` : `none in the store yet — gkm secrets:set <KEY> '…' --stage ${options.stage}`}`,\n\t\t);\n\t} else {\n\t\tlogger.log(\n\t\t\t` Secrets key: ${hasKey ? keyPath : `none at ${keyPath} — run gkm secrets:init --stage ${options.stage} first`}`,\n\t\t);\n\t}\n\n\tif (options.dryRun) {\n\t\tif (access.kind === 'scoped') {\n\t\t\tconst document = scopedPolicyDocument(access.statements('<account>'));\n\t\t\tif (document) {\n\t\t\t\tlogger.log(\n\t\t\t\t\t`\\n Inline policy:\\n${JSON.stringify(JSON.parse(document), null, 2).replace(/^/gm, ' ')}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tlogger.log('\\n --dry-run: nothing changed.\\n');\n\t\treturn { repo, subject: oidc.subject };\n\t}\n\n\tconst iam = deps.iam ?? (await iamFor(options.profile));\n\tconst providerArn = await ensureOidcProvider(iam).catch((error) => {\n\t\t// The first AWS call is where an expired SSO login surfaces; the SDK's\n\t\t// message does not say which profile, and this command knows.\n\t\tif (/SSO session/i.test(String(error?.message)) && options.profile) {\n\t\t\tthrow new SsoSessionExpired(options.profile);\n\t\t}\n\t\tthrow error;\n\t});\n\tconst outcome = await ensureRole(\n\t\tiam,\n\t\trole,\n\t\ttrustPolicy(providerArn, oidc.subject),\n\t\taccess.kind === 'managed'\n\t\t\t? { managed: access.policyArn }\n\t\t\t: {\n\t\t\t\t\tinline: scopedPolicyDocument(\n\t\t\t\t\t\taccess.statements(accountOf(providerArn)),\n\t\t\t\t\t),\n\t\t\t\t},\n\t);\n\tconst roleArn = outcome.arn;\n\tlogger.log(`\\n ✓ AWS: ${roleArn}${outcome.created ? ' (created)' : ''}`);\n\tif (!outcome.created) {\n\t\tlogger.log(\n\t\t\toutcome.previousSubject === oidc.subject\n\t\t\t\t? ` ✓ Trust: unchanged, ${oidc.subject}`\n\t\t\t\t: ` ✓ Trust: ${outcome.previousSubject ?? '(no subject)'} → ${oidc.subject}`,\n\t\t);\n\t}\n\tfor (const detached of outcome.detached) {\n\t\tlogger.log(` ✓ Detached ${detached} (attached by gkm, no longer needed)`);\n\t}\n\tif (access.kind === 'scoped') {\n\t\tfor (const attached of outcome.leftAttached) {\n\t\t\tlogger.log(\n\t\t\t\t` ⚠ ${attached} is still attached to ${role}. gkm has no record of attaching it, so it is left; the compose deploy does not need it. Detach it with: aws iam detach-role-policy --role-name ${role} --policy-arn ${attached}${options.profile ? ` --profile ${options.profile}` : ''}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// The environment the generated deploy workflow runs the stage in.\n\tgh(['api', '--method', 'PUT', `repos/${repo}/environments/${options.stage}`]);\n\tgh([\n\t\t'variable',\n\t\t'set',\n\t\t'AWS_ROLE_ARN',\n\t\t'--env',\n\t\toptions.stage,\n\t\t'--repo',\n\t\trepo,\n\t\t'--body',\n\t\troleArn,\n\t]);\n\tlogger.log(` ✓ GitHub: environment \"${options.stage}\", AWS_ROLE_ARN`);\n\n\tif (remote) {\n\t\t// Nothing to send: the deploy job reads the stage's store itself.\n\t\tif (!hasSecrets) {\n\t\t\tlogger.log(\n\t\t\t\t` ⚠ The \"${options.stage}\" store holds no secrets yet; set them with gkm secrets:set <KEY> '…' --stage ${options.stage}${options.profile ? ` (AWS_PROFILE=${options.profile})` : ''}.`,\n\t\t\t);\n\t\t}\n\t} else if (hasKey) {\n\t\t// Through stdin, so the key is never an argument a process list shows.\n\t\tgh(\n\t\t\t[\n\t\t\t\t'secret',\n\t\t\t\t'set',\n\t\t\t\t'GKM_SECRETS_KEY',\n\t\t\t\t'--env',\n\t\t\t\toptions.stage,\n\t\t\t\t'--repo',\n\t\t\t\trepo,\n\t\t\t],\n\t\t\tkey!,\n\t\t);\n\t\tlogger.log(' ✓ GitHub: GKM_SECRETS_KEY');\n\t} else {\n\t\tlogger.log(\n\t\t\t` ⚠ No secrets key for \"${options.stage}\"; run gkm secrets:init --stage ${options.stage}, then this again.`,\n\t\t);\n\t}\n\n\tlogger.log(\n\t\t`\\n Protect it: add required reviewers to the \"${options.stage}\" environment in the repository settings.\\n`,\n\t);\n\treturn { roleArn, repo, subject: oidc.subject };\n}\n\nconst SUBJECT_KINDS = {\n\tdefault: \"the repository's default subject\",\n\timmutable: \"the repository's immutable subject\",\n\tcustom: \"the repository's custom subject template\",\n\tassumed: 'assumed: the default format',\n} as const;\n\n/** The profile's SSO login has lapsed; the fix is one command away. */\nexport class SsoSessionExpired extends GkmError {\n\tconstructor(readonly profile: string) {\n\t\tsuper(\n\t\t\t`The SSO session for profile \"${profile}\" has expired or is invalid. Run: aws sso login --profile ${profile}`,\n\t\t);\n\t\tthis.name = 'SsoSessionExpired';\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,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AA4B,QAAQ,MAAM,gBAAgB;CAErE,IAAI,QAEC;MAAA,CAAC,YACJ,OAAO,IACN,YAAY,QAAQ,MAAM,gFAAgF,QAAQ,QAAQ,QAAQ,UAAU,iBAAiB,QAAQ,QAAQ,KAAK,GAAG,EACtL;CAAA,OAEK,IAAI,QAAQ;EAElB,GACC;GACC;GACA;GACA;GACA;GACA,QAAQ;GACR;GACA;EACD,GACA,GACD;EACA,OAAO,IAAI,6BAA6B;CACzC,OACC,OAAO,IACN,2BAA2B,QAAQ,MAAM,kCAAkC,QAAQ,MAAM,mBAC1F;CAGD,OAAO,IACN,kDAAkD,QAAQ,MAAM,4CACjE;CACA,OAAO;EAAE;EAAS;EAAM,SAAS,KAAK;CAAQ;AAC/C;AAEA,MAAM,gBAAgB;CACrB,SAAS;CACT,WAAW;CACX,QAAQ;CACR,SAAS;AACV;;AAGA,IAAa,oBAAb,cAAuC,SAAS;CAC1B;CAArB,YAAY,SAA0B;EACrC,MACC,gCAAgC,QAAQ,4DAA4D,SACrG;EAHoB,KAAA,UAAA;EAIpB,KAAK,OAAO;CACb;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"seeds-D7q1zKCJ.cjs","names":["userInfo","hostname"],"sources":["../src/deploy/journal.ts","../src/deploy/actor.ts","../src/deploy/dnsResources.ts","../src/target/seeds.ts"],"sourcesContent":["/**\n * A deploy's record of what it is creating, written as it goes.\n *\n * Deploy used to write state once, after every app had deployed, so a run that\n * failed half way lost the ids of everything it had created and the next run\n * fell back to finding them by name — or made them again. The journal writes\n * through the stage's `StateStore` after every resource instead:\n *\n * 1. `pending`, before the call that creates it — \"this may now exist\";\n * 2. `ready` with the target's id, once the call has returned.\n *\n * A run that meets a `pending` record looks the resource up before it creates\n * anything, so a run killed between the create and the record adopts what the\n * dead run made instead of making a second one. Every write is conditional on\n * the version the journal last wrote, so a writer that skipped the stage's\n * lock raises `StateVersionConflict` here rather than being overwritten.\n */\n\nimport type { ResourceRecord, StateStore, StateVersion } from './StateStore';\nimport type { StageState } from './state';\n\n/** One resource, as the journal keys and describes it. */\nexport interface JournalEntry {\n\t/** `<type>:<name>`, unique within the stage — `application:api`. */\n\tkey: string;\n\ttype: string;\n\t/** What a later run needs to find it again — its name, usually. */\n\tdata?: Record<string, unknown>;\n}\n\n/** How to get at one kind of resource on the target. */\nexport interface ResourceSteps<T> {\n\t/** By the id a `ready` record holds; `null` when the target lost it. */\n\tget?: (id: string) => Promise<T | null | undefined>;\n\t/** By what identifies it otherwise — its name, in its environment. */\n\tfind: () => Promise<T | null | undefined>;\n\tcreate: () => Promise<T>;\n\tid: (resource: T) => string;\n}\n\nexport interface Ensured<T> {\n\tresource: T;\n\t/**\n\t * - `recorded`: the id in a `ready` record still resolves\n\t * - `resumed`: a `pending` record's resource was found — a run died\n\t * between creating it and recording it\n\t * - `found`: it existed, unrecorded\n\t * - `created`: it did not exist\n\t */\n\tvia: 'recorded' | 'resumed' | 'found' | 'created';\n\t/** The recorded id that no longer resolved, if there was one. */\n\tstaleId?: string;\n}\n\nexport class DeployJournal<S extends StageState = StageState> {\n\tprivate constructor(\n\t\tprivate readonly store: StateStore,\n\t\treadonly stage: string,\n\t\t/** The stage's state, mutated by the deploy and written by `save`. */\n\t\treadonly state: S,\n\t\tprivate resources: Record<string, ResourceRecord>,\n\t\tprivate version: StateVersion,\n\t\t/** Whether the stage had state before this run. */\n\t\treadonly existed: boolean,\n\t) {}\n\n\t/**\n\t * The stage's journal — its stored state, or `initial` written as the\n\t * stage's first state, so there is somewhere to record the very first\n\t * resource before it is created.\n\t *\n\t * `adopt` turns a stored state into the shape the caller works on — a\n\t * Dokploy deploy of a stage compose deployed keeps its releases and starts\n\t * its Dokploy ids afresh. Without it, the stored state is used as it is.\n\t */\n\tstatic async open(\n\t\tstore: StateStore,\n\t\tstage: string,\n\t\tinitial: () => StageState,\n\t): Promise<DeployJournal<StageState>>;\n\tstatic async open<S extends StageState>(\n\t\tstore: StateStore,\n\t\tstage: string,\n\t\tinitial: () => S,\n\t\tadopt: (stored: StageState) => S,\n\t): Promise<DeployJournal<S>>;\n\tstatic async open(\n\t\tstore: StateStore,\n\t\tstage: string,\n\t\tinitial: () => StageState,\n\t\tadopt: (stored: StageState) => StageState = (stored) => stored,\n\t): Promise<DeployJournal<StageState>> {\n\t\tconst stored = await store.read(stage);\n\t\tif (stored) {\n\t\t\treturn new DeployJournal(\n\t\t\t\tstore,\n\t\t\t\tstage,\n\t\t\t\tadopt(stored.state),\n\t\t\t\tstored.resources,\n\t\t\t\tstored.version,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t}\n\n\t\tconst state = initial();\n\t\tconst version = await store.write(stage, state, { expectedVersion: null });\n\t\treturn new DeployJournal(store, stage, state, {}, version, false);\n\t}\n\n\trecord(key: string): ResourceRecord | undefined {\n\t\treturn this.resources[key];\n\t}\n\n\t/** The keys a previous run marked `pending` and never saw created. */\n\tunfinished(): string[] {\n\t\treturn Object.values(this.resources)\n\t\t\t.filter((record) => record.status === 'pending')\n\t\t\t.map((record) => record.key);\n\t}\n\n\t/** Records that `entry` is about to be created. */\n\tasync pending(entry: JournalEntry): Promise<void> {\n\t\tawait this.put({ ...entry, status: 'pending' });\n\t}\n\n\t/**\n\t * Records `entry` as existing with `id`; a no-op if it already is, with\n\t * the same data.\n\t */\n\tasync ready(entry: JournalEntry, id: string): Promise<void> {\n\t\tconst current = this.resources[entry.key];\n\t\tif (\n\t\t\tcurrent?.status === 'ready' &&\n\t\t\tcurrent.id === id &&\n\t\t\tJSON.stringify(current.data) === JSON.stringify(entry.data)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tawait this.put({ ...entry, status: 'ready', id });\n\t}\n\n\t/**\n\t * The resource `entry` names: by its recorded id, else by looking it up,\n\t * else created — with `pending` written before the create and `ready`\n\t * after, so a run that dies in between leaves a record the next run\n\t * resolves by looking the resource up rather than creating another.\n\t */\n\tasync ensure<T>(\n\t\tentry: JournalEntry,\n\t\tsteps: ResourceSteps<T>,\n\t): Promise<Ensured<T>> {\n\t\tconst record = this.resources[entry.key];\n\t\tlet staleId: string | undefined;\n\n\t\tif (record?.status === 'ready' && record.id && steps.get) {\n\t\t\tconst known = await steps.get(record.id);\n\t\t\tif (known) {\n\t\t\t\tawait this.ready(entry, steps.id(known));\n\t\t\t\treturn { resource: known, via: 'recorded' };\n\t\t\t}\n\t\t\tstaleId = record.id;\n\t\t}\n\n\t\tconst existing = await steps.find();\n\t\tif (existing) {\n\t\t\tawait this.ready(entry, steps.id(existing));\n\t\t\treturn {\n\t\t\t\tresource: existing,\n\t\t\t\tvia: record?.status === 'pending' ? 'resumed' : 'found',\n\t\t\t\t...(staleId ? { staleId } : {}),\n\t\t\t};\n\t\t}\n\n\t\tawait this.pending(entry);\n\t\tconst created = await steps.create();\n\t\tawait this.ready(entry, steps.id(created));\n\t\treturn {\n\t\t\tresource: created,\n\t\t\tvia: 'created',\n\t\t\t...(staleId ? { staleId } : {}),\n\t\t};\n\t}\n\n\t/** Removes `key`'s record — a resource that no longer exists. */\n\tasync forget(key: string): Promise<void> {\n\t\tif (!(key in this.resources)) return;\n\t\tthis.version = await this.store.deleteResource(this.stage, key, {\n\t\t\texpectedVersion: this.version,\n\t\t});\n\t\tconst { [key]: _removed, ...resources } = this.resources;\n\t\tthis.resources = resources;\n\t}\n\n\t/** Every record, as the journal last wrote or read it. */\n\trecords(): Record<string, ResourceRecord> {\n\t\treturn this.resources;\n\t}\n\n\t/** Writes the stage's state, keeping its resource records. */\n\tasync save(): Promise<void> {\n\t\tthis.state.lastDeployedAt = new Date().toISOString();\n\t\tthis.version = await this.store.write(this.stage, this.state, {\n\t\t\texpectedVersion: this.version,\n\t\t});\n\t}\n\n\tprivate async put(record: Omit<ResourceRecord, 'updatedAt'>): Promise<void> {\n\t\tthis.version = await this.store.putResource(this.stage, record, {\n\t\t\texpectedVersion: this.version,\n\t\t});\n\t\tthis.resources = {\n\t\t\t...this.resources,\n\t\t\t[record.key]: { ...record, updatedAt: new Date().toISOString() },\n\t\t};\n\t}\n}\n","/**\n * Who wrote a stage's deploy state: a GitHub Actions run, or a person at a\n * machine. Recorded on every state write (`updatedBy`), on every resource\n * record and on every release (`releasedBy`), so \"who put this here\" has an\n * answer that does not depend on anyone's memory.\n */\n\nimport { hostname, userInfo } from 'node:os';\n\n/** A GitHub Actions run: the account that triggered it and the run's page. */\nexport interface GithubActor {\n\tkind: 'github';\n\t/** `GITHUB_ACTOR` — the account that triggered the run. */\n\tactor: string;\n\t/** `<server>/<repository>/actions/runs/<run id>` */\n\trun: string;\n\t/** `GITHUB_WORKFLOW` — the workflow's name. */\n\tworkflow?: string;\n}\n\n/** A person at a machine. */\nexport interface LocalActor {\n\tkind: 'local';\n\tuser: string;\n\thost: string;\n}\n\nexport type Actor = GithubActor | LocalActor;\n\n/** Whether `env` is a CI job — GitHub Actions or any runner that sets `CI`. */\nexport function isCi(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn env.GITHUB_ACTIONS === 'true' || env.CI === 'true';\n}\n\n/** Who this process is writing as. */\nexport function currentActor(env: NodeJS.ProcessEnv = process.env): Actor {\n\tif (env.GITHUB_ACTIONS === 'true') {\n\t\tconst server = env.GITHUB_SERVER_URL ?? 'https://github.com';\n\t\treturn {\n\t\t\tkind: 'github',\n\t\t\tactor: env.GITHUB_ACTOR ?? 'unknown',\n\t\t\trun: `${server}/${env.GITHUB_REPOSITORY ?? 'unknown'}/actions/runs/${env.GITHUB_RUN_ID ?? 'unknown'}`,\n\t\t\t...(env.GITHUB_WORKFLOW ? { workflow: env.GITHUB_WORKFLOW } : {}),\n\t\t};\n\t}\n\n\tlet user = 'unknown';\n\ttry {\n\t\tuser = userInfo().username;\n\t} catch {\n\t\t// No passwd entry (a container running as an arbitrary uid).\n\t}\n\treturn { kind: 'local', user, host: hostname() };\n}\n\n/** `octocat (deploy, https://github.com/…/runs/1)` or `ada@laptop`. */\nexport function describeActor(actor: Actor | undefined): string {\n\tif (!actor) return 'unknown';\n\tif (actor.kind === 'local') return `${actor.user}@${actor.host}`;\n\treturn `${actor.actor} (${actor.workflow ? `${actor.workflow}, ` : ''}${actor.run})`;\n}\n","/**\n * DNS records gkm wrote for a stage, as resource records in its deploy state.\n *\n * Each is `dns-record:<fqdn>:<type>` — `dns-record:api.example.com:A` — with\n * `id` `<fqdn> <type>` and the record's value in `data`. Every deploy's DNS\n * step writes through here — `gkm deploy` and `gkm compose` alike — so each\n * record has one key, whoever wrote it.\n */\n\nimport type { DeployJournal } from './journal';\nimport type { ResourceInput, ResourceRecord } from './StateStore';\n\n/** The resource type of a DNS record gkm wrote. */\nexport const DNS_RECORD_RESOURCE = 'dns-record';\n\n/** A DNS record as gkm writes it. */\nexport interface DnsResourceRecord {\n\t/** The `dns` domain it is under: `example.com`. */\n\tdomain: string;\n\t/** Relative to the domain, as providers take it: `api`, `@`. */\n\tname: string;\n\ttype: string;\n\tvalue: string;\n\tttl: number;\n\t/**\n\t * The domain's provider — `godaddy`, `route53`, … Absent on a record\n\t * migrated from a v2 state, which did not say.\n\t */\n\tprovider?: string;\n}\n\n/** `data` of a `dns-record` resource. */\nexport type DnsResourceData = Omit<DnsResourceRecord, 'type'>;\n\n/** A record's full name: `api.example.com`, or the domain for `@`. */\nexport function dnsRecordFqdn(domain: string, name: string): string {\n\treturn name === '@' || name === '' ? domain : `${name}.${domain}`;\n}\n\n/** `dns-record:<fqdn>:<type>` */\nexport function dnsResourceKey(fqdn: string, type: string): string {\n\treturn `${DNS_RECORD_RESOURCE}:${fqdn.toLowerCase()}:${type.toUpperCase()}`;\n}\n\n/** The resource record a written DNS record is kept as. */\nexport function dnsRecordResource(record: DnsResourceRecord): ResourceInput {\n\tconst fqdn = dnsRecordFqdn(record.domain, record.name).toLowerCase();\n\tconst type = record.type.toUpperCase();\n\tconst data: DnsResourceData = {\n\t\tdomain: record.domain,\n\t\tname: record.name,\n\t\tvalue: record.value,\n\t\tttl: record.ttl,\n\t\t...(record.provider ? { provider: record.provider } : {}),\n\t};\n\treturn {\n\t\tkey: dnsResourceKey(fqdn, type),\n\t\ttype: DNS_RECORD_RESOURCE,\n\t\tid: `${fqdn} ${type}`,\n\t\tstatus: 'ready',\n\t\tdata,\n\t};\n}\n\n/** Records that gkm wrote `record` — or updates the value it holds. */\nexport async function recordDnsResource(\n\tjournal: DeployJournal,\n\trecord: DnsResourceRecord,\n): Promise<void> {\n\tconst { key, type, id, data } = dnsRecordResource(record);\n\tawait journal.ready({ key, type, ...(data ? { data } : {}) }, id!);\n}\n\n/** Forgets a DNS record gkm deleted. */\nexport async function forgetDnsResource(\n\tjournal: DeployJournal,\n\trecord: Pick<DnsResourceRecord, 'domain' | 'name' | 'type'>,\n): Promise<void> {\n\tawait journal.forget(\n\t\tdnsResourceKey(dnsRecordFqdn(record.domain, record.name), record.type),\n\t);\n}\n\n/** One change a DNS step made, as `applyStackDns` reports it. */\nexport interface AppliedDnsChange {\n\tdomain: string;\n\tname: string;\n\ttype: string;\n\taction: string;\n\tvalue?: string;\n\tttl?: number;\n}\n\n/**\n * The changes a DNS step made, kept: what it created, updated or wrote is\n * recorded, what it deleted is forgotten. A record it found already right is\n * recorded only if gkm wrote it before; one it left to a person is not.\n */\nexport async function recordDnsChanges(\n\tjournal: DeployJournal,\n\tchanges: readonly AppliedDnsChange[],\n\tproviderOf: (domain: string) => string | undefined,\n): Promise<void> {\n\tfor (const change of changes) {\n\t\tif (change.action === 'delete') {\n\t\t\tawait forgetDnsResource(journal, change);\n\t\t\tcontinue;\n\t\t}\n\t\tconst written =\n\t\t\tchange.action === 'create' ||\n\t\t\tchange.action === 'update' ||\n\t\t\tchange.action === 'write';\n\t\tconst known =\n\t\t\tchange.action === 'unchanged' &&\n\t\t\tjournal.record(\n\t\t\t\tdnsResourceKey(dnsRecordFqdn(change.domain, change.name), change.type),\n\t\t\t) !== undefined;\n\t\tif ((!written && !known) || change.value === undefined) continue;\n\t\tconst provider = providerOf(change.domain);\n\t\tawait recordDnsResource(journal, {\n\t\t\tdomain: change.domain,\n\t\t\tname: change.name,\n\t\t\ttype: change.type,\n\t\t\tvalue: change.value,\n\t\t\tttl: change.ttl ?? 0,\n\t\t\t...(provider ? { provider } : {}),\n\t\t});\n\t}\n}\n\n/** Every DNS record gkm wrote for the stage, from its resource records. */\nexport function dnsResources(\n\tresources: Record<string, ResourceRecord>,\n): (DnsResourceRecord & { fqdn: string })[] {\n\treturn Object.values(resources)\n\t\t.filter((record) => record.type === DNS_RECORD_RESOURCE)\n\t\t.map((record) => {\n\t\t\tconst data = (record.data ?? {}) as DnsResourceData;\n\t\t\tconst [fqdn = '', type = ''] = (record.id ?? '').split(' ');\n\t\t\treturn { ...data, type, fqdn };\n\t\t})\n\t\t.sort(\n\t\t\t(a, b) => a.fqdn.localeCompare(b.fqdn) || a.type.localeCompare(b.type),\n\t\t);\n}\n","/**\n * A deployed stage's seeds: what every server target runs after its\n * migrations and before any app starts.\n *\n * Seeds are reference data — roles, permissions, plans — kept current by\n * being run again, so a deploy runs every one of them, every time, on every\n * stage, production included. That is only safe because a seed is an\n * idempotent upsert; the docs say so, and nothing here can check it.\n */\n\nimport type { TargetEvent } from './types';\n\n/** A seed of a deployed stage failed; the release stopped before any app. */\nexport class DeploySeedsFailed extends Error {\n\tconstructor(\n\t\treadonly stage: string,\n\t\t/** The construct whose seed failed: `Database`. */\n\t\treadonly construct: string,\n\t\t/** The seed file, by name: `001_roles`. */\n\t\treadonly seed: string,\n\t\toverride readonly cause: unknown,\n\t) {\n\t\tsuper(\n\t\t\t`Seeding \"${stage}\" failed, so no app was released: ${construct}'s seed ` +\n\t\t\t\t`'${seed}' failed — ${causeMessage(cause)}. Its writes were rolled ` +\n\t\t\t\t'back; the migrations and the seeds before it stay applied. Seeds run ' +\n\t\t\t\t'on every deploy, so each must be an idempotent upsert: fix it and ' +\n\t\t\t\t'deploy again.',\n\t\t);\n\t\tthis.name = 'DeploySeedsFailed';\n\t}\n}\n\n/**\n * What went wrong underneath: a `SeedFailed`'s own cause (the database's\n * error), or — from a sandbox, where errors arrive as data — the same.\n */\nfunction causeMessage(cause: unknown): string {\n\tconst message = (value: unknown): string | undefined =>\n\t\tvalue && typeof value === 'object' && 'message' in value\n\t\t\t? String(value.message)\n\t\t\t: undefined;\n\tconst inner =\n\t\tcause && typeof cause === 'object' && 'cause' in cause\n\t\t\t? message(cause.cause)\n\t\t\t: undefined;\n\treturn inner ?? message(cause) ?? String(cause);\n}\n\n/** One construct's migrations, as a target reports them. */\nexport interface MigrationsReport {\n\tconstruct: string;\n\tfolder: string;\n\tapplied: readonly string[];\n}\n\n/** One construct's seeds, as a target reports them. */\nexport interface SeedsReport {\n\tconstruct: string;\n\tfolder: string;\n\tseeded: readonly string[];\n}\n\n/**\n * Say what a deploy's migrations and seeds did: a line per construct with\n * something applied or run — `🌱 db/database/seeds: ran 2`, then each seed —\n * and a `migration.applied` or `seed.ran` event beside it.\n */\nexport function reportDatabaseRuns(\n\tmigrations: readonly MigrationsReport[],\n\tseeds: readonly SeedsReport[],\n\tlog: (line: string) => void,\n\temit: (event: TargetEvent) => void,\n): void {\n\tfor (const { construct, folder, applied } of migrations) {\n\t\tif (applied.length === 0) continue;\n\t\tlog(`🗄️ ${folder}: applied ${applied.length}`);\n\t\tfor (const name of applied) log(` ✓ ${name}`);\n\t\temit({\n\t\t\ttype: 'migration.applied',\n\t\t\tconstruct,\n\t\t\tfolder,\n\t\t\tapplied: [...applied],\n\t\t});\n\t}\n\tfor (const { construct, folder, seeded } of seeds) {\n\t\tif (seeded.length === 0) continue;\n\t\tlog(`🌱 ${folder}: ran ${seeded.length}`);\n\t\tfor (const name of seeded) log(` ✓ ${name}`);\n\t\temit({ type: 'seed.ran', construct, folder, seeded: [...seeded] });\n\t}\n}\n\n/** What a dry run lists: the seeds a deploy would run, construct by construct. */\nexport function reportPlannedSeeds(\n\tplanned: readonly { folder: string; seeds: readonly string[] }[],\n\tlog: (line: string) => void,\n): void {\n\tfor (const { folder, seeds } of planned) {\n\t\tlog(`🌱 ${folder}: would run ${seeds.length} (${seeds.join(', ')})`);\n\t}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GACA;GACA,SAAS,CAAC,GAAG,OAAO;EACrB,CAAC;CACF;CACA,KAAK,MAAM,EAAE,WAAW,QAAQ,YAAY,OAAO;EAClD,IAAI,OAAO,WAAW,GAAG;EACzB,IAAI,MAAM,OAAO,QAAQ,OAAO,QAAQ;EACxC,KAAK,MAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM;EAC7C,KAAK;GAAE,MAAM;GAAY;GAAW;GAAQ,QAAQ,CAAC,GAAG,MAAM;EAAE,CAAC;CAClE;AACD;;AAGA,SAAgB,mBACf,SACA,KACO;CACP,KAAK,MAAM,EAAE,QAAQ,WAAW,SAC/B,IAAI,MAAM,OAAO,cAAc,MAAM,OAAO,IAAI,MAAM,KAAK,IAAI,EAAE,EAAE;AAErE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"seeds-y1rzXlAc.mjs","names":[],"sources":["../src/deploy/journal.ts","../src/deploy/actor.ts","../src/deploy/dnsResources.ts","../src/target/seeds.ts"],"sourcesContent":["/**\n * A deploy's record of what it is creating, written as it goes.\n *\n * Deploy used to write state once, after every app had deployed, so a run that\n * failed half way lost the ids of everything it had created and the next run\n * fell back to finding them by name — or made them again. The journal writes\n * through the stage's `StateStore` after every resource instead:\n *\n * 1. `pending`, before the call that creates it — \"this may now exist\";\n * 2. `ready` with the target's id, once the call has returned.\n *\n * A run that meets a `pending` record looks the resource up before it creates\n * anything, so a run killed between the create and the record adopts what the\n * dead run made instead of making a second one. Every write is conditional on\n * the version the journal last wrote, so a writer that skipped the stage's\n * lock raises `StateVersionConflict` here rather than being overwritten.\n */\n\nimport type { ResourceRecord, StateStore, StateVersion } from './StateStore';\nimport type { StageState } from './state';\n\n/** One resource, as the journal keys and describes it. */\nexport interface JournalEntry {\n\t/** `<type>:<name>`, unique within the stage — `application:api`. */\n\tkey: string;\n\ttype: string;\n\t/** What a later run needs to find it again — its name, usually. */\n\tdata?: Record<string, unknown>;\n}\n\n/** How to get at one kind of resource on the target. */\nexport interface ResourceSteps<T> {\n\t/** By the id a `ready` record holds; `null` when the target lost it. */\n\tget?: (id: string) => Promise<T | null | undefined>;\n\t/** By what identifies it otherwise — its name, in its environment. */\n\tfind: () => Promise<T | null | undefined>;\n\tcreate: () => Promise<T>;\n\tid: (resource: T) => string;\n}\n\nexport interface Ensured<T> {\n\tresource: T;\n\t/**\n\t * - `recorded`: the id in a `ready` record still resolves\n\t * - `resumed`: a `pending` record's resource was found — a run died\n\t * between creating it and recording it\n\t * - `found`: it existed, unrecorded\n\t * - `created`: it did not exist\n\t */\n\tvia: 'recorded' | 'resumed' | 'found' | 'created';\n\t/** The recorded id that no longer resolved, if there was one. */\n\tstaleId?: string;\n}\n\nexport class DeployJournal<S extends StageState = StageState> {\n\tprivate constructor(\n\t\tprivate readonly store: StateStore,\n\t\treadonly stage: string,\n\t\t/** The stage's state, mutated by the deploy and written by `save`. */\n\t\treadonly state: S,\n\t\tprivate resources: Record<string, ResourceRecord>,\n\t\tprivate version: StateVersion,\n\t\t/** Whether the stage had state before this run. */\n\t\treadonly existed: boolean,\n\t) {}\n\n\t/**\n\t * The stage's journal — its stored state, or `initial` written as the\n\t * stage's first state, so there is somewhere to record the very first\n\t * resource before it is created.\n\t *\n\t * `adopt` turns a stored state into the shape the caller works on — a\n\t * Dokploy deploy of a stage compose deployed keeps its releases and starts\n\t * its Dokploy ids afresh. Without it, the stored state is used as it is.\n\t */\n\tstatic async open(\n\t\tstore: StateStore,\n\t\tstage: string,\n\t\tinitial: () => StageState,\n\t): Promise<DeployJournal<StageState>>;\n\tstatic async open<S extends StageState>(\n\t\tstore: StateStore,\n\t\tstage: string,\n\t\tinitial: () => S,\n\t\tadopt: (stored: StageState) => S,\n\t): Promise<DeployJournal<S>>;\n\tstatic async open(\n\t\tstore: StateStore,\n\t\tstage: string,\n\t\tinitial: () => StageState,\n\t\tadopt: (stored: StageState) => StageState = (stored) => stored,\n\t): Promise<DeployJournal<StageState>> {\n\t\tconst stored = await store.read(stage);\n\t\tif (stored) {\n\t\t\treturn new DeployJournal(\n\t\t\t\tstore,\n\t\t\t\tstage,\n\t\t\t\tadopt(stored.state),\n\t\t\t\tstored.resources,\n\t\t\t\tstored.version,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t}\n\n\t\tconst state = initial();\n\t\tconst version = await store.write(stage, state, { expectedVersion: null });\n\t\treturn new DeployJournal(store, stage, state, {}, version, false);\n\t}\n\n\trecord(key: string): ResourceRecord | undefined {\n\t\treturn this.resources[key];\n\t}\n\n\t/** The keys a previous run marked `pending` and never saw created. */\n\tunfinished(): string[] {\n\t\treturn Object.values(this.resources)\n\t\t\t.filter((record) => record.status === 'pending')\n\t\t\t.map((record) => record.key);\n\t}\n\n\t/** Records that `entry` is about to be created. */\n\tasync pending(entry: JournalEntry): Promise<void> {\n\t\tawait this.put({ ...entry, status: 'pending' });\n\t}\n\n\t/**\n\t * Records `entry` as existing with `id`; a no-op if it already is, with\n\t * the same data.\n\t */\n\tasync ready(entry: JournalEntry, id: string): Promise<void> {\n\t\tconst current = this.resources[entry.key];\n\t\tif (\n\t\t\tcurrent?.status === 'ready' &&\n\t\t\tcurrent.id === id &&\n\t\t\tJSON.stringify(current.data) === JSON.stringify(entry.data)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tawait this.put({ ...entry, status: 'ready', id });\n\t}\n\n\t/**\n\t * The resource `entry` names: by its recorded id, else by looking it up,\n\t * else created — with `pending` written before the create and `ready`\n\t * after, so a run that dies in between leaves a record the next run\n\t * resolves by looking the resource up rather than creating another.\n\t */\n\tasync ensure<T>(\n\t\tentry: JournalEntry,\n\t\tsteps: ResourceSteps<T>,\n\t): Promise<Ensured<T>> {\n\t\tconst record = this.resources[entry.key];\n\t\tlet staleId: string | undefined;\n\n\t\tif (record?.status === 'ready' && record.id && steps.get) {\n\t\t\tconst known = await steps.get(record.id);\n\t\t\tif (known) {\n\t\t\t\tawait this.ready(entry, steps.id(known));\n\t\t\t\treturn { resource: known, via: 'recorded' };\n\t\t\t}\n\t\t\tstaleId = record.id;\n\t\t}\n\n\t\tconst existing = await steps.find();\n\t\tif (existing) {\n\t\t\tawait this.ready(entry, steps.id(existing));\n\t\t\treturn {\n\t\t\t\tresource: existing,\n\t\t\t\tvia: record?.status === 'pending' ? 'resumed' : 'found',\n\t\t\t\t...(staleId ? { staleId } : {}),\n\t\t\t};\n\t\t}\n\n\t\tawait this.pending(entry);\n\t\tconst created = await steps.create();\n\t\tawait this.ready(entry, steps.id(created));\n\t\treturn {\n\t\t\tresource: created,\n\t\t\tvia: 'created',\n\t\t\t...(staleId ? { staleId } : {}),\n\t\t};\n\t}\n\n\t/** Removes `key`'s record — a resource that no longer exists. */\n\tasync forget(key: string): Promise<void> {\n\t\tif (!(key in this.resources)) return;\n\t\tthis.version = await this.store.deleteResource(this.stage, key, {\n\t\t\texpectedVersion: this.version,\n\t\t});\n\t\tconst { [key]: _removed, ...resources } = this.resources;\n\t\tthis.resources = resources;\n\t}\n\n\t/** Every record, as the journal last wrote or read it. */\n\trecords(): Record<string, ResourceRecord> {\n\t\treturn this.resources;\n\t}\n\n\t/** Writes the stage's state, keeping its resource records. */\n\tasync save(): Promise<void> {\n\t\tthis.state.lastDeployedAt = new Date().toISOString();\n\t\tthis.version = await this.store.write(this.stage, this.state, {\n\t\t\texpectedVersion: this.version,\n\t\t});\n\t}\n\n\tprivate async put(record: Omit<ResourceRecord, 'updatedAt'>): Promise<void> {\n\t\tthis.version = await this.store.putResource(this.stage, record, {\n\t\t\texpectedVersion: this.version,\n\t\t});\n\t\tthis.resources = {\n\t\t\t...this.resources,\n\t\t\t[record.key]: { ...record, updatedAt: new Date().toISOString() },\n\t\t};\n\t}\n}\n","/**\n * Who wrote a stage's deploy state: a GitHub Actions run, or a person at a\n * machine. Recorded on every state write (`updatedBy`), on every resource\n * record and on every release (`releasedBy`), so \"who put this here\" has an\n * answer that does not depend on anyone's memory.\n */\n\nimport { hostname, userInfo } from 'node:os';\n\n/** A GitHub Actions run: the account that triggered it and the run's page. */\nexport interface GithubActor {\n\tkind: 'github';\n\t/** `GITHUB_ACTOR` — the account that triggered the run. */\n\tactor: string;\n\t/** `<server>/<repository>/actions/runs/<run id>` */\n\trun: string;\n\t/** `GITHUB_WORKFLOW` — the workflow's name. */\n\tworkflow?: string;\n}\n\n/** A person at a machine. */\nexport interface LocalActor {\n\tkind: 'local';\n\tuser: string;\n\thost: string;\n}\n\nexport type Actor = GithubActor | LocalActor;\n\n/** Whether `env` is a CI job — GitHub Actions or any runner that sets `CI`. */\nexport function isCi(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn env.GITHUB_ACTIONS === 'true' || env.CI === 'true';\n}\n\n/** Who this process is writing as. */\nexport function currentActor(env: NodeJS.ProcessEnv = process.env): Actor {\n\tif (env.GITHUB_ACTIONS === 'true') {\n\t\tconst server = env.GITHUB_SERVER_URL ?? 'https://github.com';\n\t\treturn {\n\t\t\tkind: 'github',\n\t\t\tactor: env.GITHUB_ACTOR ?? 'unknown',\n\t\t\trun: `${server}/${env.GITHUB_REPOSITORY ?? 'unknown'}/actions/runs/${env.GITHUB_RUN_ID ?? 'unknown'}`,\n\t\t\t...(env.GITHUB_WORKFLOW ? { workflow: env.GITHUB_WORKFLOW } : {}),\n\t\t};\n\t}\n\n\tlet user = 'unknown';\n\ttry {\n\t\tuser = userInfo().username;\n\t} catch {\n\t\t// No passwd entry (a container running as an arbitrary uid).\n\t}\n\treturn { kind: 'local', user, host: hostname() };\n}\n\n/** `octocat (deploy, https://github.com/…/runs/1)` or `ada@laptop`. */\nexport function describeActor(actor: Actor | undefined): string {\n\tif (!actor) return 'unknown';\n\tif (actor.kind === 'local') return `${actor.user}@${actor.host}`;\n\treturn `${actor.actor} (${actor.workflow ? `${actor.workflow}, ` : ''}${actor.run})`;\n}\n","/**\n * DNS records gkm wrote for a stage, as resource records in its deploy state.\n *\n * Each is `dns-record:<fqdn>:<type>` — `dns-record:api.example.com:A` — with\n * `id` `<fqdn> <type>` and the record's value in `data`. Every deploy's DNS\n * step writes through here — `gkm deploy` and `gkm compose` alike — so each\n * record has one key, whoever wrote it.\n */\n\nimport type { DeployJournal } from './journal';\nimport type { ResourceInput, ResourceRecord } from './StateStore';\n\n/** The resource type of a DNS record gkm wrote. */\nexport const DNS_RECORD_RESOURCE = 'dns-record';\n\n/** A DNS record as gkm writes it. */\nexport interface DnsResourceRecord {\n\t/** The `dns` domain it is under: `example.com`. */\n\tdomain: string;\n\t/** Relative to the domain, as providers take it: `api`, `@`. */\n\tname: string;\n\ttype: string;\n\tvalue: string;\n\tttl: number;\n\t/**\n\t * The domain's provider — `godaddy`, `route53`, … Absent on a record\n\t * migrated from a v2 state, which did not say.\n\t */\n\tprovider?: string;\n}\n\n/** `data` of a `dns-record` resource. */\nexport type DnsResourceData = Omit<DnsResourceRecord, 'type'>;\n\n/** A record's full name: `api.example.com`, or the domain for `@`. */\nexport function dnsRecordFqdn(domain: string, name: string): string {\n\treturn name === '@' || name === '' ? domain : `${name}.${domain}`;\n}\n\n/** `dns-record:<fqdn>:<type>` */\nexport function dnsResourceKey(fqdn: string, type: string): string {\n\treturn `${DNS_RECORD_RESOURCE}:${fqdn.toLowerCase()}:${type.toUpperCase()}`;\n}\n\n/** The resource record a written DNS record is kept as. */\nexport function dnsRecordResource(record: DnsResourceRecord): ResourceInput {\n\tconst fqdn = dnsRecordFqdn(record.domain, record.name).toLowerCase();\n\tconst type = record.type.toUpperCase();\n\tconst data: DnsResourceData = {\n\t\tdomain: record.domain,\n\t\tname: record.name,\n\t\tvalue: record.value,\n\t\tttl: record.ttl,\n\t\t...(record.provider ? { provider: record.provider } : {}),\n\t};\n\treturn {\n\t\tkey: dnsResourceKey(fqdn, type),\n\t\ttype: DNS_RECORD_RESOURCE,\n\t\tid: `${fqdn} ${type}`,\n\t\tstatus: 'ready',\n\t\tdata,\n\t};\n}\n\n/** Records that gkm wrote `record` — or updates the value it holds. */\nexport async function recordDnsResource(\n\tjournal: DeployJournal,\n\trecord: DnsResourceRecord,\n): Promise<void> {\n\tconst { key, type, id, data } = dnsRecordResource(record);\n\tawait journal.ready({ key, type, ...(data ? { data } : {}) }, id!);\n}\n\n/** Forgets a DNS record gkm deleted. */\nexport async function forgetDnsResource(\n\tjournal: DeployJournal,\n\trecord: Pick<DnsResourceRecord, 'domain' | 'name' | 'type'>,\n): Promise<void> {\n\tawait journal.forget(\n\t\tdnsResourceKey(dnsRecordFqdn(record.domain, record.name), record.type),\n\t);\n}\n\n/** One change a DNS step made, as `applyStackDns` reports it. */\nexport interface AppliedDnsChange {\n\tdomain: string;\n\tname: string;\n\ttype: string;\n\taction: string;\n\tvalue?: string;\n\tttl?: number;\n}\n\n/**\n * The changes a DNS step made, kept: what it created, updated or wrote is\n * recorded, what it deleted is forgotten. A record it found already right is\n * recorded only if gkm wrote it before; one it left to a person is not.\n */\nexport async function recordDnsChanges(\n\tjournal: DeployJournal,\n\tchanges: readonly AppliedDnsChange[],\n\tproviderOf: (domain: string) => string | undefined,\n): Promise<void> {\n\tfor (const change of changes) {\n\t\tif (change.action === 'delete') {\n\t\t\tawait forgetDnsResource(journal, change);\n\t\t\tcontinue;\n\t\t}\n\t\tconst written =\n\t\t\tchange.action === 'create' ||\n\t\t\tchange.action === 'update' ||\n\t\t\tchange.action === 'write';\n\t\tconst known =\n\t\t\tchange.action === 'unchanged' &&\n\t\t\tjournal.record(\n\t\t\t\tdnsResourceKey(dnsRecordFqdn(change.domain, change.name), change.type),\n\t\t\t) !== undefined;\n\t\tif ((!written && !known) || change.value === undefined) continue;\n\t\tconst provider = providerOf(change.domain);\n\t\tawait recordDnsResource(journal, {\n\t\t\tdomain: change.domain,\n\t\t\tname: change.name,\n\t\t\ttype: change.type,\n\t\t\tvalue: change.value,\n\t\t\tttl: change.ttl ?? 0,\n\t\t\t...(provider ? { provider } : {}),\n\t\t});\n\t}\n}\n\n/** Every DNS record gkm wrote for the stage, from its resource records. */\nexport function dnsResources(\n\tresources: Record<string, ResourceRecord>,\n): (DnsResourceRecord & { fqdn: string })[] {\n\treturn Object.values(resources)\n\t\t.filter((record) => record.type === DNS_RECORD_RESOURCE)\n\t\t.map((record) => {\n\t\t\tconst data = (record.data ?? {}) as DnsResourceData;\n\t\t\tconst [fqdn = '', type = ''] = (record.id ?? '').split(' ');\n\t\t\treturn { ...data, type, fqdn };\n\t\t})\n\t\t.sort(\n\t\t\t(a, b) => a.fqdn.localeCompare(b.fqdn) || a.type.localeCompare(b.type),\n\t\t);\n}\n","/**\n * A deployed stage's seeds: what every server target runs after its\n * migrations and before any app starts.\n *\n * Seeds are reference data — roles, permissions, plans — kept current by\n * being run again, so a deploy runs every one of them, every time, on every\n * stage, production included. That is only safe because a seed is an\n * idempotent upsert; the docs say so, and nothing here can check it.\n */\n\nimport type { TargetEvent } from './types';\n\n/** A seed of a deployed stage failed; the release stopped before any app. */\nexport class DeploySeedsFailed extends Error {\n\tconstructor(\n\t\treadonly stage: string,\n\t\t/** The construct whose seed failed: `Database`. */\n\t\treadonly construct: string,\n\t\t/** The seed file, by name: `001_roles`. */\n\t\treadonly seed: string,\n\t\toverride readonly cause: unknown,\n\t) {\n\t\tsuper(\n\t\t\t`Seeding \"${stage}\" failed, so no app was released: ${construct}'s seed ` +\n\t\t\t\t`'${seed}' failed — ${causeMessage(cause)}. Its writes were rolled ` +\n\t\t\t\t'back; the migrations and the seeds before it stay applied. Seeds run ' +\n\t\t\t\t'on every deploy, so each must be an idempotent upsert: fix it and ' +\n\t\t\t\t'deploy again.',\n\t\t);\n\t\tthis.name = 'DeploySeedsFailed';\n\t}\n}\n\n/**\n * What went wrong underneath: a `SeedFailed`'s own cause (the database's\n * error), or — from a sandbox, where errors arrive as data — the same.\n */\nfunction causeMessage(cause: unknown): string {\n\tconst message = (value: unknown): string | undefined =>\n\t\tvalue && typeof value === 'object' && 'message' in value\n\t\t\t? String(value.message)\n\t\t\t: undefined;\n\tconst inner =\n\t\tcause && typeof cause === 'object' && 'cause' in cause\n\t\t\t? message(cause.cause)\n\t\t\t: undefined;\n\treturn inner ?? message(cause) ?? String(cause);\n}\n\n/** One construct's migrations, as a target reports them. */\nexport interface MigrationsReport {\n\tconstruct: string;\n\tfolder: string;\n\tapplied: readonly string[];\n}\n\n/** One construct's seeds, as a target reports them. */\nexport interface SeedsReport {\n\tconstruct: string;\n\tfolder: string;\n\tseeded: readonly string[];\n}\n\n/**\n * Say what a deploy's migrations and seeds did: a line per construct with\n * something applied or run — `🌱 db/database/seeds: ran 2`, then each seed —\n * and a `migration.applied` or `seed.ran` event beside it.\n */\nexport function reportDatabaseRuns(\n\tmigrations: readonly MigrationsReport[],\n\tseeds: readonly SeedsReport[],\n\tlog: (line: string) => void,\n\temit: (event: TargetEvent) => void,\n): void {\n\tfor (const { construct, folder, applied } of migrations) {\n\t\tif (applied.length === 0) continue;\n\t\tlog(`🗄️ ${folder}: applied ${applied.length}`);\n\t\tfor (const name of applied) log(` ✓ ${name}`);\n\t\temit({\n\t\t\ttype: 'migration.applied',\n\t\t\tconstruct,\n\t\t\tfolder,\n\t\t\tapplied: [...applied],\n\t\t});\n\t}\n\tfor (const { construct, folder, seeded } of seeds) {\n\t\tif (seeded.length === 0) continue;\n\t\tlog(`🌱 ${folder}: ran ${seeded.length}`);\n\t\tfor (const name of seeded) log(` ✓ ${name}`);\n\t\temit({ type: 'seed.ran', construct, folder, seeded: [...seeded] });\n\t}\n}\n\n/** What a dry run lists: the seeds a deploy would run, construct by construct. */\nexport function reportPlannedSeeds(\n\tplanned: readonly { folder: string; seeds: readonly string[] }[],\n\tlog: (line: string) => void,\n): void {\n\tfor (const { folder, seeds } of planned) {\n\t\tlog(`🌱 ${folder}: would run ${seeds.length} (${seeds.join(', ')})`);\n\t}\n}\n"],"mappings":";;AAsDA,IAAa,gBAAb,MAAa,cAAiD;CAE3C;CACR;CAEA;CACD;CACA;CAEC;CARV,YACC,OACA,OAEA,OACA,WACA,SAEA,SACC;EARgB,KAAA,QAAA;EACR,KAAA,QAAA;EAEA,KAAA,QAAA;EACD,KAAA,YAAA;EACA,KAAA,UAAA;EAEC,KAAA,U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