@geekmidas/cli 10.0.0-alpha.18 → 10.0.0-alpha.181

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 (448) hide show
  1. package/README.md +323 -380
  2. package/bin/adjacent-tsconfig.mjs +46 -8
  3. package/bin/gkm.mjs +11 -3
  4. package/bin/owning-tsconfig-jsx-register.mjs +18 -0
  5. package/bin/owning-tsconfig-jsx.mjs +108 -0
  6. package/dist/EndpointGenerator-CBKH87_b.mjs +1043 -0
  7. package/dist/EndpointGenerator-CBKH87_b.mjs.map +1 -0
  8. package/dist/EndpointGenerator-iyA3HkOH.cjs +1102 -0
  9. package/dist/EndpointGenerator-iyA3HkOH.cjs.map +1 -0
  10. package/dist/LegacyStateStore-DvufVJjQ.cjs +124 -0
  11. package/dist/LegacyStateStore-DvufVJjQ.cjs.map +1 -0
  12. package/dist/LegacyStateStore-p-_Z8ucw.mjs +124 -0
  13. package/dist/LegacyStateStore-p-_Z8ucw.mjs.map +1 -0
  14. package/dist/LocalStateStore-BKAi5XsN.mjs +167 -0
  15. package/dist/LocalStateStore-BKAi5XsN.mjs.map +1 -0
  16. package/dist/LocalStateStore-DLDD6udB.cjs +178 -0
  17. package/dist/LocalStateStore-DLDD6udB.cjs.map +1 -0
  18. package/dist/OpenApiTsGenerator-CoVA3Ykv.mjs +534 -0
  19. package/dist/OpenApiTsGenerator-CoVA3Ykv.mjs.map +1 -0
  20. package/dist/OpenApiTsGenerator-vy-fOJgs.cjs +539 -0
  21. package/dist/OpenApiTsGenerator-vy-fOJgs.cjs.map +1 -0
  22. package/dist/S3StateStore-C8thID2w.mjs +223 -0
  23. package/dist/S3StateStore-C8thID2w.mjs.map +1 -0
  24. package/dist/S3StateStore-J3FztlVC.cjs +222 -0
  25. package/dist/S3StateStore-J3FztlVC.cjs.map +1 -0
  26. package/dist/SSMStateStore-0TQsme40.mjs +205 -0
  27. package/dist/SSMStateStore-0TQsme40.mjs.map +1 -0
  28. package/dist/SSMStateStore-DhkkSF1D.cjs +204 -0
  29. package/dist/SSMStateStore-DhkkSF1D.cjs.map +1 -0
  30. package/dist/SubscriberGenerator-B3jHf26s.mjs +787 -0
  31. package/dist/SubscriberGenerator-B3jHf26s.mjs.map +1 -0
  32. package/dist/SubscriberGenerator-JhwVlWBS.cjs +852 -0
  33. package/dist/SubscriberGenerator-JhwVlWBS.cjs.map +1 -0
  34. package/dist/add-DWCzdPLz.mjs +711 -0
  35. package/dist/add-DWCzdPLz.mjs.map +1 -0
  36. package/dist/add-gs34ewLG.cjs +713 -0
  37. package/dist/add-gs34ewLG.cjs.map +1 -0
  38. package/dist/appPorts-BoXMwolc.mjs +249 -0
  39. package/dist/appPorts-BoXMwolc.mjs.map +1 -0
  40. package/dist/appPorts-IW-OZmRi.cjs +296 -0
  41. package/dist/appPorts-IW-OZmRi.cjs.map +1 -0
  42. package/dist/apps-C27qrbEe.cjs +5174 -0
  43. package/dist/apps-C27qrbEe.cjs.map +1 -0
  44. package/dist/apps-D2oTQasd.mjs +4650 -0
  45. package/dist/apps-D2oTQasd.mjs.map +1 -0
  46. package/dist/aws-BXfiWNbi.cjs +108 -0
  47. package/dist/aws-BXfiWNbi.cjs.map +1 -0
  48. package/dist/aws-BjvSTTcE.mjs +97 -0
  49. package/dist/aws-BjvSTTcE.mjs.map +1 -0
  50. package/dist/awsStore-BYYCmXiq.mjs +121 -0
  51. package/dist/awsStore-BYYCmXiq.mjs.map +1 -0
  52. package/dist/awsStore-DKQUElJL.cjs +138 -0
  53. package/dist/awsStore-DKQUElJL.cjs.map +1 -0
  54. package/dist/{backup-provisioner-DIVCbfee.mjs → backup-provisioner-C8DnCmxK.mjs} +2 -2
  55. package/dist/backup-provisioner-C8DnCmxK.mjs.map +1 -0
  56. package/dist/{backup-provisioner-BmhIO_Yr.cjs → backup-provisioner-oDEsPj02.cjs} +2 -2
  57. package/dist/backup-provisioner-oDEsPj02.cjs.map +1 -0
  58. package/dist/backups/runner.cjs +519 -0
  59. package/dist/backups/runner.cjs.map +1 -0
  60. package/dist/backups/runner.d.cts +102 -0
  61. package/dist/backups/runner.d.cts.map +1 -0
  62. package/dist/backups/runner.d.mts +102 -0
  63. package/dist/backups/runner.d.mts.map +1 -0
  64. package/dist/backups/runner.mjs +506 -0
  65. package/dist/backups/runner.mjs.map +1 -0
  66. package/dist/{bundler-mwH7WOb1.mjs → bundler-CbT4y4H_.mjs} +68 -15
  67. package/dist/bundler-CbT4y4H_.mjs.map +1 -0
  68. package/dist/{bundler-mjqGAvu1.cjs → bundler-DGeOugof.cjs} +67 -14
  69. package/dist/bundler-DGeOugof.cjs.map +1 -0
  70. package/dist/cli-C-jUNT69.cjs +80 -0
  71. package/dist/cli-C-jUNT69.cjs.map +1 -0
  72. package/dist/cli-DKEJryS7.mjs +80 -0
  73. package/dist/cli-DKEJryS7.mjs.map +1 -0
  74. package/dist/clientTelemetry-BAwj6MOf.d.cts +10 -0
  75. package/dist/clientTelemetry-BAwj6MOf.d.cts.map +1 -0
  76. package/dist/clientTelemetry-CvamPJj_.d.mts +10 -0
  77. package/dist/clientTelemetry-CvamPJj_.d.mts.map +1 -0
  78. package/dist/compose-BpnSP2x7.mjs +2434 -0
  79. package/dist/compose-BpnSP2x7.mjs.map +1 -0
  80. package/dist/compose-DJAaJEqL.cjs +2925 -0
  81. package/dist/compose-DJAaJEqL.cjs.map +1 -0
  82. package/dist/compose-DmtR2f0l.cjs +3564 -0
  83. package/dist/compose-DmtR2f0l.cjs.map +1 -0
  84. package/dist/compose-Glqs13is.mjs +3451 -0
  85. package/dist/compose-Glqs13is.mjs.map +1 -0
  86. package/dist/config-BODxZemw.d.mts +291 -0
  87. package/dist/config-BODxZemw.d.mts.map +1 -0
  88. package/dist/config-C3U5HulX.d.cts +291 -0
  89. package/dist/config-C3U5HulX.d.cts.map +1 -0
  90. package/dist/config.cjs +457 -9
  91. package/dist/config.cjs.map +1 -0
  92. package/dist/config.d.cts +4 -117
  93. package/dist/config.d.mts +4 -117
  94. package/dist/config.mjs +441 -3
  95. package/dist/config.mjs.map +1 -0
  96. package/dist/credentialSchemas-D_85KW2k.mjs +236 -0
  97. package/dist/credentialSchemas-D_85KW2k.mjs.map +1 -0
  98. package/dist/credentialSchemas-DjK6xKMk.cjs +271 -0
  99. package/dist/credentialSchemas-DjK6xKMk.cjs.map +1 -0
  100. package/dist/databases-CV22HzrI.mjs +588 -0
  101. package/dist/databases-CV22HzrI.mjs.map +1 -0
  102. package/dist/databases-DwYYH2mX.cjs +703 -0
  103. package/dist/databases-DwYYH2mX.cjs.map +1 -0
  104. package/dist/dbTunnel-DUudiQWj.cjs +154 -0
  105. package/dist/dbTunnel-DUudiQWj.cjs.map +1 -0
  106. package/dist/dbTunnel-KgbAh2v1.mjs +154 -0
  107. package/dist/dbTunnel-KgbAh2v1.mjs.map +1 -0
  108. package/dist/define-BfrNaY82.mjs +106 -0
  109. package/dist/define-BfrNaY82.mjs.map +1 -0
  110. package/dist/define-zKgLY65H.cjs +153 -0
  111. package/dist/define-zKgLY65H.cjs.map +1 -0
  112. package/dist/deploy/public.cjs +211 -0
  113. package/dist/deploy/public.cjs.map +1 -0
  114. package/dist/deploy/public.d.cts +659 -0
  115. package/dist/deploy/public.d.cts.map +1 -0
  116. package/dist/deploy/public.d.mts +659 -0
  117. package/dist/deploy/public.d.mts.map +1 -0
  118. package/dist/deploy/public.mjs +144 -0
  119. package/dist/deploy/public.mjs.map +1 -0
  120. package/dist/deploy/sniffer-envparser-worker.cjs +54 -0
  121. package/dist/deploy/sniffer-envparser-worker.cjs.map +1 -0
  122. package/dist/deploy/sniffer-envparser-worker.d.cts +1 -0
  123. package/dist/deploy/sniffer-envparser-worker.d.mts +1 -0
  124. package/dist/deploy/sniffer-envparser-worker.mjs +55 -0
  125. package/dist/deploy/sniffer-envparser-worker.mjs.map +1 -0
  126. package/dist/deploy/sniffer-hooks.cjs +1 -1
  127. package/dist/deploy/sniffer-hooks.mjs +1 -1
  128. package/dist/deploy/sniffer-loader.cjs +2 -2
  129. package/dist/deploy/sniffer-loader.mjs +1 -1
  130. package/dist/deploy/sniffer-routes-worker.cjs +2 -2
  131. package/dist/deploy/sniffer-routes-worker.mjs +1 -1
  132. package/dist/deploy-UkAiPzTp.mjs +3838 -0
  133. package/dist/deploy-UkAiPzTp.mjs.map +1 -0
  134. package/dist/deploy-ycRCutW9.cjs +3894 -0
  135. package/dist/deploy-ycRCutW9.cjs.map +1 -0
  136. package/dist/destroy-Cq5Un0kf.mjs +789 -0
  137. package/dist/destroy-Cq5Un0kf.mjs.map +1 -0
  138. package/dist/destroy-DzRzQcAR.cjs +790 -0
  139. package/dist/destroy-DzRzQcAR.cjs.map +1 -0
  140. package/dist/discover-Dfmn6HQ7.mjs +940 -0
  141. package/dist/discover-Dfmn6HQ7.mjs.map +1 -0
  142. package/dist/discover-OXczlq08.cjs +1085 -0
  143. package/dist/discover-OXczlq08.cjs.map +1 -0
  144. package/dist/dns-7zc-Mc9k.cjs +2257 -0
  145. package/dist/dns-7zc-Mc9k.cjs.map +1 -0
  146. package/dist/dns-dl7WUWmB.mjs +1820 -0
  147. package/dist/dns-dl7WUWmB.mjs.map +1 -0
  148. package/dist/docker-BDqp9Pfn.cjs +1798 -0
  149. package/dist/docker-BDqp9Pfn.cjs.map +1 -0
  150. package/dist/docker-MjMWQSEN.mjs +1649 -0
  151. package/dist/docker-MjMWQSEN.mjs.map +1 -0
  152. package/dist/dokploy-B0xtYCzY.mjs +38 -0
  153. package/dist/dokploy-B0xtYCzY.mjs.map +1 -0
  154. package/dist/dokploy-D-pBRnSV.cjs +38 -0
  155. package/dist/dokploy-D-pBRnSV.cjs.map +1 -0
  156. package/dist/drivers-BQRb3KsL.mjs +294 -0
  157. package/dist/drivers-BQRb3KsL.mjs.map +1 -0
  158. package/dist/drivers-DP7__dJX.cjs +377 -0
  159. package/dist/drivers-DP7__dJX.cjs.map +1 -0
  160. package/dist/eas-9danFNrJ.mjs +334 -0
  161. package/dist/eas-9danFNrJ.mjs.map +1 -0
  162. package/dist/eas-BJRA27vb.cjs +337 -0
  163. package/dist/eas-BJRA27vb.cjs.map +1 -0
  164. package/dist/emit-C4KSXOeS.mjs +153 -0
  165. package/dist/emit-C4KSXOeS.mjs.map +1 -0
  166. package/dist/emit-DiW0kbue.cjs +164 -0
  167. package/dist/emit-DiW0kbue.cjs.map +1 -0
  168. package/dist/encryption-0IiNCA3O.cjs +90 -0
  169. package/dist/encryption-0IiNCA3O.cjs.map +1 -0
  170. package/dist/encryption-ZDhvgGvu.mjs +89 -0
  171. package/dist/encryption-ZDhvgGvu.mjs.map +1 -0
  172. package/dist/engine-Csnr6XDu.mjs +3217 -0
  173. package/dist/engine-Csnr6XDu.mjs.map +1 -0
  174. package/dist/engine-DpjIgsGn.cjs +3330 -0
  175. package/dist/engine-DpjIgsGn.cjs.map +1 -0
  176. package/dist/errors-C9uIyIDt.mjs +27 -0
  177. package/dist/errors-C9uIyIDt.mjs.map +1 -0
  178. package/dist/errors-D1x8duqI.cjs +38 -0
  179. package/dist/errors-D1x8duqI.cjs.map +1 -0
  180. package/dist/github-Dej8EWxH.mjs +986 -0
  181. package/dist/github-Dej8EWxH.mjs.map +1 -0
  182. package/dist/github-HHxVur1m.cjs +987 -0
  183. package/dist/github-HHxVur1m.cjs.map +1 -0
  184. package/dist/googlePlay-DNrD-67X.mjs +931 -0
  185. package/dist/googlePlay-DNrD-67X.mjs.map +1 -0
  186. package/dist/googlePlay-NK1zgJJm.cjs +931 -0
  187. package/dist/googlePlay-NK1zgJJm.cjs.map +1 -0
  188. package/dist/iam-BzFyFf7T.mjs +442 -0
  189. package/dist/iam-BzFyFf7T.mjs.map +1 -0
  190. package/dist/iam-WIoKnLBp.cjs +521 -0
  191. package/dist/iam-WIoKnLBp.cjs.map +1 -0
  192. package/dist/{index-RCUizGxL.d.cts → index-BKgOlfK2.d.mts} +38 -14
  193. package/dist/index-BKgOlfK2.d.mts.map +1 -0
  194. package/dist/{index-B4H4XF7A.d.mts → index-zPzigXh-.d.cts} +38 -14
  195. package/dist/index-zPzigXh-.d.cts.map +1 -0
  196. package/dist/index.cjs +14502 -12767
  197. package/dist/index.cjs.map +1 -1
  198. package/dist/index.mjs +15137 -13400
  199. package/dist/index.mjs.map +1 -1
  200. package/dist/local-BW_VIsx0.cjs +241 -0
  201. package/dist/local-BW_VIsx0.cjs.map +1 -0
  202. package/dist/local-CVp-4wDb.mjs +224 -0
  203. package/dist/local-CVp-4wDb.mjs.map +1 -0
  204. package/dist/migrate-B8fq5egU.cjs +272 -0
  205. package/dist/migrate-B8fq5egU.cjs.map +1 -0
  206. package/dist/migrate-C8yCZ5P3.mjs +181 -0
  207. package/dist/migrate-C8yCZ5P3.mjs.map +1 -0
  208. package/dist/migrate-CkSq2f7k.mjs +267 -0
  209. package/dist/migrate-CkSq2f7k.mjs.map +1 -0
  210. package/dist/migrate-FOc2erAl.cjs +181 -0
  211. package/dist/migrate-FOc2erAl.cjs.map +1 -0
  212. package/dist/next.cjs +59 -0
  213. package/dist/next.cjs.map +1 -0
  214. package/dist/next.d.cts +44 -0
  215. package/dist/next.d.cts.map +1 -0
  216. package/dist/next.d.mts +44 -0
  217. package/dist/next.d.mts.map +1 -0
  218. package/dist/next.mjs +58 -0
  219. package/dist/next.mjs.map +1 -0
  220. package/dist/notes--JQyDHim.cjs +510 -0
  221. package/dist/notes--JQyDHim.cjs.map +1 -0
  222. package/dist/notes-DXl9qERh.mjs +409 -0
  223. package/dist/notes-DXl9qERh.mjs.map +1 -0
  224. package/dist/openapi.cjs +213 -7
  225. package/dist/openapi.cjs.map +1 -0
  226. package/dist/openapi.d.cts +27 -8
  227. package/dist/openapi.d.cts.map +1 -1
  228. package/dist/openapi.d.mts +27 -8
  229. package/dist/openapi.d.mts.map +1 -1
  230. package/dist/openapi.mjs +208 -2
  231. package/dist/openapi.mjs.map +1 -0
  232. package/dist/projectBucket-CGpcWqyY.cjs +263 -0
  233. package/dist/projectBucket-CGpcWqyY.cjs.map +1 -0
  234. package/dist/projectBucket-TigJy25c.mjs +222 -0
  235. package/dist/projectBucket-TigJy25c.mjs.map +1 -0
  236. package/dist/provider-BvjDbsTR.mjs +46 -0
  237. package/dist/provider-BvjDbsTR.mjs.map +1 -0
  238. package/dist/provider-DLhgo-mB.cjs +57 -0
  239. package/dist/provider-DLhgo-mB.cjs.map +1 -0
  240. package/dist/publish-BPfW3DWi.mjs +123 -0
  241. package/dist/publish-BPfW3DWi.mjs.map +1 -0
  242. package/dist/publish-D4pC6_G0.cjs +124 -0
  243. package/dist/publish-D4pC6_G0.cjs.map +1 -0
  244. package/dist/ready-BcV28QoW.mjs +375 -0
  245. package/dist/ready-BcV28QoW.mjs.map +1 -0
  246. package/dist/ready-ByQvw4-W.cjs +404 -0
  247. package/dist/ready-ByQvw4-W.cjs.map +1 -0
  248. package/dist/reconcile/public.cjs +3 -5
  249. package/dist/reconcile/public.d.cts +33 -89
  250. package/dist/reconcile/public.d.cts.map +1 -1
  251. package/dist/reconcile/public.d.mts +33 -89
  252. package/dist/reconcile/public.d.mts.map +1 -1
  253. package/dist/reconcile/public.mjs +3 -3
  254. package/dist/reconcile--I7V4Klj.mjs +34 -0
  255. package/dist/reconcile--I7V4Klj.mjs.map +1 -0
  256. package/dist/reconcile-CuCQBa5-.cjs +34 -0
  257. package/dist/reconcile-CuCQBa5-.cjs.map +1 -0
  258. package/dist/resolve-BmBR1vBr.cjs +316 -0
  259. package/dist/resolve-BmBR1vBr.cjs.map +1 -0
  260. package/dist/resolve-DA1kORng.mjs +263 -0
  261. package/dist/resolve-DA1kORng.mjs.map +1 -0
  262. package/dist/rollback-DlgQDX8m.mjs +136 -0
  263. package/dist/rollback-DlgQDX8m.mjs.map +1 -0
  264. package/dist/rollback-tsy4pyEp.cjs +165 -0
  265. package/dist/rollback-tsy4pyEp.cjs.map +1 -0
  266. package/dist/runtime-CaejlcZt.d.mts +82 -0
  267. package/dist/runtime-CaejlcZt.d.mts.map +1 -0
  268. package/dist/runtime-D3jD4Dvn.d.cts +82 -0
  269. package/dist/runtime-D3jD4Dvn.d.cts.map +1 -0
  270. package/dist/s3-BLEF-PQU.cjs +240 -0
  271. package/dist/s3-BLEF-PQU.cjs.map +1 -0
  272. package/dist/s3-DVYiOqWs.mjs +240 -0
  273. package/dist/s3-DVYiOqWs.mjs.map +1 -0
  274. package/dist/sandbox/config-worker.cjs +43 -0
  275. package/dist/sandbox/config-worker.cjs.map +1 -0
  276. package/dist/sandbox/config-worker.d.cts +1 -0
  277. package/dist/sandbox/config-worker.d.mts +1 -0
  278. package/dist/sandbox/config-worker.mjs +44 -0
  279. package/dist/sandbox/config-worker.mjs.map +1 -0
  280. package/dist/sandbox/credentials-worker.cjs +53 -0
  281. package/dist/sandbox/credentials-worker.cjs.map +1 -0
  282. package/dist/sandbox/credentials-worker.d.cts +1 -0
  283. package/dist/sandbox/credentials-worker.d.mts +1 -0
  284. package/dist/sandbox/credentials-worker.mjs +54 -0
  285. package/dist/sandbox/credentials-worker.mjs.map +1 -0
  286. package/dist/sandbox/discover-worker.cjs +47 -0
  287. package/dist/sandbox/discover-worker.cjs.map +1 -0
  288. package/dist/sandbox/discover-worker.d.cts +1 -0
  289. package/dist/sandbox/discover-worker.d.mts +1 -0
  290. package/dist/sandbox/discover-worker.mjs +48 -0
  291. package/dist/sandbox/discover-worker.mjs.map +1 -0
  292. package/dist/sandbox/migrate-worker.cjs +75 -0
  293. package/dist/sandbox/migrate-worker.cjs.map +1 -0
  294. package/dist/sandbox/migrate-worker.d.cts +1 -0
  295. package/dist/sandbox/migrate-worker.d.mts +1 -0
  296. package/dist/sandbox/migrate-worker.mjs +76 -0
  297. package/dist/sandbox/migrate-worker.mjs.map +1 -0
  298. package/dist/{workspace-CRD9YinV.cjs → schemas-BCwKKA42.mjs} +399 -1179
  299. package/dist/schemas-BCwKKA42.mjs.map +1 -0
  300. package/dist/{workspace-Bu3xNCej.mjs → schemas-BQ_v0lEX.cjs} +487 -982
  301. package/dist/schemas-BQ_v0lEX.cjs.map +1 -0
  302. package/dist/secretsManager-CjTo6CRq.mjs +113 -0
  303. package/dist/secretsManager-CjTo6CRq.mjs.map +1 -0
  304. package/dist/secretsManager-CvmBGjdM.cjs +124 -0
  305. package/dist/secretsManager-CvmBGjdM.cjs.map +1 -0
  306. package/dist/seeds-Bc3niNVb.cjs +382 -0
  307. package/dist/seeds-Bc3niNVb.cjs.map +1 -0
  308. package/dist/seeds-Ccn0Ru2T.mjs +299 -0
  309. package/dist/seeds-Ccn0Ru2T.mjs.map +1 -0
  310. package/dist/serverSetup-B_O65wLb.cjs +685 -0
  311. package/dist/serverSetup-B_O65wLb.cjs.map +1 -0
  312. package/dist/serverSetup-Dsy8drIb.mjs +685 -0
  313. package/dist/serverSetup-Dsy8drIb.mjs.map +1 -0
  314. package/dist/sniffer-Ckx4cr-o.cjs +1997 -0
  315. package/dist/sniffer-Ckx4cr-o.cjs.map +1 -0
  316. package/dist/sniffer-fBefNUuJ.mjs +1824 -0
  317. package/dist/sniffer-fBefNUuJ.mjs.map +1 -0
  318. package/dist/snsSubscriptions-BJ0LErGk.mjs +1010 -0
  319. package/dist/snsSubscriptions-BJ0LErGk.mjs.map +1 -0
  320. package/dist/snsSubscriptions-ChbFp-QP.cjs +1135 -0
  321. package/dist/snsSubscriptions-ChbFp-QP.cjs.map +1 -0
  322. package/dist/sst-BnuPeGyy.cjs +501 -0
  323. package/dist/sst-BnuPeGyy.cjs.map +1 -0
  324. package/dist/sst-Y7H_zaEZ.mjs +478 -0
  325. package/dist/sst-Y7H_zaEZ.mjs.map +1 -0
  326. package/dist/stack-BAipv5Js.cjs +1887 -0
  327. package/dist/stack-BAipv5Js.cjs.map +1 -0
  328. package/dist/stack-BHrGbsGA.mjs +1777 -0
  329. package/dist/stack-BHrGbsGA.mjs.map +1 -0
  330. package/dist/stage-BSZ9890H.mjs +303 -0
  331. package/dist/stage-BSZ9890H.mjs.map +1 -0
  332. package/dist/stage-D7vBtLXL.cjs +332 -0
  333. package/dist/stage-D7vBtLXL.cjs.map +1 -0
  334. package/dist/stages-BeSQQQ4z.cjs +190 -0
  335. package/dist/stages-BeSQQQ4z.cjs.map +1 -0
  336. package/dist/stages-DjFKQv08.mjs +190 -0
  337. package/dist/stages-DjFKQv08.mjs.map +1 -0
  338. package/dist/target/public.cjs +15 -0
  339. package/dist/target/public.d.cts +28 -0
  340. package/dist/target/public.d.cts.map +1 -0
  341. package/dist/target/public.d.mts +28 -0
  342. package/dist/target/public.d.mts.map +1 -0
  343. package/dist/target/public.mjs +4 -0
  344. package/dist/terminal-B7G-FtkD.cjs +85 -0
  345. package/dist/terminal-B7G-FtkD.cjs.map +1 -0
  346. package/dist/terminal-lp8RwHdX.mjs +85 -0
  347. package/dist/terminal-lp8RwHdX.mjs.map +1 -0
  348. package/dist/{types-7R81hu0i.d.mts → types-CLxsw-QY.d.cts} +2135 -428
  349. package/dist/types-CLxsw-QY.d.cts.map +1 -0
  350. package/dist/{types-N7c2O2m7.d.cts → types-wLlwkSib.d.mts} +2133 -428
  351. package/dist/types-wLlwkSib.d.mts.map +1 -0
  352. package/dist/utils-D2Nk1Nv2.cjs +205 -0
  353. package/dist/utils-D2Nk1Nv2.cjs.map +1 -0
  354. package/dist/utils-D_fxUqvU.mjs +156 -0
  355. package/dist/utils-D_fxUqvU.mjs.map +1 -0
  356. package/dist/vitest.cjs +65 -0
  357. package/dist/vitest.cjs.map +1 -0
  358. package/dist/vitest.d.cts +29 -0
  359. package/dist/vitest.d.cts.map +1 -0
  360. package/dist/vitest.d.mts +29 -0
  361. package/dist/vitest.d.mts.map +1 -0
  362. package/dist/vitest.mjs +65 -0
  363. package/dist/vitest.mjs.map +1 -0
  364. package/dist/workerRuntime-BXfhbe13.cjs +108 -0
  365. package/dist/workerRuntime-BXfhbe13.cjs.map +1 -0
  366. package/dist/workerRuntime-CsOyBRx2.mjs +79 -0
  367. package/dist/workerRuntime-CsOyBRx2.mjs.map +1 -0
  368. package/dist/workspace/index.cjs +6 -2
  369. package/dist/workspace/index.d.cts +3 -3
  370. package/dist/workspace/index.d.mts +3 -3
  371. package/dist/workspace/index.mjs +2 -2
  372. package/dist/workspace-DJjhfAGf.mjs +3027 -0
  373. package/dist/workspace-DJjhfAGf.mjs.map +1 -0
  374. package/dist/workspace-wTLnc1Ef.cjs +3577 -0
  375. package/dist/workspace-wTLnc1Ef.cjs.map +1 -0
  376. package/package.json +76 -13
  377. package/dist/HostingerProvider-BY26bWwB.mjs +0 -243
  378. package/dist/HostingerProvider-BY26bWwB.mjs.map +0 -1
  379. package/dist/HostingerProvider-BZFGYYVA.cjs +0 -243
  380. package/dist/HostingerProvider-BZFGYYVA.cjs.map +0 -1
  381. package/dist/LocalStateProvider-7HR6SS2t.cjs +0 -48
  382. package/dist/LocalStateProvider-7HR6SS2t.cjs.map +0 -1
  383. package/dist/LocalStateProvider-D7QyJoLM.mjs +0 -48
  384. package/dist/LocalStateProvider-D7QyJoLM.mjs.map +0 -1
  385. package/dist/Route53Provider-Cvj40A8I.mjs +0 -209
  386. package/dist/Route53Provider-Cvj40A8I.mjs.map +0 -1
  387. package/dist/Route53Provider-DVILBsvV.cjs +0 -209
  388. package/dist/Route53Provider-DVILBsvV.cjs.map +0 -1
  389. package/dist/SSMStateProvider-B0Hu1MKZ.mjs +0 -75
  390. package/dist/SSMStateProvider-B0Hu1MKZ.mjs.map +0 -1
  391. package/dist/SSMStateProvider-VrQ-yeqd.cjs +0 -74
  392. package/dist/SSMStateProvider-VrQ-yeqd.cjs.map +0 -1
  393. package/dist/backup-provisioner-BmhIO_Yr.cjs.map +0 -1
  394. package/dist/backup-provisioner-DIVCbfee.mjs.map +0 -1
  395. package/dist/bundler-mjqGAvu1.cjs.map +0 -1
  396. package/dist/bundler-mwH7WOb1.mjs.map +0 -1
  397. package/dist/config-DSXI480r.cjs +0 -467
  398. package/dist/config-DSXI480r.cjs.map +0 -1
  399. package/dist/config-DdKkoUE1.mjs +0 -414
  400. package/dist/config-DdKkoUE1.mjs.map +0 -1
  401. package/dist/config.d.cts.map +0 -1
  402. package/dist/config.d.mts.map +0 -1
  403. package/dist/credentials-C6Pfn6GY.cjs +0 -2939
  404. package/dist/credentials-C6Pfn6GY.cjs.map +0 -1
  405. package/dist/credentials-lbv-j0Be.mjs +0 -2802
  406. package/dist/credentials-lbv-j0Be.mjs.map +0 -1
  407. package/dist/discover-BERGFg8v.cjs +0 -288
  408. package/dist/discover-BERGFg8v.cjs.map +0 -1
  409. package/dist/discover-CK-n3w6b.mjs +0 -244
  410. package/dist/discover-CK-n3w6b.mjs.map +0 -1
  411. package/dist/emit-BdoPFjZf.cjs +0 -253
  412. package/dist/emit-BdoPFjZf.cjs.map +0 -1
  413. package/dist/emit-Bzq7JsMP.mjs +0 -224
  414. package/dist/emit-Bzq7JsMP.mjs.map +0 -1
  415. package/dist/generator-LfZU7NlU.mjs +0 -247
  416. package/dist/generator-LfZU7NlU.mjs.map +0 -1
  417. package/dist/generator-Wdfp0jCS.cjs +0 -282
  418. package/dist/generator-Wdfp0jCS.cjs.map +0 -1
  419. package/dist/github-DlIrXPee.mjs +0 -216
  420. package/dist/github-DlIrXPee.mjs.map +0 -1
  421. package/dist/github-n7N9yOff.cjs +0 -216
  422. package/dist/github-n7N9yOff.cjs.map +0 -1
  423. package/dist/index-B4H4XF7A.d.mts.map +0 -1
  424. package/dist/index-RCUizGxL.d.cts.map +0 -1
  425. package/dist/openapi-B8bu_OXN.cjs +0 -2038
  426. package/dist/openapi-B8bu_OXN.cjs.map +0 -1
  427. package/dist/openapi-DfjbhrsM.mjs +0 -1991
  428. package/dist/openapi-DfjbhrsM.mjs.map +0 -1
  429. package/dist/reconcile-Cq4cO83R.cjs +0 -136
  430. package/dist/reconcile-Cq4cO83R.cjs.map +0 -1
  431. package/dist/reconcile-fmoluZmZ.mjs +0 -113
  432. package/dist/reconcile-fmoluZmZ.mjs.map +0 -1
  433. package/dist/ssm-BKN1Cg4z.mjs +0 -60
  434. package/dist/ssm-BKN1Cg4z.mjs.map +0 -1
  435. package/dist/ssm-FxeSAt35.cjs +0 -60
  436. package/dist/ssm-FxeSAt35.cjs.map +0 -1
  437. package/dist/storage-DgypfSD6.cjs +0 -351
  438. package/dist/storage-DgypfSD6.cjs.map +0 -1
  439. package/dist/storage-TP0x118M.mjs +0 -304
  440. package/dist/storage-TP0x118M.mjs.map +0 -1
  441. package/dist/transfer-2aRVVJ6I.mjs +0 -122
  442. package/dist/transfer-2aRVVJ6I.mjs.map +0 -1
  443. package/dist/transfer-C3WZVmj_.cjs +0 -151
  444. package/dist/transfer-C3WZVmj_.cjs.map +0 -1
  445. package/dist/types-7R81hu0i.d.mts.map +0 -1
  446. package/dist/types-N7c2O2m7.d.cts.map +0 -1
  447. package/dist/workspace-Bu3xNCej.mjs.map +0 -1
  448. package/dist/workspace-CRD9YinV.cjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stack-BHrGbsGA.mjs","names":[],"sources":["../src/providers/aws.ts","../src/providers/s3/plannedOrigin.ts","../src/compose/sitePassword.ts","../src/compose/stack.ts"],"sourcesContent":["/**\n * The AWS account a provider provisions in — the stage's, found the way the\n * SSM and Secrets Manager stores find it.\n *\n * 1. `--profile`, resolved on its own: exported keys left over from another\n * account never win over a profile someone named.\n * 2. `AWS_PROFILE`, else `AWS_ACCESS_KEY_ID`/`AWS_SECRET_ACCESS_KEY` — the\n * deploy's own `aws` credential kind (`storedCredentials`).\n * 3. The SDK's default chain: `~/.aws` default profile, SSO, a role. In CI,\n * whatever `aws-actions/configure-aws-credentials` exported.\n *\n * None of them: the provider has no provisioning credentials, and the stage\n * is treated as `external`.\n */\n\nimport {\n\ttype AwsCredential,\n\tstoredCredentials,\n} from '../deploy/credentials.js';\nimport type { CredentialLookup } from './types.js';\n\n/** An AWS credential, or the default chain the SDK resolves itself. */\nexport type AwsProvisioning =\n\t| AwsCredential\n\t| {\n\t\t\tchain: true;\n\t\t\tregion?: string;\n\t };\n\nexport async function awsProvisioningCredentials(\n\tlookup: CredentialLookup,\n): Promise<AwsProvisioning | undefined> {\n\tconst region = lookup.env.AWS_REGION ?? lookup.env.AWS_DEFAULT_REGION;\n\tconst where = region ? { region } : {};\n\tif (lookup.profile) return { profile: lookup.profile, ...where };\n\n\tconst stored = await storedCredentials({\n\t\tenv: lookup.env,\n\t\t...(lookup.home ? { home: lookup.home } : {}),\n\t}).get({ kind: 'aws', stage: lookup.stage });\n\tif (stored) return stored;\n\n\ttry {\n\t\tconst { fromNodeProviderChain } = await import(\n\t\t\t'@aws-sdk/credential-providers'\n\t\t);\n\t\tawait fromNodeProviderChain({ timeout: 1000, maxRetries: 0 })();\n\t\treturn { chain: true, ...where };\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * An S3-compatible endpoint the environment points the SDK at — the AWS\n * emulator in tests. The SDK reads it itself; it is read here too, because\n * an emulator takes path-style requests, and a key written for one has to\n * say where it is.\n */\nexport function awsEndpoint(\n\tenv: NodeJS.ProcessEnv,\n\tservice: 'S3' | 'IAM' | 'CLOUDFRONT' | 'ACM' | 'SNS' | 'SQS' | 'STS' | 'SES',\n): string | undefined {\n\treturn env[`AWS_ENDPOINT_URL_${service}`] ?? env.AWS_ENDPOINT_URL;\n}\n\n/** An SDK client's config for a provisioning credential. */\nexport async function awsClientConfig(\n\tcredential: AwsProvisioning,\n\tregion: string,\n): Promise<{\n\tregion: string;\n\tcredentials?:\n\t\t| ReturnType<typeof import('@aws-sdk/credential-providers').fromIni>\n\t\t| { accessKeyId: string; secretAccessKey: string; sessionToken?: string };\n}> {\n\tif ('profile' in credential) {\n\t\tconst { fromIni } = await import('@aws-sdk/credential-providers');\n\t\treturn { region, credentials: fromIni({ profile: credential.profile }) };\n\t}\n\tif ('accessKeyId' in credential) {\n\t\treturn {\n\t\t\tregion,\n\t\t\tcredentials: {\n\t\t\t\taccessKeyId: credential.accessKeyId,\n\t\t\t\tsecretAccessKey: credential.secretAccessKey,\n\t\t\t\t...(credential.sessionToken\n\t\t\t\t\t? { sessionToken: credential.sessionToken }\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t};\n\t}\n\treturn { region };\n}\n","/**\n * Where a bucket the `s3` provider is to create signs its links, before it\n * has: the origin of the name and region its first deploy gives it.\n *\n * A site's image inlines its buckets' signed origins, and a protected stage's\n * images are built on every push to the default branch, long before the\n * release that first deploys the stage. The connection the origin is\n * otherwise derived from (`signedOrigins`) is written by that deploy, so\n * without this a stage that has never been deployed cannot be built, and a\n * stage that cannot be built is never deployed.\n */\n\nimport * as s3Url from '@geekmidas/storage/s3-url';\nimport { appKey } from '../../workspace/derive.js';\nimport type {\n\tNormalizedWorkspace,\n\tS3ObjectsConfig,\n} from '../../workspace/types.js';\nimport { awsEndpoint } from '../aws.js';\nimport { s3Region } from './config.js';\nimport { bucketName } from './naming.js';\n\nexport interface PlannedOriginInput {\n\tworkspace: Pick<NormalizedWorkspace, 'secrets'>;\n\tstage: string;\n\t/** The deploy identity's scope, which every bucket name starts with. */\n\tscope: string;\n\tconfig: S3ObjectsConfig;\n\t/** The `ObjectStorage` construct's id. */\n\tbucket: string;\n}\n\n/**\n * `https://<bucket>.s3.<region>.amazonaws.com` for the bucket's good name.\n *\n * Nothing when it cannot be known ahead: against an S3 emulator\n * (`AWS_ENDPOINT_URL`), or with no region to name. The first deploy names a\n * bucket otherwise only when another account already holds the good name —\n * a suffixed one, which it reports, and whose origin the next build inlines.\n */\nexport function plannedSignedOrigin(\n\tinput: PlannedOriginInput,\n\tenv: NodeJS.ProcessEnv = process.env,\n): string | undefined {\n\tif (awsEndpoint(env, 'S3')) return undefined;\n\tlet region: string;\n\ttry {\n\t\tregion = s3Region(input, env);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tconst bucket = bucketName({\n\t\tscope: input.scope,\n\t\tstage: input.stage,\n\t\tid: appKey(input.bucket),\n\t});\n\treturn s3Url.signedOrigin({ bucket, region });\n}\n","/**\n * A site served behind a password on some deployed stages — a `StaticSite`'s\n * `password`, naming a `RandomPassword` — so a staging build is not public\n * while it is being tried.\n *\n * The edge asks for it with HTTP basic auth, before a request reaches the\n * site: the browser prompts, and nothing of the site loads until the stage's\n * login is given. The user is the stage's name; the password is the\n * `RandomPassword`'s value on the stage, generated and kept like any other.\n * Only its bcrypt hash reaches the edge's config.\n *\n * Pure.\n */\n\nimport { createHash } from 'node:crypto';\nimport type { ConstructManifest, SiteDeclaration } from '@geekmidas/manifest';\nimport bcrypt from 'bcryptjs';\nimport { GkmError } from '../errors';\nimport { appKey } from '../workspace/derive.js';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\n\n/** The basic-auth login a site is served behind. */\nexport interface SiteAuth {\n\t/** The stage's name. */\n\tuser: string;\n\tpassword: string;\n\t/** The password's bcrypt hash — what the edge's config holds. */\n\thash: string;\n\t/** The stage secret the password is kept in: `SITE_PASSWORD`. */\n\tkey: string;\n}\n\n/** A site's `password` names a `RandomPassword` the manifest does not hold. */\nexport class SitePasswordNotDeclared extends GkmError {\n\tconstructor(\n\t\treadonly site: string,\n\t\treadonly secret: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${site}' is served behind the password '${secret}', and no ` +\n\t\t\t\t`RandomPassword '${secret}' was found. Export it from a constructs ` +\n\t\t\t\t`file, as any construct is: export const ${secret[0]!.toLowerCase()}${secret.slice(1)} = ` +\n\t\t\t\t`new RandomPassword('${secret}');`,\n\t\t);\n\t\tthis.name = 'SitePasswordNotDeclared';\n\t}\n}\n\n/** A site's `password` names a stage the workspace does not deploy. */\nexport class UnknownPasswordStage extends GkmError {\n\tconstructor(\n\t\treadonly site: string,\n\t\treadonly stage: string,\n\t\treadonly deployed: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`'${site}' is served behind a password on '${stage}', which is not ` +\n\t\t\t\t`one of the workspace's deployed stages (${deployed\n\t\t\t\t\t.map((s) => `'${s}'`)\n\t\t\t\t\t.join(', ')}). Name one of them in its password's stages.`,\n\t\t);\n\t\tthis.name = 'UnknownPasswordStage';\n\t}\n}\n\n/** A site behind a password, with none in the stage's secrets. */\nexport class SitePasswordMissing extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly key: string,\n\t) {\n\t\tsuper(\n\t\t\t`A site of '${stage}' is served behind a password, and the stage has ` +\n\t\t\t\t`no ${key} in its secrets. Run gkm compose --stage ${stage} once to ` +\n\t\t\t\t`generate it, or set one: gkm secrets:set ${key} '…' --stage ${stage}`,\n\t\t);\n\t\tthis.name = 'SitePasswordMissing';\n\t}\n}\n\n/**\n * A site behind a password on a stage it deploys through a target that cannot\n * ask for a login. Refused rather than ignored: ignored, the site would be\n * public while its construct says it is not.\n */\nexport class SitePasswordNeedsCompose extends GkmError {\n\tconstructor(\n\t\treadonly site: string,\n\t\treadonly stage: string,\n\t\treadonly target: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${site}' is served behind a password on '${stage}', and it deploys ` +\n\t\t\t\t`through '${target}', which cannot ask for one yet — only compose ` +\n\t\t\t\t`does. Remove ${stage} from its password's stages, or deploy it ` +\n\t\t\t\t`with compose.`,\n\t\t);\n\t\tthis.name = 'SitePasswordNeedsCompose';\n\t}\n}\n\n/**\n * The `RandomPassword` a site is served behind on `stage`, by its key —\n * `SITE_PASSWORD` — or `undefined` where the stage asks for none.\n *\n * @throws {SitePasswordNotDeclared} where the password is not in the manifest\n */\nexport function sitePasswordKey(\n\tmanifest: ConstructManifest,\n\tsite: SiteDeclaration,\n\tstage: string,\n): string | undefined {\n\tconst password = site.password;\n\tif (!password?.stages.includes(stage)) return undefined;\n\n\tconst secret = manifest[password.secret];\n\tconst key = secret?.kind === 'secret' ? secret.provides?.[0] : undefined;\n\tif (!key) throw new SitePasswordNotDeclared(site.id, password.secret);\n\treturn key;\n}\n\n/**\n * Before anything is deployed: every site behind a password names a deployed\n * stage and a declared `RandomPassword`, and one of `apps` behind it on\n * `stage` deploys through compose.\n *\n * @throws {UnknownPasswordStage}, {SitePasswordNotDeclared},\n * {SitePasswordNeedsCompose}\n */\nexport function assertSitePasswords(\n\tworkspace: Pick<NormalizedWorkspace, 'stages'>,\n\tmanifest: ConstructManifest,\n\tstage: string,\n\tapps: readonly string[],\n\ttarget: string,\n): void {\n\tfor (const site of Object.values(manifest)) {\n\t\tif (site.kind !== 'site' || !site.password) continue;\n\n\t\tfor (const named of site.password.stages) {\n\t\t\tif (!workspace.stages.deployed.includes(named)) {\n\t\t\t\tthrow new UnknownPasswordStage(\n\t\t\t\t\tsite.id,\n\t\t\t\t\tnamed,\n\t\t\t\t\tworkspace.stages.deployed,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst key = sitePasswordKey(manifest, site, stage);\n\t\tif (key && target !== 'compose' && apps.includes(appKey(site.id))) {\n\t\t\tthrow new SitePasswordNeedsCompose(site.id, stage, target);\n\t\t}\n\t}\n}\n\n/**\n * The login a site is served behind on `stage`, from the password kept under\n * `key`.\n *\n * The hash's salt is derived from the password, so the same password always\n * renders the same edge config: a deploy that changed nothing rewrites\n * nothing, and the proxy is not reloaded for it. A per-hash random salt\n * guards against a precomputed table of common passwords; a generated one is\n * 43 random characters, which no table holds.\n *\n * @throws {SitePasswordMissing} where the stage's secrets hold none\n */\nexport function siteAuth(\n\tstage: string,\n\tkey: string,\n\tcustom: Readonly<Record<string, string>>,\n): SiteAuth {\n\tconst password = custom[key];\n\tif (!password) throw new SitePasswordMissing(stage, key);\n\n\treturn {\n\t\tuser: stage,\n\t\tpassword,\n\t\thash: bcrypt.hashSync(password, saltFor(password)),\n\t\tkey,\n\t};\n}\n\n/** bcrypt's own base-64 alphabet, in which a salt is written. */\nconst BCRYPT_ALPHABET =\n\t'./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n\n/**\n * A bcrypt salt — `$2a$`, which Caddy and Traefik both read, at cost 10 —\n * derived from the password.\n */\nfunction saltFor(password: string): string {\n\tconst digest = createHash('sha256').update(password).digest();\n\tlet salt = '';\n\tfor (let i = 0; i < 22; i++) salt += BCRYPT_ALPHABET[digest[i]! % 64];\n\treturn `$2a$10$${salt}`;\n}\n","/**\n * The stack a workspace runs as for one stage — pure.\n *\n * Everything `gkm compose` writes is decided here, as data: the compose file,\n * the Caddyfile, one env file per process that reads one — each backend,\n * worker and site that runs a server — and the image each app runs. The\n * command around it reads the workspace, asks the registry, writes the files\n * and starts Docker; none of those decide anything, so all of it can be\n * asserted without a daemon.\n *\n * The values come from the same derivations every other target uses. The\n * plan is reconcile's `planFor`, the keys a process reads are\n * `processEnvKeys` — the rule `gkm dev` and `gkm exec` apply — and every URL\n * is `envFor`'s, with each app at its public address: a browser and a sibling\n * service reach an API by the same name, through the edge.\n */\n\nimport { createHash } from 'node:crypto';\nimport { join } from 'node:path';\nimport {\n\ttype LocalAuthorityPaths,\n\tlocalAuthorityPaths,\n} from '@geekmidas/edge/certificates/local';\nimport { CADDY_TLS_DIR, edgeCaddyfile } from '@geekmidas/edge/proxy/caddy';\nimport {\n\tEDGE_NETWORK,\n\tedgeAlias,\n\tedgeCertificatePaths,\n\ttraefikDynamicFile,\n} from '@geekmidas/edge/proxy/traefik';\nimport {\n\ttype ComposeProxy,\n\tEDGE_LIMITS,\n\ttype EdgeRoute,\n\ttype EdgeTls,\n\ttype EdgeWildcard,\n\tNOFILE,\n\trouteHosts,\n} from '@geekmidas/edge/routes';\nimport {\n\ttype ConstructManifest,\n\tEDGE_TOKEN_KEY,\n\tisWildcardSite,\n\tprovidedKeyFor,\n\tprovisionOrder,\n\ttype SiteDeclaration,\n\ttype WebSocketEdgeLimits,\n\tWILDCARD_SUBDOMAIN,\n} from '@geekmidas/manifest';\nimport { stageBackups } from '../backups/config.js';\nimport {\n\tBACKUPS_SERVICE,\n\tbackupsService,\n\ttype StackBackups,\n\tstackBackups,\n} from '../backups/service.js';\nimport {\n\ttype ProcessorUnit,\n\tprocessorUnits,\n\ttype WorkerUnit,\n\tworkerUnits,\n} from '../build/workers.js';\nimport {\n\ttype DevServiceUse,\n\tdevServicesUsed,\n\ttype ExternalServices,\n\texternalServices,\n\ttype ServiceDeclaration,\n\tstageServiceDeclarations,\n\tsuppliedOnly,\n} from '../deploy/devServices.js';\nimport { isMainFrontendApp, resolveHost } from '../deploy/domain.js';\nimport { type DeployIdentity, imageRef, stageTag } from '../deploy/identity.js';\nimport { findRootDomain, normalizeDnsConfig } from '../dns/index';\nimport { validateImageRef } from '../docker/imageRef.js';\nimport {\n\tappDockerfile,\n\tprocessorDockerfile,\n\tworkerDockerfile,\n} from '../docker/index.js';\nimport { composeBuildPaths, type ImageLayout } from '../docker/layout.js';\nimport {\n\tLOCAL_CA_BUILD_SECRET,\n\tPRERENDER_RUN_ARG,\n\tPROCESSOR_PORT,\n\tTURBO_VERSION,\n\tWORKER_PORT,\n} from '../docker/templates.js';\nimport { GkmError } from '../errors';\nimport {\n\tobjectsRoute,\n\tSNS_SUBSCRIPTIONS_KEY,\n\tsubscriberRoute,\n} from '../generators/subscriberRoute.js';\nimport { gkmHome } from '../home';\nimport { stageProvider } from '../providers/config.js';\nimport { stageProviderNotes } from '../providers/notes.js';\nimport {\n\tORIGIN_VERIFY_HEADER,\n\toriginSecretKey,\n\tprocessorOriginHost,\n} from '../providers/processorOrigin.js';\nimport { servesOnCdn } from '../providers/s3/config.js';\nimport { plannedSignedOrigin } from '../providers/s3/plannedOrigin.js';\nimport { networkEnv, processEnvKeys } from '../reconcile/apps.js';\nimport {\n\thostFor,\n\thostsFor,\n\tLOCAL_TLD,\n\ttype ResourceHosts,\n} from '../reconcile/caddyfile.js';\nimport { type ComposeService, composeFor } from '../reconcile/compose.js';\nimport { DEFAULT_IMAGES, portKeys } from '../reconcile/containers.js';\nimport type { BoundSubscriber } from '../reconcile/discover.js';\nimport { EMULATOR_ACCESS_KEY_ID } from '../reconcile/emulator.js';\nimport { type EnvOptions, localRolePassword } from '../reconcile/env.js';\nimport {\n\tINBOX_RELAY_TOKEN_KEY,\n\tinboxRelayWorker,\n\tinboxWebhookUrl,\n} from '../reconcile/inboxRelay.js';\nimport {\n\ttype ContainerCredentials,\n\tLOCAL_RABBITMQ_USER,\n\ttype LocalCredentials,\n\tpostgresSuperuser,\n} from '../reconcile/localCredentials.js';\nimport {\n\tminioWebhookEnv,\n\ttype ObjectWebhook,\n\twatchedBuckets,\n} from '../reconcile/objectEvents.js';\nimport { type Plan, type PlannedResource, planFor } from '../reconcile/plan.js';\nimport { bucketLifecycles, bucketPolicies } from '../reconcile/provision.js';\nimport { signedOrigins } from '../reconcile/signedOrigins.js';\nimport type { StageSecrets } from '../secrets/types.js';\nimport { NoDomainForStage } from '../target/dokploy/domain.js';\nimport {\n\totlpTelemetryEnv,\n\ttype ResolvedTelemetry,\n\tresolveStageTelemetry,\n\ttelemetryEnv,\n} from '../telemetry/config.js';\nimport {\n\tisTelemetryKey,\n\tscopeTelemetryEnv,\n\tstackTelemetry,\n\ttelemetryOf,\n\tusesTelemetry,\n} from '../telemetry/edges.js';\nimport { DEFAULT_EVENTS } from '../types.js';\nimport { appKey } from '../workspace/derive.js';\nimport { fileServerHost } from '../workspace/fileServerLabel.js';\nimport type {\n\tComposeTlsConfig,\n\tNormalizedAppConfig,\n\tNormalizedWorkspace,\n\tS3ObjectsConfig,\n} from '../workspace/types.js';\nimport { isReservedStageKey } from './dnsConfig.js';\nimport type { AppImage } from './images.js';\nimport {\n\tLOGS_SERVICE,\n\tlogsOnPort,\n\tlogsPorts,\n\tlogsService,\n\ttype StackLogs,\n\tstackLogs,\n} from './logs.js';\nimport { LOGS_PORT } from './logsConfig.js';\nimport { certificateFor, proxyFor } from './proxy.js';\nimport {\n\tREDIS_SERVICE,\n\tredisService,\n\tSTACK_CACHE,\n\ttype StackRedis,\n\tstackRedis,\n} from './redis.js';\nimport {\n\tOFFLINE_BUILD_ADDRESS,\n\tofflineBuildHosts,\n\tpublicBuildValues,\n\trunsServer,\n} from './siteBuild.js';\nimport { type SiteAuth, siteAuth, sitePasswordKey } from './sitePassword.js';\n\n/** Where a stack's files are written, relative to the workspace root. */\nexport function stackDir(stage: string): string {\n\treturn `.gkm/compose/${stage}`;\n}\n\n/**\n * The compose project a stage's stack runs as.\n *\n * The deploy identity's scope, so two workspaces with one name in different\n * namespaces never share containers or volumes — and the stage, so a\n * machine can run two stages side by side.\n */\nexport function composeProject(identity: DeployIdentity): string {\n\treturn `${identity.scope}-${identity.stage}`;\n}\n\n/** The ports the edge is published on, and the variables that move them. */\nexport const EDGE_PORT_ENV = {\n\thttps: 'GKM_COMPOSE_HTTPS_PORT',\n\thttp: 'GKM_COMPOSE_HTTP_PORT',\n} as const;\n\n/**\n * The variable that moves the local stage's OpenObserve off its loopback\n * port, 5080 — which the local stage takes from nowhere else, since it\n * ignores `deploy.telemetry`. Another stack, or another tool, may hold 5080.\n */\nexport const LOGS_PORT_ENV = 'GKM_COMPOSE_LOGS_PORT';\n\n/**\n * Containers this target does not run.\n *\n * The AWS emulator never applies: a stack is a server target, whose events\n * are pg-boss. Reconcile's Caddy fronts `gkm dev`'s host processes; the stack\n * brings its own edge.\n *\n * MinIO and Mailpit run on the local stage always, and on a deployed stage\n * only where `--allow-dev-services` allowed them and its secrets configure no\n * real bucket or mail server — see `devServices.ts`.\n */\nconst NOT_RUN: Readonly<Record<string, true>> = {\n\tlocalstack: true,\n\tcaddy: true,\n};\n\n/** The kinds a deployed stage takes from its secrets, or a dev service. */\nconst SERVICE_KINDS: Readonly<Record<string, ServiceDeclaration['kind']>> = {\n\temail: 'email',\n\tobjects: 'objects',\n\t'file-server': 'file-server',\n};\n\n/** The region MinIO is addressed with. It has no regions; the SDK wants one. */\nconst MINIO_REGION = 'us-east-1';\n\n/** The S3 client's credentials, read beside a bucket's URL when it has them. */\nconst STORAGE_KEYS = [\n\t'AWS_ACCESS_KEY_ID',\n\t'AWS_SECRET_ACCESS_KEY',\n\t'AWS_REGION',\n] as const;\n\n/**\n * Every service's Docker logs, rotated. The json-file driver keeps a\n * container's output in one file that grows until the disk is full — on a\n * small server, in weeks. Three files of 10 MB each per container is enough\n * to see what happened and never fills anything. A project's own override\n * file that sets `logging` wins over it.\n */\nexport const LOG_ROTATION = {\n\tdriver: 'json-file',\n\toptions: { 'max-size': '10m', 'max-file': '3' },\n} as const;\n\n/** Each image's build, where the stack builds rather than pulls. */\nexport interface AppBuild {\n\t/** Where the Dockerfile is written, relative to the workspace root. */\n\tdockerfile: string;\n\t/** A site's public URLs, inlined by its bundler. */\n\targs?: Record<string, string>;\n\t/**\n\t * A site's own hosts and its edges', refused for the length of its build —\n\t * see {@link offlineBuildHosts}.\n\t */\n\tofflineHosts?: string[];\n}\n\n/** One app in the stack. */\nexport interface StackApp extends AppImage {\n\t/** Its compose service name — the app key, `api`. */\n\tname: string;\n\t/** The construct it serves. */\n\tid: string;\n\tkind: 'rest-api' | 'websocket-api' | 'site';\n\t/**\n\t * A site's framework — whether its pages are rendered by a server (`next`,\n\t * `tanstack`) or built once as files (`static`). Absent for a backend.\n\t */\n\tvariant?: SiteDeclaration['variant'];\n\t/**\n\t * How many containers serve it, each an upstream of its route: `api`,\n\t * then `api-2`, `api-3`. One, but for a surface that asked for more.\n\t */\n\treplicas: number;\n\t/** Its directory, relative to the workspace root. */\n\tpath: string;\n\tport: number;\n\t/** The host the edge answers it on — canonical: its `<ID>_URL`'s. */\n\thost: string;\n\t/** More hosts the edge answers it on, as `host`: its `aliases`. */\n\taliases?: string[];\n\t/** Hosts the edge redirects to `host`, permanently: a site's `redirects`. */\n\tredirects?: string[];\n\t/** `https://<host>` — with the edge's port where it is not 443. */\n\turl: string;\n\tbuild?: AppBuild;\n\t/**\n\t * Whether it reads an environment at runtime: every backend, and a site\n\t * that runs a server (`runsServer`). A static site is a bundle.\n\t */\n\truntime: boolean;\n\t/**\n\t * Exactly the keys it reads at runtime (`processEnvKeys`). Absent for a\n\t * static site.\n\t */\n\tenv?: Record<string, string>;\n\t/** The login the edge asks for, where the site is behind a password. */\n\tauth?: SiteAuth;\n\t/**\n\t * A site that pre-renders against its stage (`prerender: 'stage'`): the\n\t * apps of the stack its `.dependsOn()` names, by compose service name —\n\t * what has to answer, healthy, before its image is built.\n\t */\n\tprerender?: { against: string[] };\n\t/** A WebSocket surface's per-address limits, which its route enforces. */\n\tlimits?: WebSocketEdgeLimits;\n}\n\n/**\n * A Worker in the stack: its crons, queue consumers and subscribers in a\n * container of their own. Nothing is published, and nothing routes to it\n * unless SNS pushes to one of its subscribers — then the edge answers it on\n * a host of its own, on exactly those subscribers' routes.\n */\nexport interface StackWorker extends AppImage {\n\t/** Its compose service name — `jobs`. */\n\tname: string;\n\t/** The Worker construct. */\n\tid: string;\n\t/** The app whose build writes its entry, which its image is built from. */\n\thost: string;\n\t/** Where its health check answers, inside the container. */\n\tport: number;\n\tbuild?: AppBuild;\n\t/** Exactly the keys the worker's constructs read. */\n\tenv?: Record<string, string>;\n\t/** Where SNS pushes to it, when it pushes to any of its subscribers. */\n\tpush?: WorkerPush;\n}\n\n/** A worker's public face: the routes SNS pushes its subscribers' messages to. */\nexport interface WorkerPush {\n\t/** e.g. `jobs.example.com` */\n\thost: string;\n\t/** `https://<host>` — what each route is subscribed under. */\n\turl: string;\n\t/** Each pushed subscriber's route, and nothing else the worker serves. */\n\tpaths: string[];\n\t/**\n\t * Each pushed subscriber: its export, the key of the SNS connection its\n\t * deliveries come from, and the URL the deploy subscribes for it.\n\t */\n\tsubscribers: PushedSubscriber[];\n}\n\n/** One subscriber SNS pushes to, as the deploy subscribes it. */\nexport interface PushedSubscriber {\n\t/** Its export — what its subscription ARN is recorded under. */\n\tname: string;\n\t/**\n\t * The env key of the SNS connection it is delivered from — its topic's\n\t * publisher string, or its bucket's events string.\n\t */\n\tconnectionKey: string;\n\t/** `https://<host>/__gkm/subscribers/<name>` */\n\tendpoint: string;\n\t/**\n\t * The event types a topic subscriber names — its subscription's filter.\n\t * Absent for a bucket's subscriber.\n\t */\n\tevents?: readonly string[];\n}\n\n/**\n * A file server's processors in the stack: one container answering each of\n * their patterns, built from the app whose build writes their entry.\n *\n * Reached on the file server's own host when the stack's MinIO serves it —\n * its patterns sent here, every other path to the bucket — or, when a CDN\n * serves the bucket, on a host of its own that only the CDN may call.\n */\nexport interface StackProcessor extends AppImage {\n\t/** Its compose service name — `assets-processors`. */\n\tname: string;\n\t/** The file server's surface it answers on, `AssetsServer`. */\n\tid: string;\n\t/** The app whose build writes its entry, which its image is built from. */\n\thost: string;\n\tport: number;\n\t/** Its processors' prefixes — `/i/` — the paths the edge sends it. */\n\tprefixes: string[];\n\t/**\n\t * Where a CDN reaches it, when the bucket is served by one: its host, and\n\t * the header value the CDN adds, without which the edge refuses.\n\t */\n\torigin?: { host: string; secret: string };\n\tbuild?: AppBuild;\n\t/** Exactly the keys its processors read. */\n\tenv?: Record<string, string>;\n}\n\n/** A CDN serves the bucket, and the secret it sends the processors is not in the stage. */\nexport class ProcessorOriginSecretMissing extends GkmError {\n\tconstructor(\n\t\treadonly fileServer: string,\n\t\treadonly key: string,\n\t\treadonly stage: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${fileServer}' has processors, and its bucket is not the stack's MinIO, ` +\n\t\t\t\t`so they are reached through the CDN in front of it — which sends ` +\n\t\t\t\t`${key}, and stage '${stage}' has none. It is written by the deploy ` +\n\t\t\t\t`that creates the CDN (\\`deploy.objects.${stage}\\` on s3, cdn on): run ` +\n\t\t\t\t`gkm deploy --stage ${stage}.`,\n\t\t);\n\t\tthis.name = 'ProcessorOriginSecretMissing';\n\t}\n}\n\n/**\n * A mobile app, as a stage builds it: nothing in the stack runs it — EAS\n * builds it and the stores ship it — but its build reads the stage's\n * public values, resolved here the way a site's build args are.\n */\nexport interface StackMobileApp {\n\t/** Its app key — `app`. */\n\tname: string;\n\t/** The `MobileApp` construct. */\n\tid: string;\n\t/**\n\t * What its build reads, for this stage: its scheme, its edges' public\n\t * URLs under `EXPO_PUBLIC_`, and every stage secret already named so.\n\t */\n\tvalues: Record<string, string>;\n}\n\n/** A service as the stack's compose file defines it. */\nexport interface StackService {\n\timage: string;\n\tbuild?: {\n\t\tcontext: string;\n\t\tdockerfile: string;\n\t\targs?: Record<string, string>;\n\t\t/** `host:address` lines for the build's own `/etc/hosts`. */\n\t\textra_hosts?: string[];\n\t\t/** Top-level {@link StackFile.secrets} the build may mount. */\n\t\tsecrets?: string[];\n\t};\n\t/** `build` for an image built on the server and never pulled. */\n\tpull_policy?: 'build';\n\trestart?: string;\n\tcommand?: string | string[];\n\tenv_file?: { path: string; format: 'raw' }[];\n\tenvironment?: Record<string, string>;\n\tports?: string[];\n\tvolumes?: string[];\n\t/** Names resolved to an address of the container's choosing — the host's. */\n\textra_hosts?: string[];\n\t/** Files handed to the container inline — see {@link withCaddyConfigs}. */\n\tconfigs?: { source: string; target: string; mode?: number }[];\n\tlabels?: Record<string, string>;\n\t/** Per-container kernel settings — namespaced ones only. */\n\tsysctls?: Record<string, string>;\n\tulimits?: Record<string, { soft: number; hard: number }>;\n\tdepends_on?: Record<\n\t\tstring,\n\t\t{ condition: 'service_healthy' | 'service_started' }\n\t>;\n\thealthcheck?: ComposeService['healthcheck'];\n\t/**\n\t * Behind the shared edge, a public service is on the stack's own network\n\t * and the edge's, by an alias unique on both.\n\t */\n\tnetworks?: Record<string, { aliases: string[] }>;\n\tlogging?: {\n\t\tdriver: string;\n\t\toptions: Record<string, string>;\n\t};\n}\n\nexport interface StackFile {\n\tname: string;\n\tservices: Record<string, StackService>;\n\tvolumes: Record<string, Record<string, never>>;\n\t/** The shared edge's network, which the stack joins but never creates. */\n\tnetworks?: Record<string, { name: string; external: true }>;\n\t/** Files the stack's containers are handed, by content. */\n\tconfigs?: Record<string, { content: string }>;\n\t/** Files a build mounts as a secret, from this machine. */\n\tsecrets?: Record<string, { file: string }>;\n}\n\n/**\n * The stack with Caddy's files inline: its Caddyfile and, where the stage has\n * one, its own certificate — `configs` with their `content`, which compose\n * copies into the container through the engine's API. Nothing is mounted from\n * a path, so the stack runs the same on a server's engine, over SSH, as on\n * this machine's. Their hash is a label: a changed file is a changed service,\n * which `up` recreates (compose does not, for a config's content alone).\n */\nexport function withCaddyConfigs(\n\tcompose: StackFile,\n\tfiles: { caddyfile: string; tls?: { cert: string; key: string } },\n): StackFile {\n\tconst caddy = compose.services.caddy;\n\tif (!caddy) return compose;\n\tconst configs: Record<string, { content: string }> = {\n\t\tcaddyfile: { content: files.caddyfile },\n\t\t...(files.tls\n\t\t\t? {\n\t\t\t\t\t'tls-cert': { content: files.tls.cert },\n\t\t\t\t\t'tls-key': { content: files.tls.key },\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n\tconst hash = createHash('sha256');\n\tfor (const [name, { content }] of Object.entries(configs)) {\n\t\thash.update(`${name}\\0${content}\\0`);\n\t}\n\treturn {\n\t\t...compose,\n\t\tservices: {\n\t\t\t...compose.services,\n\t\t\tcaddy: {\n\t\t\t\t...caddy,\n\t\t\t\tconfigs: [\n\t\t\t\t\t{ source: 'caddyfile', target: '/etc/caddy/Caddyfile' },\n\t\t\t\t\t...(files.tls\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t{ source: 'tls-cert', target: `${CADDY_TLS_DIR}/cert.pem` },\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tsource: 'tls-key',\n\t\t\t\t\t\t\t\t\ttarget: `${CADDY_TLS_DIR}/key.pem`,\n\t\t\t\t\t\t\t\t\tmode: 0o400,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: []),\n\t\t\t\t],\n\t\t\t\tlabels: {\n\t\t\t\t\t...caddy.labels,\n\t\t\t\t\t'dev.geekmidas.caddy.config': hash.digest('hex').slice(0, 16),\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tconfigs: { ...compose.configs, ...configs },\n\t};\n}\n\nexport interface ComposeStack {\n\tproject: string;\n\tstage: string;\n\t/**\n\t * The project's local stage, served with the certificate gkm's local\n\t * authority issues — see {@link ComposeStack.authority} — unless it set\n\t * its own.\n\t */\n\tlocal: boolean;\n\t/**\n\t * The local stage's certificate authority: gkm's, on this machine — absent\n\t * when the stage set its own certificate (`deploy.compose.tls`). Its root\n\t * is what every app container trusts and the verify step checks against,\n\t * and it issues the edge's certificate as the stack is written.\n\t */\n\tauthority?: LocalAuthorityPaths;\n\tapps: StackApp[];\n\t/** Each Worker with background work, in a container of its own. */\n\tworkers: StackWorker[];\n\t/** Each file server's processors, in a container of their own. */\n\tprocessors: StackProcessor[];\n\t/** Each mobile app, and what its build reads for this stage. */\n\tmobileApps: StackMobileApp[];\n\t/** The infrastructure containers, by compose service name. */\n\tinfra: string[];\n\tcompose: StackFile;\n\t/**\n\t * What serves the stack: its own Caddy, or the machine's shared Traefik\n\t * edge (`deploy.compose.proxy` — see `proxyFor`).\n\t */\n\tproxy: ComposeProxy;\n\t/** Every public host and what answers it — what either proxy renders. */\n\troutes: EdgeRoute[];\n\t/**\n\t * A deployed stage's wildcard site: its id, the `*.<domain>` host its\n\t * one DNS record is written for, and where its certificate comes from —\n\t * `dns` when the deploy has to give the shared edge its Route 53 key.\n\t */\n\twildcard?: {\n\t\tsite: string;\n\t\thost: string;\n\t\ttls: EdgeWildcard['tls']['kind'];\n\t};\n\t/** The stack's own Caddy's configuration — with `proxy: 'caddy'`. */\n\tcaddyfile?: string;\n\t/**\n\t * What the stack registers with the shared edge — with `proxy:\n\t * 'traefik'`: the dynamic configuration file written to its directory.\n\t */\n\ttraefik?: string;\n\t/**\n\t * The stage's own certificate and key, on this machine\n\t * (`deploy.compose.tls`) — copied to where the proxy reads it — and the\n\t * root it chains to, where it named one.\n\t */\n\ttls?: ComposeTlsConfig;\n\t/** Generated Dockerfiles, by path relative to the workspace root. */\n\tdockerfiles: Record<string, string>;\n\t/** The plan the stack was derived from — what provisioning creates. */\n\tplan: Plan;\n\t/** The containers' logins, and the seed role passwords take. */\n\tcredential: StackCredential;\n\t/**\n\t * What the stack resolves its values with, but the ports: its logins, its\n\t * seed, and each app's and file server's public address.\n\t *\n\t * What runs on this machine against the stack — its migrations and seeds\n\t * — resolves with the same (`stageEnv`), on the ports it reaches each of\n\t * {@link LOOPBACK_SERVICES} by, so a seed sees the keys `gkm seed` would\n\t * hand it and the addresses the stack's apps are given.\n\t */\n\tresolution: Omit<EnvOptions, 'ports'>;\n\t/**\n\t * The stack's MinIO, where it runs one: its root credential — what the\n\t * backends sign with — and the buckets and open paths provisioning\n\t * creates in it.\n\t */\n\tstorage?: StackStorage;\n\t/** The dev services a deployed stage runs (`--allow-dev-services`). */\n\tdevServices: DevServiceUse[];\n\t/**\n\t * The stack's OpenObserve, when the stage's telemetry is self-hosted —\n\t * every process with a `Telemetry` edge sends its logs and traces to it.\n\t */\n\tlogs?: StackLogs;\n\t/** Where the stage's telemetry goes, when any process uses it. */\n\ttelemetry?: ResolvedTelemetry;\n\t/**\n\t * The stack's Redis, where a declared cache lives in it — every cache\n\t * whose URL the stage's secrets do not set.\n\t */\n\tredis?: StackRedis;\n\t/**\n\t * The stage's backups, where it is deployed, runs Postgres and has not\n\t * set `deploy.backups.<stage>: false`.\n\t */\n\tbackups?: StackBackups;\n\t/**\n\t * The stack's Mailpit inbox, on the local stage where it runs Mailpit:\n\t * its web UI, routed through the edge at `mail.<project>.localhost`. A\n\t * deployed stage never has one — a dev service's Mailpit stays internal.\n\t */\n\tmailInbox?: StackMailInbox;\n\t/**\n\t * What the stack resolved and says without refusing it: a file server's\n\t * stored address that its stage's domain disagrees with. Printed by\n\t * whatever composed it.\n\t */\n\twarnings: string[];\n}\n\n/** The local stage's Mailpit inbox, as the edge serves it. */\nexport interface StackMailInbox {\n\t/** `mail.<project>.localhost` */\n\thost: string;\n\t/** What a browser opens, with the edge's port when it is not 443. */\n\turl: string;\n}\n\n/** The label the local stage's Mailpit inbox answers on. */\nexport const MAIL_INBOX_LABEL = 'mail';\n\n/** Mailpit's web UI and API, inside the stack's network. */\nconst MAILPIT_WEB_PORT = 8025;\n\n/** An app of the local stage on the host its Mailpit inbox is served at. */\nexport class MailInboxHostTaken extends GkmError {\n\tconstructor(\n\t\treadonly host: string,\n\t\treadonly app: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${app}' answers on ${host}, which the local stage serves its Mailpit ` +\n\t\t\t\t`inbox at. Give '${app}' another subdomain — '${MAIL_INBOX_LABEL}' is ` +\n\t\t\t\t`reserved for the inbox on the local stage.`,\n\t\t);\n\t\tthis.name = 'MailInboxHostTaken';\n\t}\n}\n\n/**\n * The services a stack publishes on its engine's loopback, and the port each\n * answers on inside — what gkm reaches from this machine to provision the\n * stack and run its migrations and seeds. Everything else is reached only on\n * the stack's network.\n */\nexport const LOOPBACK_SERVICES = {\n\tpostgres: 5432,\n\tminio: 9000,\n} as const satisfies Record<string, number>;\n\n/** What a stack's containers run with, and what its role passwords take. */\nexport interface StackCredential {\n\tcontainers: ContainerCredentials;\n\tseed: string;\n}\n\n/** The local stage's stack, without the logins `gkm dev` generates. */\nexport class LocalCredentialsMissing extends GkmError {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`The local stage '${stage}' runs with this machine's generated logins, and none were passed. Load them with loadLocalCredentials(workspace) and pass them as localCredentials.`,\n\t\t);\n\t\tthis.name = 'LocalCredentialsMissing';\n\t}\n}\n\n/**\n * A deployed stage's container logins, derived from its seed like its role\n * passwords — so every deploy of the stage computes the same ones, and no one\n * reading the repo can.\n */\nexport function derivedCredentials(\n\tproject: string,\n\tplan: Plan,\n\tseed: string,\n): ContainerCredentials {\n\tconst derive = (purpose: string) =>\n\t\tlocalRolePassword(project, plan, purpose, seed);\n\treturn {\n\t\tpostgres: { user: postgresSuperuser(project), password: derive('master') },\n\t\tminio: { user: `${project}-minio`, password: derive('minio') },\n\t\trabbitmq: { user: LOCAL_RABBITMQ_USER, password: derive('rabbitmq') },\n\t\tredis: { password: derive('redis') },\n\t\tcacheToken: derive('cache-token'),\n\t\temulator: {\n\t\t\taccessKeyId: EMULATOR_ACCESS_KEY_ID,\n\t\t\tsecretAccessKey: derive('emulator'),\n\t\t},\n\t\t// Never read: a deployed stage's OpenObserve signs in with the root\n\t\t// login its secrets hold (`stackLogs`), and the stack hands each process\n\t\t// its telemetry keys from that, not from the derivation.\n\t\tlogs: { email: `admin@${project}`, password: derive('logs') },\n\t};\n}\n\n/** The stack's MinIO, and what is created in it. */\nexport interface StackStorage {\n\tuser: string;\n\tpassword: string;\n\t/** Each bucket's stage-scoped name. */\n\tbuckets: string[];\n\t/** The open paths of each served bucket. */\n\tpolicies: { bucket: string; open: string[] }[];\n\t/**\n\t * Each bucket by construct id and name, and which of them post their\n\t * events to a worker — the notifications gkm writes once MinIO runs.\n\t */\n\tobjects: { id: string; name: string }[];\n\t/** Where MinIO posts each watched bucket's events: on the stack's network. */\n\twebhooks: ObjectWebhook[];\n\t/** How long each bucket keeps what is under each prefix. */\n\tlifecycles: { bucket: string; expire: Readonly<Record<string, number>> }[];\n}\n\nexport interface StackInput {\n\tworkspace: NormalizedWorkspace;\n\tmanifest: ConstructManifest;\n\t/**\n\t * Each Worker's crons', queues' and subscribers' files, from discovery —\n\t * which workers run, and which app each is built from.\n\t */\n\tbackground?: Readonly<Record<string, readonly string[]>>;\n\t/**\n\t * Each Worker's topic subscribers, from discovery — which of them SNS\n\t * pushes to decides whether the worker answers on a host of its own.\n\t */\n\tsubscribers?: Readonly<Record<string, readonly BoundSubscriber[]>>;\n\t/**\n\t * The SNS subscriptions the deploy made for each worker's pushed\n\t * subscribers — worker id → subscriber export → subscription ARN — handed\n\t * to the worker as `GKM_SNS_SUBSCRIPTIONS`. A pushed subscriber without\n\t * one fails the stack: the worker would mount no route for it.\n\t */\n\tpushSubscriptions?: Readonly<\n\t\tRecord<string, Readonly<Record<string, string>>>\n\t>;\n\t/**\n\t * Composed before the deploy has made the subscriptions it is about to\n\t * record — to learn where SNS pushes, and with what. No worker is handed\n\t * `GKM_SNS_SUBSCRIPTIONS`, so a pushed subscriber without an ARN is not\n\t * refused: this stack is read, never run.\n\t */\n\trecordingSubscriptions?: boolean;\n\tstage: string;\n\tidentity: DeployIdentity;\n\timages: {\n\t\tmode: 'build' | 'pull';\n\t\t/**\n\t\t * A release tag, or — building — the commit. Each image carries it with\n\t\t * the stage on (`stageTag`).\n\t\t */\n\t\ttag: string;\n\t\tregistry?: string;\n\t};\n\t/** The stage's secrets — set by hand, and what a deployed stage generated. */\n\tsecrets?: StageSecrets | null;\n\t/**\n\t * This machine's generated local logins — required for the local stage,\n\t * which runs with the same ones `gkm dev` does. See `localCredentials.ts`.\n\t */\n\tlocalCredentials?: LocalCredentials;\n\t/**\n\t * gkm's local certificate authority, for the local stage: the CLI's\n\t * home's when not given.\n\t */\n\tlocalAuthority?: LocalAuthorityPaths;\n\t/**\n\t * `--allow-dev-services`: a deployed stage runs the dev service for every\n\t * bucket and mail it does not account for. The local stage runs both\n\t * regardless.\n\t */\n\tallowDevServices?: boolean;\n\t/** The edge's published ports. 443 and 80 by default. */\n\tports?: {\n\t\thttps?: number;\n\t\thttp?: number;\n\t\t/** The local stage's OpenObserve port — see {@link LOGS_PORT_ENV}. */\n\t\tlogs?: number;\n\t};\n\t/**\n\t * The stack only builds its images, to push them (`--build --push`): no\n\t * backend's or worker's runtime environment is resolved and no service\n\t * reads an env file, so building needs none of the stage's backend\n\t * secrets. A site's build args — its public URLs — are still resolved.\n\t */\n\tbuildOnly?: boolean;\n\t/**\n\t * What names this deploy to a site that pre-renders against its stage —\n\t * its build's `GKM_PRERENDER_RUN`, so the layer that fetches the stage's\n\t * data is built again on every deploy rather than served from cache.\n\t */\n\tprerenderRun?: string;\n\t/**\n\t * For builds: where the images are built from and with what — the build\n\t * root, its package manager and turbo. The workspace's root, with pnpm,\n\t * when not given.\n\t */\n\tlayout?: ImageLayout;\n}\n\n/** A value only the stage's secrets can hold, and they do not. */\nexport class StageSecretMissing extends GkmError {\n\tconstructor(\n\t\treadonly app: string,\n\t\treadonly key: string,\n\t\treadonly stage: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${app}' reads ${key}, and the stage '${stage}' has none. Nothing in ` +\n\t\t\t\t`the stack can derive it; set it in the stage's secrets: ` +\n\t\t\t\t`gkm secrets:set ${key} '…' --stage ${stage}`,\n\t\t);\n\t\tthis.name = 'StageSecretMissing';\n\t}\n}\n\n/** Where a deployed inbox's values come from: the stage's domain, and its secrets. */\nexport interface DeployedInboxSources {\n\t/** Who reads them, named in the error when one is missing. */\n\treader: string;\n\tstage: string;\n\tdomain: string | undefined;\n\t/** The stage's secrets, where the inbox's provider wrote its keys. */\n\tsecrets: Readonly<Record<string, string>>;\n}\n\n/**\n * One key of a deployed inbox — the one rule every target reads it by.\n *\n * Its domain is the stage's, which mail is addressed to. Everything else (where\n * its raw messages are read, its topic's publisher string) is what its\n * provider made and wrote to the stage's secrets; nothing can derive it.\n *\n * @throws {NoDomainForStage} for its domain when the stage has none.\n * @throws {StageSecretMissing} when the provider has not written the key.\n */\nexport function deployedInboxValue(\n\tinbox: string,\n\tkey: string,\n\tsources: DeployedInboxSources,\n): string {\n\tif (key === providedKeyFor(inbox, 'inbox', 'domain')) {\n\t\tif (!sources.domain) throw new NoDomainForStage(sources.stage);\n\t\treturn sources.domain;\n\t}\n\tconst value = sources.secrets[key];\n\tif (value === undefined) {\n\t\tthrow new StageSecretMissing(sources.reader, key, sources.stage);\n\t}\n\treturn value;\n}\n\n/**\n * Every deployed inbox's keys, and its topic's publisher string, by key: what\n * a target that provisions nothing of the inbox's (SST) is handed, read by\n * {@link deployedInboxValue} as the compose stack reads each.\n */\nexport function deployedInboxEnv(\n\tmanifest: ConstructManifest,\n\tsources: DeployedInboxSources,\n): Record<string, string> {\n\tconst env: Record<string, string> = {};\n\tfor (const declaration of Object.values(manifest)) {\n\t\tif (declaration.kind !== 'inbox') continue;\n\t\tconst keys = [\n\t\t\t...(declaration.provides ?? []),\n\t\t\tprovidedKeyFor(declaration.topic, 'topic', 'publisherConnectionString'),\n\t\t];\n\t\tfor (const key of keys) {\n\t\t\tenv[key] = deployedInboxValue(declaration.id, key, sources);\n\t\t}\n\t}\n\treturn env;\n}\n\n/** A deployed stage's secrets with no seed to derive its passwords from. */\nexport class StageSeedMissing extends GkmError {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`The stage '${stage}' has no seed in its secrets, and a deployed stage's ` +\n\t\t\t\t`database passwords are derived from it. Run gkm compose --stage ${stage} ` +\n\t\t\t\t`without --dry-run once, or gkm deploy, to generate it.`,\n\t\t);\n\t\tthis.name = 'StageSeedMissing';\n\t}\n}\n\n/** A workspace with no API and no site to run. */\nexport class NothingToCompose extends GkmError {\n\tconstructor(readonly root: string) {\n\t\tsuper(\n\t\t\t`${root} declares no RestApi, no site and no Worker with work to do, ` +\n\t\t\t\t`so a stack would run nothing. Mobile apps ship through their own ` +\n\t\t\t\t`toolchain.`,\n\t\t);\n\t\tthis.name = 'NothingToCompose';\n\t}\n}\n\n/** A value that cannot be written to an env file a line at a time. */\nexport class EnvValueMultiline extends GkmError {\n\tconstructor(\n\t\treadonly app: string,\n\t\treadonly key: string,\n\t) {\n\t\tsuper(\n\t\t\t`${key} for '${app}' spans more than one line, and an env file holds ` +\n\t\t\t\t`one value per line. Store it on one line — base64, or JSON — and ` +\n\t\t\t\t`decode it where it is read.`,\n\t\t);\n\t\tthis.name = 'EnvValueMultiline';\n\t}\n}\n\n/** The services a stack's apps wait on. */\nconst HEALTHY = { condition: 'service_healthy' } as const;\n\n/**\n * What Caddy waits on of each app: that it started, never that it is\n * healthy. Its routes are served whatever an app's health — Caddy's own\n * upstream health checks take one out of rotation — so one app that never\n * turns healthy leaves the others routed, and a site whose health check goes\n * through the edge can turn healthy at all.\n */\nconst STARTED = { condition: 'service_started' } as const;\n\n/**\n * An app's health check: its own server, asked on 127.0.0.1 — not\n * `localhost`, which resolves to `::1` first in an Alpine container while a\n * server may listen on IPv4 alone.\n */\nfunction probe(port: number, path: string): StackService['healthcheck'] {\n\treturn {\n\t\ttest: [\n\t\t\t'CMD',\n\t\t\t'wget',\n\t\t\t'-q',\n\t\t\t'-O',\n\t\t\t'/dev/null',\n\t\t\t`http://127.0.0.1:${port}${path}`,\n\t\t],\n\t\tinterval: '5s',\n\t\ttimeout: '3s',\n\t\tretries: 20,\n\t\tstart_period: '10s',\n\t};\n}\n\n/**\n * What a stage's stack provisions: reconcile's plan, with a server target's\n * backends whatever `deploy.default` says — the stack is one machine running\n * containers, so events are pg-boss beside the declared database, and every\n * cache, one declared from that database included, is in the stack's own\n * Redis.\n */\nexport function stackPlan(\n\tworkspace: Pick<\n\t\tNormalizedWorkspace,\n\t\t'stages' | 'protectedSubdomains' | 'domains'\n\t>,\n\tmanifest: ConstructManifest,\n\tstage: string,\n): Plan {\n\t// A stage whose domain sits under this one's is a label of it no tenant\n\t// may take: `staging`, beside every app's own and the configured names.\n\tconst protectedSubdomains = [\n\t\t...(workspace.protectedSubdomains ?? []),\n\t\t...nestedStageLabels(workspace.domains, stage),\n\t];\n\treturn planFor(manifest, stage, provisionOrder(manifest), {\n\t\tlocalStage: workspace.stages.local,\n\t\t...(protectedSubdomains.length > 0 ? { protectedSubdomains } : {}),\n\t\tevents: DEFAULT_EVENTS.server,\n\t\tcache: STACK_CACHE,\n\t\t// The stack brings its own edge; reconcile's would front the host.\n\t\tedge: false,\n\t});\n}\n\n/** The stack for one stage. */\nexport function composeStack(input: StackInput): ComposeStack {\n\tconst { workspace, manifest, stage, identity } = input;\n\tconst local = stage === workspace.stages.local;\n\tconst project = composeProject(identity);\n\tconst custom = input.secrets?.custom ?? {};\n\tconst https = input.ports?.https ?? 443;\n\tconst http = input.ports?.http ?? 80;\n\tconst proxy = proxyFor(workspace.deploy?.compose, stage, local);\n\tconst certificate = certificateFor(\n\t\tworkspace.deploy?.compose,\n\t\tstage,\n\t\tworkspace.root,\n\t);\n\n\t// A server target's backends, whatever `deploy.default` says: the stack is\n\t// one machine running containers, so events are pg-boss beside the\n\t// declared database — and every cache, one declared from that database\n\t// included, is in the stack's own Redis.\n\tconst plan = stackPlan(workspace, manifest, stage);\n\tconst byId = new Map(plan.resources.map((r) => [r.id, r]));\n\n\t// The local stage's logins are the ones `gkm dev` generated for this\n\t// machine, so the two run their containers with the same; a deployed\n\t// stage's are derived from its seed.\n\tif (local && !input.localCredentials) {\n\t\tthrow new LocalCredentialsMissing(stage);\n\t}\n\tconst seed = local ? input.localCredentials!.seed : input.secrets?.seed;\n\tif (!seed) throw new StageSeedMissing(stage);\n\tconst containers: ContainerCredentials = local\n\t\t? input.localCredentials!\n\t\t: derivedCredentials(workspace.name, plan, seed);\n\tconst credential: StackCredential = {\n\t\tcontainers: {\n\t\t\t...containers,\n\t\t\t// The stage's own key pair, where it set one, is what MinIO runs as.\n\t\t\tminio: {\n\t\t\t\tuser: custom.AWS_ACCESS_KEY_ID ?? containers.minio.user,\n\t\t\t\tpassword: custom.AWS_SECRET_ACCESS_KEY ?? containers.minio.password,\n\t\t\t},\n\t\t},\n\t\tseed,\n\t};\n\n\tconst apps = stackApps(workspace, manifest, plan, {\n\t\tlocal,\n\t\tstage,\n\t\thttps,\n\t\tidentity,\n\t\timages: input.images,\n\t});\n\tconst workers = stackWorkers(\n\t\tworkerUnits(workspace, manifest, input.background ?? {}),\n\t\t{ stage, identity, images: input.images },\n\t);\n\tconst processors = stackProcessors(processorUnits(workspace, manifest), {\n\t\tmanifest,\n\t\tstage,\n\t\tidentity,\n\t\timages: input.images,\n\t});\n\tif (apps.length === 0 && workers.length === 0 && processors.length === 0) {\n\t\tthrow new NothingToCompose(workspace.root);\n\t}\n\n\t// Which construct each key belongs to, so a key is resolved by what it is\n\t// rather than by its spelling.\n\tconst owners = new Map<string, PlannedResource>();\n\tfor (const resource of plan.resources) {\n\t\towners.set(resource.envKey, resource);\n\t\tif (resource.kind === 'email') {\n\t\t\towners.set(providedKeyFor(resource.id, resource.kind, 'from'), resource);\n\t\t\towners.set(\n\t\t\t\tprovidedKeyFor(resource.id, resource.kind, 'inboxUrl'),\n\t\t\t\tresource,\n\t\t\t);\n\t\t}\n\t\t// A bucket's signed origin is its own: derived from its connection,\n\t\t// wherever that resolved — never the stack's MinIO for a bucket on S3.\n\t\tif (resource.kind === 'objects') {\n\t\t\towners.set(\n\t\t\t\tprovidedKeyFor(resource.id, resource.kind, 'signedOrigin'),\n\t\t\t\tresource,\n\t\t\t);\n\t\t}\n\t\tif (resource.kind === 'external-api') {\n\t\t\towners.set(\n\t\t\t\tprovidedKeyFor(resource.id, resource.kind, 'credentials'),\n\t\t\t\tresource,\n\t\t\t);\n\t\t}\n\t\tif (resource.kind === 'inbox') {\n\t\t\towners.set(\n\t\t\t\tprovidedKeyFor(resource.id, resource.kind, 'domain'),\n\t\t\t\tresource,\n\t\t\t);\n\t\t}\n\t\tif (resource.kind === 'websocket-api') {\n\t\t\towners.set(\n\t\t\t\tprovidedKeyFor(resource.id, resource.kind, 'publisherConnectionString'),\n\t\t\t\tresource,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst domain = workspace.domains?.[stage];\n\n\t// Where the stage's telemetry goes, when a process uses a `Telemetry`\n\t// node: the local stage always to OpenObserve, a deployed one where\n\t// `deploy.telemetry` says — and OpenObserve when it says nothing.\n\tconst telemetry = resolveStageTelemetry({\n\t\t...(workspace.deploy?.telemetry\n\t\t\t? { telemetry: workspace.deploy.telemetry }\n\t\t\t: {}),\n\t\tstage,\n\t\tlocal,\n\t\ttarget: 'compose',\n\t\truntime: 'server',\n\t\tselfHosted: true,\n\t\tused: usesTelemetry(manifest),\n\t});\n\n\t// The log UI, when the stage's telemetry is self-hosted: its root login,\n\t// how it is reached, and what each process with the edge is handed to send\n\t// to it.\n\tconst logsBase =\n\t\ttelemetry?.provider === 'self-hosted'\n\t\t\t? stackLogs({\n\t\t\t\t\tconfig:\n\t\t\t\t\t\tlocal && input.ports?.logs\n\t\t\t\t\t\t\t? { ...telemetry.selfHosted, port: input.ports.logs }\n\t\t\t\t\t\t\t: telemetry.selfHosted,\n\t\t\t\t\tstage,\n\t\t\t\t\tlocal,\n\t\t\t\t\tproject: workspace.name,\n\t\t\t\t\t...(domain ? { domain } : {}),\n\t\t\t\t\ttelemetry: stackTelemetry(manifest),\n\t\t\t\t\tcustom,\n\t\t\t\t\thttps,\n\t\t\t\t\t...(local ? { localLogin: input.localCredentials!.logs } : {}),\n\t\t\t\t})\n\t\t\t: undefined;\n\n\t// Mail and storage: the local stage runs Mailpit and MinIO for all of it.\n\t// A deployed stage takes each from its secrets — or, where allowed, from a\n\t// dev service. Only decided here: whether the stage lacks a key is the\n\t// deploy's readiness check's to say, once, and a build asks no such thing.\n\tconst services: ExternalServices = local\n\t\t? {\n\t\t\t\tmissing: [],\n\t\t\t\tminio: plan.resources\n\t\t\t\t\t.filter((r) => r.kind === 'objects')\n\t\t\t\t\t.map((r) => r.id),\n\t\t\t\t// Mailpit receives for an inbox as it sends for mail.\n\t\t\t\tmailpit: plan.resources\n\t\t\t\t\t.filter((r) => r.kind === 'email' || r.kind === 'inbox')\n\t\t\t\t\t.map((r) => r.id),\n\t\t\t}\n\t\t: externalServices({\n\t\t\t\tstage,\n\t\t\t\tdeclarations: stageServiceDeclarations({\n\t\t\t\t\tmanifest,\n\t\t\t\t}),\n\t\t\t\tsupplied: custom,\n\t\t\t\tallow: input.allowDevServices === true,\n\t\t\t\t...(domain ? { domain } : {}),\n\t\t\t\tproviders: stageProviderNotes(workspace, stage),\n\t\t\t});\n\n\t// The caches: in the stack's Redis, unless the stage set a cache's URL —\n\t// a managed Redis — and with every one set, there is no Redis to run.\n\tconst redis = stackRedis({\n\t\tplan,\n\t\tstage,\n\t\tlocal,\n\t\tcustom,\n\t\t...(local ? { localPassword: input.localCredentials!.redis.password } : {}),\n\t});\n\n\tconst infra = [\n\t\t...plan.containers\n\t\t\t.filter((c) => !NOT_RUN[c])\n\t\t\t// Run as the stack's own, below, with the stage's login.\n\t\t\t.filter((c) => c !== LOGS_SERVICE)\n\t\t\t.filter((c) => c !== 'minio' || services.minio.length > 0)\n\t\t\t.filter((c) => c !== 'mailpit' || services.mailpit.length > 0)\n\t\t\t.filter((c) => c !== REDIS_SERVICE || redis !== undefined),\n\t\t...(logsBase ? [LOGS_SERVICE] : []),\n\t].sort();\n\n\t// The local stage's inbox: Mailpit's web UI on a host of the edge's, as\n\t// the apps are — `mail.<project>.localhost` — so a link a stack mails\n\t// can be opened and followed. Never on a deployed stage, where a dev\n\t// service's Mailpit stays internal.\n\tconst mailInbox: StackMailInbox | undefined =\n\t\tlocal && infra.includes('mailpit')\n\t\t\t? (() => {\n\t\t\t\t\tconst host = [MAIL_INBOX_LABEL, workspace.name, LOCAL_TLD]\n\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t.join('.');\n\t\t\t\t\treturn {\n\t\t\t\t\t\thost,\n\t\t\t\t\t\turl: `https://${host}${https !== 443 ? `:${https}` : ''}`,\n\t\t\t\t\t};\n\t\t\t\t})()\n\t\t\t: undefined;\n\n\t// The stack's MinIO signs with the stage's own key pair where it set one,\n\t// and otherwise with the stage's login: the local one `gkm dev` generated,\n\t// or — deployed — one derived from the stage's seed.\n\tconst storage: StackStorage | undefined = infra.includes('minio')\n\t\t? (() => {\n\t\t\t\tconst buckets = services.minio\n\t\t\t\t\t.map((id) => byId.get(id)?.name)\n\t\t\t\t\t.filter((name): name is string => Boolean(name))\n\t\t\t\t\t.sort();\n\t\t\t\treturn {\n\t\t\t\t\t...credential.containers.minio,\n\t\t\t\t\tbuckets,\n\t\t\t\t\tpolicies: bucketPolicies(plan).filter((p) =>\n\t\t\t\t\t\tbuckets.includes(p.bucket),\n\t\t\t\t\t),\n\t\t\t\t\tobjects: services.minio\n\t\t\t\t\t\t.map((id) => ({ id, name: byId.get(id)?.name }))\n\t\t\t\t\t\t.filter((b): b is { id: string; name: string } => Boolean(b.name))\n\t\t\t\t\t\t.sort((a, b) => a.name.localeCompare(b.name)),\n\t\t\t\t\t// Filled once each worker's environment is resolved, below.\n\t\t\t\t\twebhooks: [],\n\t\t\t\t\tlifecycles: bucketLifecycles(plan).filter((l) =>\n\t\t\t\t\t\tbuckets.includes(l.bucket),\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t})()\n\t\t: undefined;\n\n\t// A bucket's events keys, so they resolve by where the bucket lives.\n\tconst bucketEventKeys = new Map<string, string>();\n\tfor (const resource of plan.resources) {\n\t\tif (resource.kind !== 'objects') continue;\n\t\tbucketEventKeys.set(\n\t\t\tprovidedKeyFor(resource.id, resource.kind, 'eventsConnectionString'),\n\t\t\tresource.id,\n\t\t);\n\t\tbucketEventKeys.set(\n\t\t\tprovidedKeyFor(resource.id, resource.kind, 'eventsToken'),\n\t\t\tresource.id,\n\t\t);\n\t}\n\n\t// Each file server over the stack's MinIO, at a host of its own on the\n\t// edge — the shape it has deployed: a domain serving a bucket.\n\tconst fileServers = new Map<string, { url: string; route: EdgeRoute }>();\n\tif (storage) {\n\t\tfor (const resource of plan.resources) {\n\t\t\tif (resource.kind !== 'file-server' || !resource.of) continue;\n\t\t\tif (!services.minio.includes(resource.of)) continue;\n\t\t\tif (custom[resource.envKey] !== undefined) continue;\n\t\t\tconst bucket = byId.get(resource.of);\n\t\t\tif (!bucket) continue;\n\n\t\t\tlet host: string;\n\t\t\tif (local) {\n\t\t\t\thost = hostFor(resource, workspace.name);\n\t\t\t} else {\n\t\t\t\tif (!domain) throw new NoDomainForStage(stage);\n\t\t\t\thost = fileServerHost(resource.id, domain);\n\t\t\t}\n\t\t\tfileServers.set(resource.id, {\n\t\t\t\turl: `https://${host}${local && https !== 443 ? `:${https}` : ''}`,\n\t\t\t\troute: {\n\t\t\t\t\tname: `files-${appKey(resource.id)}`,\n\t\t\t\t\thost,\n\t\t\t\t\tupstreams: [{ service: 'minio', port: 9000 }],\n\t\t\t\t\tstreaming: false,\n\t\t\t\t\tprefix: `/${bucket.name}`,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\n\t// What the stack says, without stopping, about a value it resolved.\n\tconst warnings: string[] = [];\n\n\t// Where each file server answers on this stage. Derived wherever the\n\t// stage's domain decides it — the stack's MinIO, or the CDN the s3\n\t// provider puts in front of a bucket at the same host — so an image built\n\t// ahead of the deploy that rewrites the stored copy (a domain change)\n\t// inlines the domain it is built for. Otherwise it is what the stage\n\t// stores: an address set by hand, or a bucket's own endpoint.\n\tconst objectsProvider = stageProvider(workspace, 'objects', stage);\n\tconst onCdn =\n\t\tobjectsProvider.mode === 'provider' &&\n\t\tobjectsProvider.name === 's3' &&\n\t\tservesOnCdn(objectsProvider.config as S3ObjectsConfig);\n\t// Where each bucket the s3 provider has not created yet will sign its\n\t// links: a site or mobile build inlines it, and a protected stage is built\n\t// on every push, before the release that first deploys it writes the\n\t// connection the origin is otherwise derived from.\n\tconst plannedOrigins = new Map<string, string>();\n\tif (\n\t\t!local &&\n\t\tobjectsProvider.mode === 'provider' &&\n\t\tobjectsProvider.name === 's3'\n\t) {\n\t\tfor (const resource of plan.resources) {\n\t\t\tif (resource.kind !== 'objects') continue;\n\t\t\tif (services.minio.includes(resource.id)) continue;\n\t\t\tconst connection = providedKeyFor(\n\t\t\t\tresource.id,\n\t\t\t\t'objects',\n\t\t\t\t'connectionString',\n\t\t\t);\n\t\t\tif (custom[connection] !== undefined) continue;\n\t\t\tconst origin = plannedSignedOrigin({\n\t\t\t\tworkspace,\n\t\t\t\tstage,\n\t\t\t\tscope: identity.scope,\n\t\t\t\tconfig: objectsProvider.config as S3ObjectsConfig,\n\t\t\t\tbucket: resource.id,\n\t\t\t});\n\t\t\tif (origin) {\n\t\t\t\tplannedOrigins.set(\n\t\t\t\t\tprovidedKeyFor(resource.id, 'objects', 'signedOrigin'),\n\t\t\t\t\torigin,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\tconst fileServerUrls = new Map<string, string>();\n\tfor (const resource of plan.resources) {\n\t\tif (resource.kind !== 'file-server') continue;\n\t\tconst key = resource.envKey;\n\t\tconst stored = custom[key];\n\t\tconst inMinio = Boolean(\n\t\t\tresource.of && services.minio.includes(resource.of),\n\t\t);\n\t\tconst derived =\n\t\t\tfileServers.get(resource.id)?.url ??\n\t\t\t(!local && domain\n\t\t\t\t? `https://${fileServerHost(resource.id, domain)}`\n\t\t\t\t: undefined);\n\n\t\tif (onCdn && !inMinio && derived) {\n\t\t\tfileServerUrls.set(resource.id, derived);\n\t\t\tif (stored !== undefined && stored !== derived) {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`${key} is stored as ${stored}, and '${resource.id}' answers on ` +\n\t\t\t\t\t\t`${derived} — its CDN on the stage's domain. The stack is built ` +\n\t\t\t\t\t\t`and run with ${derived}; the deploy rewrites the stored copy.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (stored !== undefined) {\n\t\t\tfileServerUrls.set(resource.id, stored);\n\t\t\t// Set by hand — an external file server, or one over the stack's\n\t\t\t// MinIO — and kept. Said when the stage's domain gives another,\n\t\t\t// which is what a previous domain's address looks like.\n\t\t\tconst byHand = inMinio || objectsProvider.mode === 'external';\n\t\t\tif (byHand && derived && stored !== derived) {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`${key} is set by hand to ${stored}, and kept. On the stage's ` +\n\t\t\t\t\t\t`domain '${resource.id}' would answer on ${derived}; if ${stored} ` +\n\t\t\t\t\t\t`is a previous domain's, set it again: gkm secrets:set ${key} ` +\n\t\t\t\t\t\t`'${derived}' --stage ${stage}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst served = fileServers.get(resource.id)?.url;\n\t\tif (served) fileServerUrls.set(resource.id, served);\n\t}\n\n\t// Behind the shared edge, the services it routes to are on a network\n\t// every stack's public services share, where a bare name — `api` — would\n\t// be answered by each stack's. They are reached, from the edge and from\n\t// inside the stack alike, by an alias prefixed with the project.\n\tconst edgeServices = new Set(\n\t\tproxy === 'traefik'\n\t\t\t? [\n\t\t\t\t\t...apps.flatMap(replicaNames),\n\t\t\t\t\t...(fileServers.size > 0 ? ['minio'] : []),\n\t\t\t\t\t...(logsBase?.host && logsBase.public ? [LOGS_SERVICE] : []),\n\t\t\t\t\t...(mailInbox ? ['mailpit'] : []),\n\t\t\t\t]\n\t\t\t: [],\n\t);\n\tconst hostOf = (service: string) =>\n\t\tedgeServices.has(service) ? edgeAlias(project, service) : service;\n\tconst logs: StackLogs | undefined = logsBase && {\n\t\t...logsBase,\n\t\tappEnv: {\n\t\t\t...logsBase.appEnv,\n\t\t\tOTEL_EXPORTER_OTLP_ENDPOINT:\n\t\t\t\tlogsBase.appEnv.OTEL_EXPORTER_OTLP_ENDPOINT.replace(\n\t\t\t\t\t`//${LOGS_SERVICE}:`,\n\t\t\t\t\t`//${hostOf(LOGS_SERVICE)}:`,\n\t\t\t\t),\n\t\t},\n\t};\n\n\t// Every key the stage resolves, with each app at its public address — what\n\t// a browser is handed, what an app says it is, and what one app calls\n\t// another on: through the edge, as it does deployed.\n\tconst derivation = {\n\t\tproject: workspace.name,\n\t\tcredentials: credential.containers,\n\t\tseed: credential.seed,\n\t\t// Mailpit on a deployed stage sends as the stage's domain.\n\t\t...(!local && domain ? { mailDomain: domain } : {}),\n\t\t// Each watched bucket in the stack's MinIO, whose events it posts to a\n\t\t// worker to relay onto the stack's broker.\n\t\trelayedBuckets: [\n\t\t\t...watchedBuckets(manifest, input.subscribers ?? {}).keys(),\n\t\t].filter((bucket) => services.minio.includes(bucket)),\n\t};\n\tconst publicAddresses = Object.fromEntries(\n\t\tapps.map((app) => [app.id, app.url]),\n\t);\n\t// Where each app also answers — its aliases, at the edge's port as its\n\t// own address is — so a surface trusts a site on every host it serves.\n\tconst aliasAddresses = Object.fromEntries(\n\t\tapps.map((app) => [\n\t\t\tapp.id,\n\t\t\t(app.aliases ?? []).map(\n\t\t\t\t(alias) =>\n\t\t\t\t\t`https://${alias}${local && https !== 443 ? `:${https}` : ''}`,\n\t\t\t),\n\t\t]),\n\t);\n\tconst outside = networkEnv(\n\t\tplan,\n\t\t{ ...derivation, addresses: publicAddresses, aliasAddresses },\n\t\thostOf,\n\t);\n\n\t/**\n\t * What a key resolves to for one app, from the stage's secrets where only\n\t * they can hold it, and the derivations otherwise.\n\t */\n\tconst valueFor = (\n\t\tapp: Pick<StackApp, 'name' | 'id' | 'kind'>,\n\t\tkey: string,\n\t\towner: PlannedResource | undefined,\n\t): string | undefined => {\n\t\t// The server's address is gkm's own: never in an app's environment.\n\t\tif (isReservedStageKey(key)) return undefined;\n\t\t// A bucket's events: relayed onto the stack's broker when the bucket is\n\t\t// in the stack's MinIO, and otherwise wherever the stage says — a topic\n\t\t// the storage publishes to — or nowhere.\n\t\tconst watching = bucketEventKeys.get(key);\n\t\tif (watching) {\n\t\t\tif (custom[key] !== undefined) return custom[key];\n\t\t\treturn services.minio.includes(watching) ? outside[key] : undefined;\n\t\t}\n\t\t// An inbox: locally, Mailpit's API and the project's local domain, as\n\t\t// `gkm dev` resolves them. Deployed, where its raw messages are read —\n\t\t// the bucket its provider made and wrote to the stage's secrets — and\n\t\t// the stage's domain, which mail is addressed to.\n\t\tif (owner?.kind === 'inbox') {\n\t\t\tif (local) return outside[key];\n\t\t\treturn deployedInboxValue(owner.id, key, {\n\t\t\t\treader: app.name,\n\t\t\t\tstage,\n\t\t\t\tdomain,\n\t\t\t\tsecrets: custom,\n\t\t\t});\n\t\t}\n\t\t// A deployed stage has no inbox: Mailpit runs only locally — not for a\n\t\t// backend, a site's bundle or a phone.\n\t\tif (!local && owner?.kind === 'email' && key.endsWith('_INBOX_URL')) {\n\t\t\treturn undefined;\n\t\t}\n\t\t// Mail and storage: what the stage set — a real server, a real bucket —\n\t\t// and otherwise the dev service it runs, which `services` has already\n\t\t// checked it may.\n\t\tif (owner && SERVICE_KINDS[owner.kind]) {\n\t\t\t// A file server's address is decided once, above, for every process\n\t\t\t// and every site's build alike.\n\t\t\tif (owner.kind === 'file-server') return fileServerUrls.get(owner.id);\n\t\t\tif (custom[key] !== undefined) return custom[key];\n\t\t\tif (owner.kind === 'objects') {\n\t\t\t\tconst origin = providedKeyFor(owner.id, owner.kind, 'signedOrigin');\n\t\t\t\tif (key === origin) {\n\t\t\t\t\treturn signedOrigins([owner.id], (k) => valueFor(app, k, owner))[key];\n\t\t\t\t}\n\t\t\t\t// The stack's MinIO serves only the buckets it was given: one on a\n\t\t\t\t// provider is what the provider wrote, or nothing yet.\n\t\t\t\tif (!services.minio.includes(owner.id)) return undefined;\n\t\t\t}\n\t\t\treturn outside[key];\n\t\t}\n\n\t\t// Supplied by somebody: a third party's credentials, and — deployed —\n\t\t// the secrets the stage generated.\n\t\tif (owner && suppliedOnly(owner.kind, owner.id, key, local)) {\n\t\t\tconst value = custom[key];\n\t\t\tif (value === undefined) {\n\t\t\t\tthrow new StageSecretMissing(app.name, key, stage);\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\n\t\t// Set by hand wins over derived: it is the stage saying what it is.\n\t\tif (custom[key] !== undefined) return custom[key];\n\n\t\t// A cache, in the stack's Redis, by its name on the network — and a\n\t\t// WebSocket surface's publisher, on its pub/sub.\n\t\tif (owner?.kind === 'cache') return redis?.urls[key];\n\t\tif (\n\t\t\towner?.kind === 'websocket-api' &&\n\t\t\tkey === providedKeyFor(owner.id, owner.kind, 'publisherConnectionString')\n\t\t) {\n\t\t\treturn redis?.urls[key];\n\t\t}\n\n\t\t// A surface's or a site's address is its public one for every process\n\t\t// — a backend, a worker, a site's server — as `gkm dev` hands it.\n\t\treturn outside[key];\n\t};\n\n\t// What the stage resolves for its `Telemetry` node, before a process is\n\t// named: the stack's OpenObserve, or the provider `deploy.telemetry` names.\n\tconst telemetryValues: Record<string, string> | undefined = logs\n\t\t? telemetryEnv(\n\t\t\t\t{\n\t\t\t\t\tendpoint: logs.appEnv.OTEL_EXPORTER_OTLP_ENDPOINT,\n\t\t\t\t\theaders: logs.appEnv.OTEL_EXPORTER_OTLP_HEADERS,\n\t\t\t\t},\n\t\t\t\ttelemetry?.sampleRate ?? 1,\n\t\t\t)\n\t\t: telemetry?.provider === 'otlp'\n\t\t\t? otlpTelemetryEnv(telemetry)\n\t\t\t: undefined;\n\n\t/** Each key one backend process reads, resolved for this stage. */\n\tconst valuesFor = (\n\t\tapp: Pick<StackApp, 'name' | 'id' | 'kind'>,\n\t\tkeys: ReadonlySet<string>,\n\t): Record<string, string> => {\n\t\tconst values: Record<string, string> = {};\n\t\tfor (const key of [...keys].sort()) {\n\t\t\t// The node's keys are the stage's telemetry, added per process.\n\t\t\tif (isTelemetryKey(key)) continue;\n\t\t\tconst owner = owners.get(key) ?? storageOwner(key, plan);\n\t\t\tif ((STORAGE_KEYS as readonly string[]).includes(key)) {\n\t\t\t\t// The stage's own key pair where it set one — an external bucket\n\t\t\t\t// signs with it — and otherwise the stack's MinIO's.\n\t\t\t\tconst value = custom[key] ?? storageValue(key, storage);\n\t\t\t\tif (value !== undefined) values[key] = value;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst value = valueFor(app, key, owner);\n\t\t\tif (value !== undefined) values[key] = value;\n\t\t}\n\t\treturn values;\n\t};\n\n\t// The stage's own keys — set by hand, read with `get('X')` — which every\n\t// process is handed, as `gkm dev` hands them (`processEnvKeys`).\n\tconst stageKeys = Object.keys(custom);\n\n\tfor (const app of apps) {\n\t\tconst site = manifest[app.id];\n\t\tif (site?.kind === 'site') {\n\t\t\tconst args = publicBuildValues(\n\t\t\t\tsite,\n\t\t\t\tmanifest,\n\t\t\t\t(key) => valueFor(app, key, owners.get(key)) ?? plannedOrigins.get(key),\n\t\t\t\tcustom,\n\t\t\t\t// Built here for a deployed stage, an image that cannot say where\n\t\t\t\t// its pages load files from is refused — not shipped without it.\n\t\t\t\t!local && app.build ? { requireFileOrigins: { stage } } : {},\n\t\t\t);\n\t\t\tif (app.prerender && input.prerenderRun) {\n\t\t\t\targs[PRERENDER_RUN_ARG] = input.prerenderRun;\n\t\t\t}\n\t\t\tif (app.build && Object.keys(args).length > 0) app.build.args = args;\n\t\t\t// The build runs before the stack does: none of these answers yet.\n\t\t\tconst offline = offlineBuildHosts(site, manifest, (key) =>\n\t\t\t\tvalueFor(app, key, owners.get(key)),\n\t\t\t);\n\t\t\tif (app.build && offline.length > 0) app.build.offlineHosts = offline;\n\t\t\t// A static bundle reads nothing at runtime. A site that runs a server\n\t\t\t// — Next, TanStack Start — reads its edges and the stage's secrets\n\t\t\t// on it, as a backend does; its public values stay build arguments.\n\t\t\tif (!app.runtime) continue;\n\t\t}\n\t\t// Built to be pushed, an image is every stage's: what it reads at\n\t\t// runtime is the deploy's business, not the build's.\n\t\tif (input.buildOnly) continue;\n\n\t\tconst keys =\n\t\t\tprocessEnvKeys(manifest, { app: app.name }, stageKeys) ?? new Set();\n\t\tconst values = valuesFor(app, keys);\n\n\t\t// Telemetry: the stage's, to a backend with an edge to the node. A\n\t\t// site's server gets none — the exporter is the API's.\n\t\tapp.env = {\n\t\t\t...scopeTelemetryEnv(values, {\n\t\t\t\tuses:\n\t\t\t\t\tapp.kind !== 'site' && telemetryOf(manifest, app.id) !== undefined,\n\t\t\t\tserviceName: app.name,\n\t\t\t\t...(telemetryValues ? { telemetry: telemetryValues } : {}),\n\t\t\t}),\n\t\t\tNODE_ENV: 'production',\n\t\t\tPORT: String(app.port),\n\t\t\tSTAGE: stage,\n\t\t};\n\n\t\tfor (const [key, value] of Object.entries(app.env)) {\n\t\t\tif (/[\\r\\n]/.test(value)) throw new EnvValueMultiline(app.name, key);\n\t\t}\n\t}\n\n\t// A mobile app runs on a phone, which has only the public addresses — as\n\t// a browser does — so its values resolve as a site's do.\n\tconst mobileApps: StackMobileApp[] = [];\n\tfor (const declaration of Object.values(manifest)) {\n\t\tif (declaration.kind !== 'mobile-app') continue;\n\t\tconst app = {\n\t\t\tname: appKey(declaration.id),\n\t\t\tid: declaration.id,\n\t\t\tkind: 'site' as const,\n\t\t};\n\t\tmobileApps.push({\n\t\t\tname: app.name,\n\t\t\tid: app.id,\n\t\t\tvalues: publicBuildValues(\n\t\t\t\tdeclaration,\n\t\t\t\tmanifest,\n\t\t\t\t(key) => valueFor(app, key, owners.get(key)) ?? plannedOrigins.get(key),\n\t\t\t\tcustom,\n\t\t\t),\n\t\t});\n\t}\n\n\t// A worker reaches every surface at its public address: it is never one,\n\t// so no address is its own — unless SNS pushes to it.\n\tfor (const worker of input.buildOnly ? [] : workers) {\n\t\tconst keys =\n\t\t\tprocessEnvKeys(manifest, { workers: [worker.id] }, stageKeys) ??\n\t\t\tnew Set();\n\t\tconst resolved = valuesFor(\n\t\t\t{ name: worker.name, id: worker.id, kind: 'rest-api' },\n\t\t\tkeys,\n\t\t);\n\t\tconst push = local\n\t\t\t? undefined\n\t\t\t: workerPush(worker, input.subscribers?.[worker.id] ?? [], resolved, {\n\t\t\t\t\tstage,\n\t\t\t\t\t...(domain ? { domain } : {}),\n\t\t\t\t});\n\t\tif (push) {\n\t\t\tworker.push = push;\n\t\t\tif (proxy === 'traefik') edgeServices.add(worker.name);\n\t\t}\n\t\tworker.env = {\n\t\t\t...scopeTelemetryEnv(resolved, {\n\t\t\t\tuses: telemetryOf(manifest, worker.id) !== undefined,\n\t\t\t\tserviceName: worker.name,\n\t\t\t\t...(telemetryValues ? { telemetry: telemetryValues } : {}),\n\t\t\t}),\n\t\t\t...(push && !input.recordingSubscriptions\n\t\t\t\t? {\n\t\t\t\t\t\t[SNS_SUBSCRIPTIONS_KEY]: recordedSubscriptions(\n\t\t\t\t\t\t\tworker,\n\t\t\t\t\t\t\tpush,\n\t\t\t\t\t\t\tinput.pushSubscriptions?.[worker.id],\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\tNODE_ENV: 'production',\n\t\t\tPORT: String(worker.port),\n\t\t\tSTAGE: stage,\n\t\t};\n\t\tfor (const [key, value] of Object.entries(worker.env)) {\n\t\t\tif (/[\\r\\n]/.test(value)) throw new EnvValueMultiline(worker.name, key);\n\t\t}\n\t}\n\n\t// Each file server's processors: on its own host when the stack's MinIO\n\t// serves it — their patterns to their container, every other path to the\n\t// bucket — and otherwise on a host the CDN in front of the bucket reaches,\n\t// with the secret it sends.\n\tfor (const unit of processors) {\n\t\tconst served = fileServers.get(unit.id);\n\t\tif (served) {\n\t\t\tserved.route = {\n\t\t\t\t...served.route,\n\t\t\t\thandlers: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: unit.name,\n\t\t\t\t\t\tprefixes: unit.prefixes,\n\t\t\t\t\t\tupstreams: [{ service: unit.name, port: unit.port }],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t} else if (!local && !input.buildOnly) {\n\t\t\tif (!domain) throw new NoDomainForStage(stage);\n\t\t\tconst key = originSecretKey(unit.id);\n\t\t\tconst secret = custom[key];\n\t\t\tif (!secret) throw new ProcessorOriginSecretMissing(unit.id, key, stage);\n\t\t\tunit.origin = { host: processorOriginHost(unit.id, domain), secret };\n\t\t}\n\t\tif (proxy === 'traefik' && (served || unit.origin)) {\n\t\t\tedgeServices.add(unit.name);\n\t\t}\n\n\t\tif (input.buildOnly) continue;\n\t\tconst keys =\n\t\t\tprocessEnvKeys(manifest, { processors: [unit.id] }, stageKeys) ??\n\t\t\tnew Set();\n\t\tunit.env = {\n\t\t\t// Telemetry: the stage's, when the file server has an edge to the node.\n\t\t\t...scopeTelemetryEnv(\n\t\t\t\tvaluesFor({ name: unit.name, id: unit.id, kind: 'rest-api' }, keys),\n\t\t\t\t{\n\t\t\t\t\tuses: telemetryOf(manifest, unit.id) !== undefined,\n\t\t\t\t\tserviceName: unit.name,\n\t\t\t\t\t...(telemetryValues ? { telemetry: telemetryValues } : {}),\n\t\t\t\t},\n\t\t\t),\n\t\t\tNODE_ENV: 'production',\n\t\t\tPORT: String(unit.port),\n\t\t\tSTAGE: stage,\n\t\t};\n\t\tfor (const [key, value] of Object.entries(unit.env)) {\n\t\t\tif (/[\\r\\n]/.test(value)) throw new EnvValueMultiline(unit.name, key);\n\t\t}\n\t}\n\n\t// Each watched bucket in the stack's MinIO posts its events to the worker\n\t// that runs one of its subscribers, across the stack's network — with the\n\t// token that worker was handed, so the two cannot disagree. Not where its\n\t// events come from SNS: then the storage publishes them itself.\n\tif (storage && !input.buildOnly) {\n\t\tconst watched = watchedBuckets(manifest, input.subscribers ?? {});\n\t\tfor (const [bucket, workerId] of watched) {\n\t\t\tif (!services.minio.includes(bucket)) continue;\n\t\t\tconst worker = workers.find((w) => w.id === workerId);\n\t\t\tconst relay =\n\t\t\t\tworker?.env?.[\n\t\t\t\t\tprovidedKeyFor(bucket, 'objects', 'eventsConnectionString')\n\t\t\t\t];\n\t\t\tconst token =\n\t\t\t\tworker?.env?.[providedKeyFor(bucket, 'objects', 'eventsToken')];\n\t\t\tif (!worker || !relay || relay.startsWith('sns:') || !token) continue;\n\t\t\tstorage.webhooks.push({\n\t\t\t\tbucket,\n\t\t\t\tendpoint: `http://${hostOf(worker.name)}:${worker.port}${objectsRoute(bucket)}`,\n\t\t\t\ttoken,\n\t\t\t});\n\t\t}\n\t}\n\n\t// Mailpit posts what an inbox receives to the worker that runs every\n\t// inbox subscriber, across the stack's network, with the token that worker\n\t// was handed. Locally only: deployed, SES publishes to the inbox's topic.\n\tlet inboxRelay: string | undefined;\n\tif (local && infra.includes('mailpit') && !input.buildOnly) {\n\t\tconst relayId = inboxRelayWorker(manifest, input.subscribers ?? {});\n\t\tconst relay = workers.find((w) => w.id === relayId);\n\t\tconst token = relay?.env?.[INBOX_RELAY_TOKEN_KEY];\n\t\tif (relay && token) {\n\t\t\tinboxRelay = inboxWebhookUrl(\n\t\t\t\t`http://${hostOf(relay.name)}:${relay.port}`,\n\t\t\t\ttoken,\n\t\t\t);\n\t\t}\n\t}\n\n\t// The stage's certificate, as the proxy's container reads it: its own,\n\t// where it set one — any stage, either proxy — and otherwise, on the\n\t// local stage, the one gkm's local CA issues as the stack is written. A\n\t// deployed stage without one asks Let's Encrypt.\n\tconst tls: EdgeTls =\n\t\tcertificate || local\n\t\t\t? {\n\t\t\t\t\tkind: 'files',\n\t\t\t\t\t...(proxy === 'caddy'\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tcertFile: `${CADDY_TLS_DIR}/cert.pem`,\n\t\t\t\t\t\t\t\tkeyFile: `${CADDY_TLS_DIR}/key.pem`,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: edgeCertificatePaths(project)),\n\t\t\t\t}\n\t\t\t: { kind: 'acme' };\n\t// gkm's local CA: the local stage's issuer, unless it set its own.\n\tconst authority =\n\t\tlocal && !certificate\n\t\t\t? (input.localAuthority ?? localAuthorityPaths(gkmHome()))\n\t\t\t: undefined;\n\t// The root the stage's certificate chains to, on this machine: gkm's, or\n\t// the one its own certificate names. What the local stack's containers\n\t// trust for the stage's public hosts.\n\tconst root = authority?.certFile ?? certificate?.caFile;\n\n\t// The stage's backups: a deployed stage with Postgres, unless it said\n\t// `false`. A stack that only builds runs nothing, so has none.\n\tconst backupsChoice = input.buildOnly\n\t\t? undefined\n\t\t: stageBackups(workspace, manifest, stage);\n\tconst backups =\n\t\tbackupsChoice?.mode === 'on' && infra.includes('postgres')\n\t\t\t? stackBackups({\n\t\t\t\t\tworkspace,\n\t\t\t\t\tstage,\n\t\t\t\t\tproject,\n\t\t\t\t\tplan,\n\t\t\t\t\tbackups: backupsChoice.backups,\n\t\t\t\t\tcustom,\n\t\t\t\t\tseed,\n\t\t\t\t\tsuperuser: credential.containers.postgres,\n\t\t\t\t\t...(telemetryValues ? { telemetry: telemetryValues } : {}),\n\t\t\t\t})\n\t\t\t: undefined;\n\n\t// The sites behind a password on this stage, each with its login.\n\tif (!local) {\n\t\tfor (const app of apps) {\n\t\t\tconst site = manifest[app.id];\n\t\t\tif (site?.kind !== 'site') continue;\n\t\t\tconst key = sitePasswordKey(manifest, site, stage);\n\t\t\tif (key) app.auth = siteAuth(stage, key, custom);\n\t\t}\n\t}\n\n\t// The wildcard site's tenants, on a deployed stage: every label under\n\t// the domain nothing else answers, and where their certificate comes from.\n\tconst wildcard = local\n\t\t? undefined\n\t\t: stackWildcard(apps, {\n\t\t\t\tmanifest,\n\t\t\t\tbyId,\n\t\t\t\tworkspace,\n\t\t\t\tstage,\n\t\t\t\tproxy,\n\t\t\t\tcertificate: certificate !== undefined,\n\t\t\t\thostOf,\n\t\t\t});\n\n\t// One route per public host — the data both proxies render.\n\tconst routes: EdgeRoute[] = [\n\t\t...apps.map(\n\t\t\t(app): EdgeRoute => ({\n\t\t\t\tname: app.name,\n\t\t\t\thost: app.host,\n\t\t\t\t...(app.aliases?.length ? { aliases: app.aliases } : {}),\n\t\t\t\t...(app.redirects?.length\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t// Only a site has redirects, so its URL is the https origin.\n\t\t\t\t\t\t\tredirects: { hosts: app.redirects, to: app.url },\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\t...(wildcard?.site === app.id ? { wildcard: wildcard.edge } : {}),\n\t\t\t\tupstreams: replicaNames(app).map((service) => ({\n\t\t\t\t\tservice,\n\t\t\t\t\tport: app.port,\n\t\t\t\t})),\n\t\t\t\tstreaming: true,\n\t\t\t\t...(app.auth\n\t\t\t\t\t? { auth: { user: app.auth.user, hash: app.auth.hash } }\n\t\t\t\t\t: {}),\n\t\t\t\t...(app.limits ? { limits: app.limits } : {}),\n\t\t\t\thealth: app.kind === 'site' ? '/' : '/health',\n\t\t\t}),\n\t\t),\n\t\t...[...fileServers.values()].map(({ route }) => route),\n\t\t...processors.flatMap(({ name, port, prefixes, origin }): EdgeRoute[] =>\n\t\t\torigin\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\thost: origin.host,\n\t\t\t\t\t\t\tupstreams: [{ service: name, port }],\n\t\t\t\t\t\t\tstreaming: false,\n\t\t\t\t\t\t\tprefixes,\n\t\t\t\t\t\t\trequireHeader: {\n\t\t\t\t\t\t\t\tname: ORIGIN_VERIFY_HEADER,\n\t\t\t\t\t\t\t\tvalue: origin.secret,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\thealth: '/health',\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: [],\n\t\t),\n\t\t...workers.flatMap(({ name, port, push }): EdgeRoute[] =>\n\t\t\tpush\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\thost: push.host,\n\t\t\t\t\t\t\tupstreams: [{ service: name, port }],\n\t\t\t\t\t\t\tstreaming: false,\n\t\t\t\t\t\t\tpaths: push.paths,\n\t\t\t\t\t\t\thealth: '/health',\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: [],\n\t\t),\n\t\t...(logs?.host && logs.public\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: LOGS_SERVICE,\n\t\t\t\t\t\thost: logs.host,\n\t\t\t\t\t\tupstreams: [{ service: LOGS_SERVICE, port: LOGS_PORT }],\n\t\t\t\t\t\tstreaming: true,\n\t\t\t\t\t\tallow: logs.public.allow,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: []),\n\t];\n\tif (mailInbox) {\n\t\t// Before every other route is checked against every other, so an app\n\t\t// on the inbox's host is told what the host is for.\n\t\tconst taken = routes.find((route) =>\n\t\t\trouteHosts(route).includes(mailInbox.host),\n\t\t);\n\t\tif (taken) throw new MailInboxHostTaken(mailInbox.host, taken.name);\n\t\troutes.push({\n\t\t\tname: 'mailpit',\n\t\t\thost: mailInbox.host,\n\t\t\tupstreams: [{ service: 'mailpit', port: MAILPIT_WEB_PORT }],\n\t\t\t// Its UI follows new mail live, over a websocket.\n\t\t\tstreaming: true,\n\t\t});\n\t}\n\tassertHostsUnique(routes);\n\tconst layout = input.layout ?? defaultLayout(workspace.root);\n\tconst compose = stackFile({\n\t\tproject,\n\t\tplan,\n\t\tinfra,\n\t\tapps,\n\t\tworkers,\n\t\tprocessors,\n\t\tcredentials: credential.containers,\n\t\t...(storage ? { storage } : {}),\n\t\t...(inboxRelay ? { inboxRelay } : {}),\n\t\t...(logs ? { logs } : {}),\n\t\t...(redis ? { redis } : {}),\n\t\t...(backups ? { backups } : {}),\n\t\thttps,\n\t\thttp,\n\t\tcomposeDir: join(workspace.root, stackDir(stage)),\n\t\tbuildRoot: layout.buildRoot,\n\t\tworkspaceRoot: workspace.root,\n\t\tenvFiles: !input.buildOnly,\n\t\tproxy,\n\t\tedge: new Map(\n\t\t\t[...edgeServices].map((service) => [service, hostOf(service)]),\n\t\t),\n\t\t// The local stage's own public hosts, which a container's own loopback\n\t\t// would answer, and the root their certificate chains to.\n\t\t...(local\n\t\t\t? {\n\t\t\t\t\tlocalEdge: {\n\t\t\t\t\t\thosts: stackPublicHosts(routes),\n\t\t\t\t\t\t...(root ? { authority: root } : {}),\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t});\n\n\tconst dockerfiles: Record<string, string> = {};\n\tfor (const app of apps) {\n\t\tif (!app.build) continue;\n\t\t// The same Dockerfile `gkm docker` writes: the image is built inside\n\t\t// Docker from a pruned slice of the build root, and nothing is built\n\t\t// here first.\n\t\tdockerfiles[app.build.dockerfile] = appDockerfile(\n\t\t\tapp.name,\n\t\t\tworkspace.apps[app.name]!,\n\t\t\t{\n\t\t\t\tlayout,\n\t\t\t\tworkspaceRoot: workspace.root,\n\t\t\t\tapps: workspace.apps,\n\t\t\t\tmanifest,\n\t\t\t\tcache: STACK_CACHE,\n\t\t\t\t// A site's clients trace at this stage's sample rate.\n\t\t\t\tworkspace,\n\t\t\t\tstage,\n\t\t\t\t// Every build argument the site is handed, declared, or the\n\t\t\t\t// build drops it — but the run it is pre-rendered for, which\n\t\t\t\t// its Dockerfile declares itself.\n\t\t\t\t...(app.kind === 'site' && app.build.args\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tpublicUrlArgs: Object.keys(app.build.args).filter(\n\t\t\t\t\t\t\t\t(key) => key !== PRERENDER_RUN_ARG,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t);\n\t}\n\tfor (const worker of workers) {\n\t\tif (!worker.build) continue;\n\t\tdockerfiles[worker.build.dockerfile] = workerDockerfile(\n\t\t\t{ id: worker.id, name: worker.name, app: worker.host },\n\t\t\tworkspace.apps[worker.host]!,\n\t\t\t{\n\t\t\t\tlayout,\n\t\t\t\tworkspaceRoot: workspace.root,\n\t\t\t\tmanifest,\n\t\t\t\tcache: STACK_CACHE,\n\t\t\t},\n\t\t);\n\t}\n\tfor (const unit of processors) {\n\t\tif (!unit.build) continue;\n\t\tdockerfiles[unit.build.dockerfile] = processorDockerfile(\n\t\t\t{ id: unit.id, name: unit.name, app: unit.host },\n\t\t\tworkspace.apps[unit.host]!,\n\t\t\t{\n\t\t\t\tlayout,\n\t\t\t\tworkspaceRoot: workspace.root,\n\t\t\t\tmanifest,\n\t\t\t\tcache: STACK_CACHE,\n\t\t\t},\n\t\t);\n\t}\n\n\treturn {\n\t\tproject,\n\t\tstage,\n\t\tlocal,\n\t\t...(authority ? { authority } : {}),\n\t\tapps,\n\t\tworkers,\n\t\tprocessors,\n\t\tmobileApps,\n\t\tinfra,\n\t\tcompose,\n\t\tproxy,\n\t\troutes,\n\t\t...(wildcard\n\t\t\t? {\n\t\t\t\t\twildcard: {\n\t\t\t\t\t\tsite: wildcard.site,\n\t\t\t\t\t\thost: `*.${wildcard.edge.domain}`,\n\t\t\t\t\t\ttls: wildcard.edge.tls.kind,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(proxy === 'caddy'\n\t\t\t? {\n\t\t\t\t\tcaddyfile: edgeCaddyfile(routes, {\n\t\t\t\t\t\ttls,\n\t\t\t\t\t\tedgeToken: outside[EDGE_TOKEN_KEY],\n\t\t\t\t\t\t...(local ? { redirects: false } : {}),\n\t\t\t\t\t}),\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\ttraefik: traefikDynamicFile(routes, {\n\t\t\t\t\t\tproject,\n\t\t\t\t\t\ttls,\n\t\t\t\t\t\tedgeToken: outside[EDGE_TOKEN_KEY],\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t...(certificate ? { tls: certificate } : {}),\n\t\tdockerfiles,\n\t\tplan,\n\t\tcredential,\n\t\tresolution: {\n\t\t\t...derivation,\n\t\t\t// A file server at its address, as the apps are handed it.\n\t\t\taddresses: {\n\t\t\t\t...publicAddresses,\n\t\t\t\t...Object.fromEntries(fileServerUrls),\n\t\t\t},\n\t\t},\n\t\t...(storage ? { storage } : {}),\n\t\tdevServices: local ? [] : devServicesUsed(services),\n\t\t...(logs ? { logs } : {}),\n\t\t...(telemetry ? { telemetry } : {}),\n\t\t...(redis ? { redis } : {}),\n\t\t...(backups ? { backups } : {}),\n\t\t...(mailInbox ? { mailInbox } : {}),\n\t\twarnings,\n\t};\n}\n\n/** The stack's MinIO's value for one of the S3 client's keys. */\nfunction storageValue(\n\tkey: string,\n\tstorage: StackStorage | undefined,\n): string | undefined {\n\tif (!storage) return undefined;\n\tif (key === 'AWS_ACCESS_KEY_ID') return storage.user;\n\tif (key === 'AWS_SECRET_ACCESS_KEY') return storage.password;\n\tif (key === 'AWS_REGION') return MINIO_REGION;\n\treturn undefined;\n}\n\n/** Which bucket an S3 credential key belongs to — the first one declared. */\nfunction storageOwner(key: string, plan: Plan): PlannedResource | undefined {\n\tif (!(STORAGE_KEYS as readonly string[]).includes(key)) return undefined;\n\treturn plan.resources.find((r) => r.kind === 'objects');\n}\n\n/** The apps a stack runs: every API and every site, at its stage address. */\nfunction stackApps(\n\tworkspace: NormalizedWorkspace,\n\tmanifest: ConstructManifest,\n\tplan: Plan,\n\toptions: {\n\t\tlocal: boolean;\n\t\tstage: string;\n\t\thttps: number;\n\t\tidentity: DeployIdentity;\n\t\timages: StackInput['images'];\n\t},\n): StackApp[] {\n\tconst apps: StackApp[] = [];\n\tconst resources = new Map(plan.resources.map((r) => [r.id, r]));\n\n\tfor (const [id, declaration] of Object.entries(manifest)) {\n\t\tif (\n\t\t\tdeclaration.kind !== 'rest-api' &&\n\t\t\tdeclaration.kind !== 'websocket-api' &&\n\t\t\tdeclaration.kind !== 'site'\n\t\t)\n\t\t\tcontinue;\n\n\t\tconst name = appKey(id);\n\t\tconst app = workspace.apps[name];\n\t\tconst resource = resources.get(id);\n\t\tif (!app || !resource || !app.port) continue;\n\n\t\tconst { host, aliases, redirects } = appHosts(\n\t\t\tname,\n\t\t\tapp,\n\t\t\tworkspace,\n\t\t\tresource,\n\t\t\toptions,\n\t\t);\n\t\tconst site = declaration.kind === 'site';\n\t\tconst { ref, tag } = stackImage(name, options);\n\n\t\tapps.push({\n\t\t\tapp: name,\n\t\t\tname,\n\t\t\tid,\n\t\t\tkind: declaration.kind,\n\t\t\t...(declaration.kind === 'site' ? { variant: declaration.variant } : {}),\n\t\t\treplicas:\n\t\t\t\tdeclaration.kind === 'websocket-api' ? (declaration.replicas ?? 1) : 1,\n\t\t\t...(declaration.kind === 'websocket-api' && declaration.limits\n\t\t\t\t? { limits: declaration.limits }\n\t\t\t\t: {}),\n\t\t\truntime: !site || runsServer(declaration),\n\t\t\tpath: app.path,\n\t\t\tport: app.port,\n\t\t\thost,\n\t\t\t...(aliases.length ? { aliases } : {}),\n\t\t\t...(redirects.length ? { redirects } : {}),\n\t\t\turl: `${declaration.kind === 'websocket-api' ? 'wss' : 'https'}://${host}${options.local && options.https !== 443 ? `:${options.https}` : ''}`,\n\t\t\tref,\n\t\t\ttag,\n\t\t\t...(options.images.mode === 'build'\n\t\t\t\t? {\n\t\t\t\t\t\tbuild: {\n\t\t\t\t\t\t\tdockerfile: `${stackDir(options.stage)}/Dockerfile.${name}`,\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t});\n\t}\n\n\t// A site built against its stage waits on each app its edges name.\n\tconst byId = new Map(apps.map((app) => [app.id, app.name]));\n\tfor (const app of apps) {\n\t\tconst declaration = manifest[app.id];\n\t\tif (declaration?.kind !== 'site' || declaration.prerender !== 'stage') {\n\t\t\tcontinue;\n\t\t}\n\t\tconst against = declaration.dependencies\n\t\t\t.map(({ target }) => byId.get(target))\n\t\t\t.filter((name): name is string => !!name && name !== app.name);\n\t\tapp.prerender = { against: [...new Set(against)].sort() };\n\t}\n\n\treturn apps.sort((a, b) => a.name.localeCompare(b.name));\n}\n\n/**\n * Where SNS pushes to a worker on a deployed stage, or nothing when it pushes\n * to none of its subscribers.\n *\n * A subscriber is pushed to when the connection string its deliveries come\n * from — its topic's, or its bucket's events — as this stage resolved it for\n * the worker, is an SNS one — the same test the worker's own\n * startup makes, so the edge exposes a route exactly when the worker mounts\n * it. Each such route, and nothing else the worker serves, answers on\n * `<worker>.<domain>`.\n */\nexport function workerPush(\n\tworker: Pick<StackWorker, 'name'>,\n\tsubscribers: readonly BoundSubscriber[],\n\tenv: Readonly<Record<string, string>>,\n\toptions: { stage: string; domain?: string },\n): WorkerPush | undefined {\n\tconst pushed = subscribers\n\t\t.filter(({ connectionKey }) => env[connectionKey]?.startsWith('sns:'))\n\t\t.filter(\n\t\t\t(subscriber, index, all) =>\n\t\t\t\tall.findIndex((s) => s.name === subscriber.name) === index,\n\t\t)\n\t\t.sort((a, b) => a.name.localeCompare(b.name));\n\tif (pushed.length === 0) return undefined;\n\tif (!options.domain) throw new NoDomainForStage(options.stage);\n\n\tconst host = `${worker.name}.${options.domain}`;\n\tconst url = `https://${host}`;\n\treturn {\n\t\thost,\n\t\turl,\n\t\tpaths: pushed.map(({ name }) => subscriberRoute(name)),\n\t\tsubscribers: pushed.map(({ name, connectionKey, events }) => ({\n\t\t\tname,\n\t\t\tconnectionKey,\n\t\t\tendpoint: `${url}${subscriberRoute(name)}`,\n\t\t\t...(events ? { events } : {}),\n\t\t})),\n\t};\n}\n\n/** A pushed subscriber the deploy recorded no SNS subscription for. */\nexport class PushSubscriptionMissing extends GkmError {\n\tconstructor(\n\t\treadonly worker: string,\n\t\treadonly subscriber: string,\n\t) {\n\t\tsuper(\n\t\t\t`SNS pushes to '${subscriber}' on the worker '${worker}', and the ` +\n\t\t\t\t`deploy recorded no subscription for it, so the worker would mount ` +\n\t\t\t\t`no route and SNS would deliver nowhere. Deploy the stage, which ` +\n\t\t\t\t`subscribes each pushed subscriber and records its ARN.`,\n\t\t);\n\t\tthis.name = 'PushSubscriptionMissing';\n\t}\n}\n\n/**\n * The worker's `GKM_SNS_SUBSCRIPTIONS`: each pushed subscriber's recorded\n * subscription ARN, and nothing for a subscriber it does not run.\n *\n * @throws {PushSubscriptionMissing} when one has none\n */\nfunction recordedSubscriptions(\n\tworker: Pick<StackWorker, 'name'>,\n\tpush: WorkerPush,\n\trecorded: Readonly<Record<string, string>> = {},\n): string {\n\tconst arns: Record<string, string> = {};\n\tfor (const { name } of push.subscribers) {\n\t\tconst arn = recorded[name];\n\t\tif (!arn) throw new PushSubscriptionMissing(worker.name, name);\n\t\tarns[name] = arn;\n\t}\n\treturn JSON.stringify(arns);\n}\n\n/**\n * A wildcard site on a deployed stage with nowhere to get a certificate for\n * its tenants' hosts from. Let's Encrypt issues a wildcard certificate only\n * over the DNS challenge, so the stage either brings its own or gives the\n * proxy a way to get one.\n */\nexport class WildcardSiteCertificateMissing extends GkmError {\n\tconstructor(\n\t\treadonly site: string,\n\t\treadonly stage: string,\n\t\treadonly proxy: ComposeProxy,\n\t\treadonly domain: string,\n\t) {\n\t\tsuper(\n\t\t\tproxy === 'traefik'\n\t\t\t\t? `'${site}' answers on every subdomain of ${domain}, and '${stage}' ` +\n\t\t\t\t\t\t`has no certificate for them. Set deploy.compose.tls for ` +\n\t\t\t\t\t\t`'${stage}' to a *.${domain} certificate, or manage ${domain} ` +\n\t\t\t\t\t\t`with dns: { '<root domain>': { provider: 'route53' } } so the ` +\n\t\t\t\t\t\t`shared edge gets one over the DNS challenge.`\n\t\t\t\t: `'${site}' answers on every subdomain of ${domain}, and '${stage}' ` +\n\t\t\t\t\t\t`has no certificate for them. Set deploy.compose.tls for ` +\n\t\t\t\t\t\t`'${stage}' to a *.${domain} certificate, or give the site ` +\n\t\t\t\t\t\t`\\`hosts\\` so Caddy gets one per tenant, on demand.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteCertificateMissing';\n\t}\n}\n\n/**\n * A deployed stage's wildcard site, as its edge serves it: the labels it\n * never takes, and its certificate — the stage's own (`deploy.compose.tls`)\n * first; then, on the shared Traefik edge, a `*.<domain>` one over the DNS\n * challenge when Route 53 manages the domain; on the stack's own Caddy, one\n * per host on demand, asked of the site's `hosts` route.\n *\n * @throws {WildcardSiteCertificateMissing} when neither applies\n */\nfunction stackWildcard(\n\tapps: readonly StackApp[],\n\toptions: {\n\t\tmanifest: ConstructManifest;\n\t\tbyId: ReadonlyMap<string, PlannedResource>;\n\t\tworkspace: NormalizedWorkspace;\n\t\tstage: string;\n\t\tproxy: ComposeProxy;\n\t\tcertificate: boolean;\n\t\thostOf: (service: string) => string;\n\t},\n): { site: string; edge: EdgeWildcard } | undefined {\n\tconst { manifest, workspace, stage, proxy } = options;\n\tconst app = apps.find((a) => isWildcardSite(manifest[a.id]));\n\tif (!app) return undefined;\n\tconst declaration = manifest[app.id];\n\tif (!isWildcardSite(declaration)) return undefined;\n\n\tconst domain = workspace.domains?.[stage];\n\tif (!domain) throw new NoDomainForStage(stage);\n\tconst except = options.byId.get(app.id)?.protectedSubdomains ?? [];\n\n\tconst tls = ((): EdgeWildcard['tls'] => {\n\t\tif (options.certificate) return { kind: 'stage' };\n\t\tif (proxy === 'traefik') {\n\t\t\tconst dns = workspace.dns ? normalizeDnsConfig(workspace.dns) : {};\n\t\t\tconst root = findRootDomain(domain, dns);\n\t\t\tif (root && dns[root]?.provider === 'route53') return { kind: 'dns' };\n\t\t} else if (declaration.hosts) {\n\t\t\tconst surface = apps.find((a) => a.id === declaration.hosts?.surface);\n\t\t\tif (surface) {\n\t\t\t\treturn {\n\t\t\t\t\tkind: 'on-demand',\n\t\t\t\t\task: `http://${options.hostOf(surface.name)}:${surface.port}${declaration.hosts.path}`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\tthrow new WildcardSiteCertificateMissing(app.id, stage, proxy, domain);\n\t})();\n\n\treturn { site: app.id, edge: { domain, except, tls } };\n}\n\n/**\n * The first label under `stage`'s domain of every other stage's domain that\n * sits beneath it — `staging` for `staging.example.com` (or\n * `a.staging.example.com`) under `example.com`.\n */\nexport function nestedStageLabels(\n\tdomains: NormalizedWorkspace['domains'],\n\tstage: string,\n): string[] {\n\tconst own = domains?.[stage]?.toLowerCase();\n\tif (!own) return [];\n\tconst labels = new Set<string>();\n\tfor (const [other, domain] of Object.entries(domains ?? {})) {\n\t\tif (other === stage || !domain) continue;\n\t\tconst lower = domain.toLowerCase();\n\t\tif (!lower.endsWith(`.${own}`)) continue;\n\t\tconst rest = lower.slice(0, -(own.length + 1)).split('.');\n\t\tlabels.add(rest.at(-1)!);\n\t}\n\treturn [...labels].sort();\n}\n\n/** Two constructs the edge would answer on one host. */\nexport class EdgeHostTaken extends GkmError {\n\tconstructor(\n\t\treadonly host: string,\n\t\treadonly first: string,\n\t\treadonly second: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${first}' and '${second}' would both answer on ${host}, and the ` +\n\t\t\t\t`edge can send a host to only one of them. Give one a subdomain of ` +\n\t\t\t\t`its own, or rename it.`,\n\t\t);\n\t\tthis.name = 'EdgeHostTaken';\n\t}\n}\n\n/**\n * Refuse a stack where one host would be routed to two services — every\n * host of every route, its aliases and redirects included.\n */\nfunction assertHostsUnique(routes: readonly EdgeRoute[]): void {\n\tconst claimed = new Map<string, string>();\n\tfor (const route of routes) {\n\t\tfor (const host of routeHosts(route)) {\n\t\t\tconst first = claimed.get(host);\n\t\t\tif (first !== undefined && first !== route.name) {\n\t\t\t\tthrow new EdgeHostTaken(host, first, route.name);\n\t\t\t}\n\t\t\tclaimed.set(host, route.name);\n\t\t}\n\t}\n}\n\n/**\n * The image an app, worker or processor runs on the stage: the release's tag\n * with the stage on it (`stageTag`), as every target names its images.\n */\nfunction stackImage(\n\tname: string,\n\toptions: {\n\t\tstage: string;\n\t\tidentity: DeployIdentity;\n\t\timages: StackInput['images'];\n\t},\n): Pick<AppImage, 'ref' | 'tag'> {\n\tconst tag = stageTag(options.images.tag, options.stage);\n\treturn {\n\t\tref: validateImageRef(\n\t\t\timageRef(options.identity, name, options.images.registry, tag),\n\t\t),\n\t\ttag,\n\t};\n}\n\n/** Each processor unit's image, and where it is built from. */\nfunction stackProcessors(\n\tunits: readonly ProcessorUnit[],\n\toptions: {\n\t\tmanifest: ConstructManifest;\n\t\tstage: string;\n\t\tidentity: DeployIdentity;\n\t\timages: StackInput['images'];\n\t},\n): StackProcessor[] {\n\treturn units.map((unit) => {\n\t\tconst server = options.manifest[unit.id];\n\t\tconst processors =\n\t\t\tserver?.kind === 'file-server' ? (server.processors ?? []) : [];\n\t\treturn {\n\t\t\tapp: unit.name,\n\t\t\tname: unit.name,\n\t\t\tid: unit.id,\n\t\t\thost: unit.app,\n\t\t\tport: PROCESSOR_PORT,\n\t\t\tprefixes: [...new Set(processors.map((p) => p.prefix))].sort(),\n\t\t\t...stackImage(unit.name, options),\n\t\t\t...(options.images.mode === 'build'\n\t\t\t\t? {\n\t\t\t\t\t\tbuild: {\n\t\t\t\t\t\t\tdockerfile: `${stackDir(options.stage)}/Dockerfile.${unit.name}`,\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t};\n\t});\n}\n\n/** Each worker's image, and where it is built from. */\nfunction stackWorkers(\n\tunits: readonly WorkerUnit[],\n\toptions: {\n\t\tstage: string;\n\t\tidentity: DeployIdentity;\n\t\timages: StackInput['images'];\n\t},\n): StackWorker[] {\n\treturn units.map((unit) => ({\n\t\tapp: unit.name,\n\t\tname: unit.name,\n\t\tid: unit.id,\n\t\thost: unit.app,\n\t\tport: WORKER_PORT,\n\t\t...stackImage(unit.name, options),\n\t\t...(options.images.mode === 'build'\n\t\t\t? {\n\t\t\t\t\tbuild: {\n\t\t\t\t\t\tdockerfile: `${stackDir(options.stage)}/Dockerfile.${unit.name}`,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t}));\n}\n\n/**\n * The hosts an app answers on for a stage: the `gkm dev` edge's\n * `*.localhost` names for the local stage (`hostsFor`), and the stage's\n * domain — by the same rule a deploy follows — for any other. Its aliases\n * and redirects are labels under the stage's domain, as its own is.\n */\nfunction appHosts(\n\tname: string,\n\tapp: NormalizedAppConfig,\n\tworkspace: NormalizedWorkspace,\n\tresource: PlannedResource,\n\toptions: { local: boolean; stage: string },\n): ResourceHosts {\n\tif (options.local) return hostsFor(resource, workspace.name);\n\tconst domain = workspace.domains?.[options.stage];\n\t// Every label under the stage's domain, never the domain itself: a\n\t// wildcard site is no stage's root, whatever else the project has.\n\tif (resource.subdomain === WILDCARD_SUBDOMAIN) {\n\t\tif (!domain) throw new NoDomainForStage(options.stage);\n\t\treturn {\n\t\t\thost: `${WILDCARD_SUBDOMAIN}.${domain}`,\n\t\t\taliases: [],\n\t\t\tredirects: [],\n\t\t};\n\t}\n\n\tconst host = resolveHost(\n\t\tname,\n\t\tapp,\n\t\toptions.stage,\n\t\tworkspace.domains,\n\t\tisMainFrontendApp(name, app, workspace.apps),\n\t);\n\tconst under = (label: string) => {\n\t\tif (!domain) throw new NoDomainForStage(options.stage);\n\t\treturn `${label}.${domain}`;\n\t};\n\treturn {\n\t\thost,\n\t\taliases: (resource.aliases ?? []).map(under),\n\t\tredirects: (resource.redirects ?? []).map(under),\n\t};\n}\n\n/** An app's compose services, one per replica: `api`, `api-2`, `api-3`. */\nexport function replicaNames(\n\tapp: Pick<StackApp, 'name' | 'replicas'>,\n): string[] {\n\treturn [\n\t\tapp.name,\n\t\t...Array.from(\n\t\t\t{ length: app.replicas - 1 },\n\t\t\t(_, i) => `${app.name}-${i + 2}`,\n\t\t),\n\t];\n}\n\n/** Where an app container reads gkm's root certificate: mounted read-only. */\nexport const LOCAL_CA_IN_CONTAINER = '/etc/gkm/local-ca.pem';\n\n/**\n * The local stage's public hosts a container can be pointed at: every\n * route's but a wildcard's, which no host entry can name.\n */\nfunction stackPublicHosts(routes: readonly EdgeRoute[]): string[] {\n\treturn [...new Set(routes.flatMap(routeHosts))]\n\t\t.filter((host) => !host.startsWith('*.'))\n\t\t.sort();\n}\n\n/**\n * What a local stack's container needs to call the stage's own public hosts —\n * `https://api.<project>.localhost`, which a site's server-side code is\n * handed because a browser is.\n *\n * Inside a container `*.localhost` is its own loopback, so each host is\n * resolved to the host's gateway, where the edge — the stack's Caddy, or the\n * shared Traefik edge — publishes its ports. Not a network alias on the edge:\n * the address may carry the edge's published port\n * (`https://api.shop.localhost:8443`), which only the host answers on. And the\n * container trusts the root the edge's certificate chains to — gkm's, or the\n * one the stage's own certificate names — its public certificate, never a\n * key, mounted read-only.\n */\nexport function localEdgeAccess(edge: {\n\thosts: readonly string[];\n\tauthority?: string;\n}): {\n\textra_hosts: string[];\n\tvolumes: string[];\n\tenvironment: Record<string, string>;\n} {\n\treturn {\n\t\textra_hosts: edge.hosts.map((host) => `${host}:host-gateway`),\n\t\tvolumes: edge.authority\n\t\t\t? [`${edge.authority}:${LOCAL_CA_IN_CONTAINER}:ro`]\n\t\t\t: [],\n\t\tenvironment: edge.authority\n\t\t\t? { NODE_EXTRA_CA_CERTS: LOCAL_CA_IN_CONTAINER }\n\t\t\t: {},\n\t};\n}\n\n/**\n * What the build of a site that pre-renders against its stage needs to reach\n * the stage's public hosts. A deployed stage's resolve and are trusted as\n * anywhere. The local stage's are `*.localhost` — the build's own loopback —\n * so each is pointed at the host's gateway, where the edge publishes its\n * ports, and the build is handed the root the edge's certificate chains to,\n * as {@link localEdgeAccess} hands a container both.\n *\n * Not the stack's network: BuildKit builds on none but its own.\n */\nfunction prerenderBuildAccess(edge?: {\n\thosts: readonly string[];\n\tauthority?: string;\n}): { extra_hosts?: string[]; secrets?: string[] } {\n\tif (!edge) return {};\n\tconst { extra_hosts } = localEdgeAccess(edge);\n\treturn {\n\t\t...(extra_hosts.length ? { extra_hosts } : {}),\n\t\t...(edge.authority ? { secrets: [LOCAL_CA_BUILD_SECRET] } : {}),\n\t};\n}\n\n/** The compose document: the infrastructure, the apps, and the edge. */\nfunction stackFile(options: {\n\tproject: string;\n\tplan: Plan;\n\tinfra: readonly string[];\n\tapps: readonly StackApp[];\n\tworkers: readonly StackWorker[];\n\tprocessors: readonly StackProcessor[];\n\tcredentials: ContainerCredentials;\n\tstorage?: StackStorage;\n\t/** Mailpit's webhook: the inbox relay worker on the stack's network. */\n\tinboxRelay?: string;\n\tlogs?: StackLogs;\n\tredis?: StackRedis;\n\tbackups?: StackBackups;\n\thttps: number;\n\thttp: number;\n\tcomposeDir: string;\n\tbuildRoot: string;\n\tworkspaceRoot: string;\n\t/** Whether services read env files — not in a stack that only builds. */\n\tenvFiles: boolean;\n\tproxy: ComposeProxy;\n\t/** Behind the shared edge: each service it routes to, and its alias. */\n\tedge: ReadonlyMap<string, string>;\n\t/**\n\t * The local stage: its public hosts, and the root its certificate chains\n\t * to on this machine — see {@link localEdgeAccess}.\n\t */\n\tlocalEdge?: { hosts: readonly string[]; authority?: string };\n}): StackFile {\n\tconst { project, plan, apps } = options;\n\t// What reconcile defines; OpenObserve is the stack's own.\n\tconst infra = options.infra.filter((name) => name !== LOGS_SERVICE);\n\n\t// Reconcile's definitions — images, health checks, volumes — with nothing\n\t// published to the host. Ports are allocation's business there; here the\n\t// edge is the only way in.\n\tconst derived = composeFor(\n\t\t{ ...plan, containers: [...infra] },\n\t\t{\n\t\t\tproject,\n\t\t\tports: Object.fromEntries(\n\t\t\t\tportKeys(infra, plan.fakes).map((key) => [key, 0]),\n\t\t\t),\n\t\t\tcredentials: options.credentials,\n\t\t},\n\t);\n\n\tconst services: Record<string, StackService> = {};\n\tconst volumes: Record<string, Record<string, never>> = {\n\t\t...derived.volumes,\n\t\t...(options.proxy === 'caddy'\n\t\t\t? { 'caddy-data': {}, 'caddy-config': {} }\n\t\t\t: {}),\n\t\t...(options.logs ? { 'openobserve-data': {} } : {}),\n\t};\n\n\tfor (const name of infra) {\n\t\tconst {\n\t\t\tports: _ports,\n\t\t\tdepends_on,\n\t\t\tprofiles: _profiles,\n\t\t\t...service\n\t\t} = derived.services[name]!;\n\t\tservices[name] = {\n\t\t\t...service,\n\t\t\t...(depends_on?.length\n\t\t\t\t? {\n\t\t\t\t\t\tdepends_on: Object.fromEntries(\n\t\t\t\t\t\t\tdepends_on.map((dep) => [dep, HEALTHY]),\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t};\n\t}\n\n\tconst postgres = services.postgres;\n\tif (postgres) {\n\t\t// Loopback only, on a port Docker picks: gkm creates the databases and\n\t\t// roles and runs the migrations from this machine, and nothing else\n\t\t// should reach the database from outside the stack.\n\t\tpostgres.ports = [`127.0.0.1::${LOOPBACK_SERVICES.postgres}`];\n\t}\n\n\tconst minio = services.minio;\n\tif (minio && options.storage) {\n\t\tminio.environment = {\n\t\t\t...minio.environment,\n\t\t\tMINIO_ROOT_USER: options.storage.user,\n\t\t\tMINIO_ROOT_PASSWORD: options.storage.password,\n\t\t\t// Where each watched bucket's events are posted: a worker, on the\n\t\t\t// stack's network. In the environment, so a change recreates MinIO.\n\t\t\t...minioWebhookEnv(options.storage.webhooks),\n\t\t};\n\t\t// Loopback only, like Postgres: gkm creates the buckets and their\n\t\t// policies from this machine. The apps reach it on the network, and a\n\t\t// browser through a file server's host on the edge.\n\t\tminio.ports = [`127.0.0.1::${LOOPBACK_SERVICES.minio}`];\n\t}\n\n\tconst mailpit = services.mailpit;\n\tif (mailpit && options.inboxRelay) {\n\t\tmailpit.environment = {\n\t\t\t...mailpit.environment,\n\t\t\tMP_WEBHOOK_URL: options.inboxRelay,\n\t\t};\n\t}\n\n\t// Its own definition rather than reconcile's: `gkm dev`'s Redis is an\n\t// open, unbounded scratch store; this one is a production cache.\n\tif (services[REDIS_SERVICE] && options.redis) {\n\t\tservices[REDIS_SERVICE] = redisService(options.redis);\n\t}\n\n\t// Started with the infrastructure, but nothing waits on it: an app whose\n\t// telemetry cannot be delivered still serves.\n\tif (options.logs) services[LOGS_SERVICE] = logsService(options.logs);\n\n\t// The stage's backups: on the stack's network, from nothing on the host.\n\tif (options.backups) {\n\t\tservices[BACKUPS_SERVICE] = backupsService(\n\t\t\toptions.backups,\n\t\t\toptions.envFiles,\n\t\t);\n\t}\n\n\tfor (const app of apps) {\n\t\tconst definition: StackService = {\n\t\t\timage: app.ref,\n\t\t\t...(app.build\n\t\t\t\t? {\n\t\t\t\t\t\tbuild: {\n\t\t\t\t\t\t\t...composeBuildPaths({\n\t\t\t\t\t\t\t\tcomposeDir: options.composeDir,\n\t\t\t\t\t\t\t\tbuildRoot: options.buildRoot,\n\t\t\t\t\t\t\t\tworkspaceRoot: options.workspaceRoot,\n\t\t\t\t\t\t\t\tdockerfile: app.build.dockerfile,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t...(app.build.args ? { args: app.build.args } : {}),\n\t\t\t\t\t\t\t...(app.build.offlineHosts\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\textra_hosts: app.build.offlineHosts.map(\n\t\t\t\t\t\t\t\t\t\t\t(host) => `${host}:${OFFLINE_BUILD_ADDRESS}`,\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t// Built once its APIs answer, it reaches them as the stack's\n\t\t\t\t\t\t\t// containers do — see `prerenderBuildAccess`.\n\t\t\t\t\t\t\t...(app.prerender ? prerenderBuildAccess(options.localEdge) : {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\trestart: 'unless-stopped',\n\t\t\t// A static site is a bundle and reads nothing at runtime; a backend,\n\t\t\t// and a site that runs a server, reads exactly the keys in its own\n\t\t\t// file. Only a backend waits on the stack's services.\n\t\t\t...(app.runtime\n\t\t\t\t? {\n\t\t\t\t\t\tenv_file: [{ path: `./${app.name}.env`, format: 'raw' as const }],\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...(app.kind !== 'site' && infra.length\n\t\t\t\t? {\n\t\t\t\t\t\tdepends_on: Object.fromEntries(\n\t\t\t\t\t\t\tinfra.map((name) => [name, HEALTHY]),\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\thealthcheck: probe(app.port, app.kind === 'site' ? '/' : '/health'),\n\t\t\t// Every socket is a descriptor, and Docker's default soft limit is\n\t\t\t// 1024 wherever the engine was not told otherwise.\n\t\t\t...(app.kind === 'websocket-api' ? { ulimits: { nofile: NOFILE } } : {}),\n\t\t};\n\t\t// Each replica the same service under its own name: one image, one\n\t\t// env file, and an upstream each.\n\t\tfor (const name of replicaNames(app)) services[name] = { ...definition };\n\t}\n\n\t// A worker or a processor unit: no published port — its health check is\n\t// Docker's, and the edge reaches it only on the paths it routes there.\n\tfor (const worker of [...options.workers, ...options.processors]) {\n\t\tservices[worker.name] = {\n\t\t\timage: worker.ref,\n\t\t\t...(worker.build\n\t\t\t\t? {\n\t\t\t\t\t\tbuild: composeBuildPaths({\n\t\t\t\t\t\t\tcomposeDir: options.composeDir,\n\t\t\t\t\t\t\tbuildRoot: options.buildRoot,\n\t\t\t\t\t\t\tworkspaceRoot: options.workspaceRoot,\n\t\t\t\t\t\t\tdockerfile: worker.build.dockerfile,\n\t\t\t\t\t\t}),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\trestart: 'unless-stopped',\n\t\t\tenv_file: [{ path: `./${worker.name}.env`, format: 'raw' as const }],\n\t\t\t...(infra.length\n\t\t\t\t? {\n\t\t\t\t\t\tdepends_on: Object.fromEntries(\n\t\t\t\t\t\t\tinfra.map((name) => [name, HEALTHY]),\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\thealthcheck: probe(worker.port, '/health'),\n\t\t};\n\t}\n\n\t// Every container that runs the stage's code reaches its public hosts as\n\t// a browser does — through the edge, trusting gkm's root.\n\tif (options.localEdge) {\n\t\tconst access = localEdgeAccess(options.localEdge);\n\t\tfor (const name of [\n\t\t\t...apps.flatMap(replicaNames),\n\t\t\t...options.workers.map((w) => w.name),\n\t\t\t...options.processors.map((p) => p.name),\n\t\t]) {\n\t\t\tconst service = services[name];\n\t\t\tif (!service) continue;\n\t\t\tservices[name] = {\n\t\t\t\t...service,\n\t\t\t\tenvironment: { ...service.environment, ...access.environment },\n\t\t\t\t...(access.volumes.length\n\t\t\t\t\t? { volumes: [...(service.volumes ?? []), ...access.volumes] }\n\t\t\t\t\t: {}),\n\t\t\t\t...(access.extra_hosts.length\n\t\t\t\t\t? {\n\t\t\t\t\t\t\textra_hosts: [\n\t\t\t\t\t\t\t\t...(service.extra_hosts ?? []),\n\t\t\t\t\t\t\t\t...access.extra_hosts,\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t};\n\t\t}\n\t}\n\n\tif (options.proxy === 'caddy') {\n\t\tservices.caddy = {\n\t\t\timage: DEFAULT_IMAGES.caddy!,\n\t\t\trestart: 'unless-stopped',\n\t\t\tports: [`${options.https}:443`, `${options.http}:80`],\n\t\t\t// The Caddyfile and the stage's own certificate are inline configs,\n\t\t\t// added as the file is written (`withCaddyConfigs`).\n\t\t\tvolumes: ['caddy-data:/data', 'caddy-config:/config'],\n\t\t\t...EDGE_LIMITS,\n\t\t\t// Not a site built against its stage: it is built once Caddy, and\n\t\t\t// the APIs behind it, already answer.\n\t\t\tdepends_on: Object.fromEntries(\n\t\t\t\t[\n\t\t\t\t\t...apps\n\t\t\t\t\t\t.filter((app) => !(app.prerender && app.build))\n\t\t\t\t\t\t.flatMap(replicaNames),\n\t\t\t\t\t...options.workers.filter((w) => w.push).map((w) => w.name),\n\t\t\t\t\t...options.processors.map((p) => p.name),\n\t\t\t\t].map((name) => [name, STARTED]),\n\t\t\t),\n\t\t\thealthcheck: {\n\t\t\t\ttest: ['CMD', 'caddy', 'version'],\n\t\t\t\tinterval: '10s',\n\t\t\t\ttimeout: '5s',\n\t\t\t\tretries: 5,\n\t\t\t},\n\t\t};\n\t}\n\n\t// Behind the shared edge: each service it routes to joins its network,\n\t// under the alias the edge reaches it by — and keeps the stack's own,\n\t// with the same alias, which is how the stack's services reach it too.\n\t// Everything else — the databases, Redis, the workers — stays off it.\n\tfor (const [service, alias] of options.edge) {\n\t\tconst definition = services[service];\n\t\tif (!definition) continue;\n\t\tdefinition.networks = {\n\t\t\tdefault: { aliases: [alias] },\n\t\t\tedge: { aliases: [alias] },\n\t\t};\n\t}\n\n\tfor (const service of Object.values(services)) {\n\t\tif (!options.envFiles) delete service.env_file;\n\t\tservice.logging = {\n\t\t\tdriver: LOG_ROTATION.driver,\n\t\t\toptions: { ...LOG_ROTATION.options },\n\t\t};\n\t}\n\n\t// The local edge's root, for a build that reaches the stage through it.\n\tconst authority = options.localEdge?.authority;\n\tconst prerendered = apps.some((app) => app.prerender && app.build);\n\n\treturn {\n\t\tname: project,\n\t\tservices,\n\t\tvolumes,\n\t\t...(prerendered && authority\n\t\t\t? { secrets: { [LOCAL_CA_BUILD_SECRET]: { file: authority } } }\n\t\t\t: {}),\n\t\t...(options.edge.size > 0\n\t\t\t? { networks: { edge: { name: EDGE_NETWORK, external: true as const } } }\n\t\t\t: {}),\n\t};\n}\n\n/**\n * A build without a layout: the workspace is the build root, with pnpm.\n * What a caller that never looked at the filesystem gets.\n */\nfunction defaultLayout(root: string): ImageLayout {\n\treturn {\n\t\tbuildRoot: root,\n\t\tgkmRoot: '.',\n\t\ttools: {\n\t\t\tpackageManager: 'pnpm',\n\t\t\tturboVersion: TURBO_VERSION,\n\t\t\tmonorepo: true,\n\t\t},\n\t\tgkmPaths: ['gkm.config.*'],\n\t};\n}\n\n/** Render an app's env file: one `KEY=value` per line, read raw by compose. */\nexport function envFile(env: Readonly<Record<string, string>>): string {\n\treturn `${Object.entries(env)\n\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t.map(([key, value]) => `${key}=${value}`)\n\t\t.join('\\n')}\\n`;\n}\n\n/**\n * The stack with its OpenObserve on another loopback port — the one its\n * server has free for it, found before anything is written. Its UI's URL and\n * its service's published port move together; nothing else reads the port.\n */\nexport function withLogsPort(stack: ComposeStack, port: number): ComposeStack {\n\tif (!stack.logs) return stack;\n\tconst logs = logsOnPort(stack.logs, port);\n\tconst service = stack.compose.services[LOGS_SERVICE];\n\tif (logs === stack.logs || !service) return stack;\n\treturn {\n\t\t...stack,\n\t\tlogs,\n\t\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