@geekmidas/cli 10.0.0-alpha.17 → 10.0.0-alpha.170

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 (452) 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-C1h_wExz.cjs +1098 -0
  7. package/dist/EndpointGenerator-C1h_wExz.cjs.map +1 -0
  8. package/dist/EndpointGenerator-CSKhAD6W.mjs +1039 -0
  9. package/dist/EndpointGenerator-CSKhAD6W.mjs.map +1 -0
  10. package/dist/GoDaddyProvider-Cf4MIuaD.mjs +412 -0
  11. package/dist/GoDaddyProvider-Cf4MIuaD.mjs.map +1 -0
  12. package/dist/GoDaddyProvider-DK9_Jw9d.cjs +412 -0
  13. package/dist/GoDaddyProvider-DK9_Jw9d.cjs.map +1 -0
  14. package/dist/{HostingerProvider-BY26bWwB.mjs → HostingerProvider-CQebZrz3.mjs} +23 -9
  15. package/dist/HostingerProvider-CQebZrz3.mjs.map +1 -0
  16. package/dist/{HostingerProvider-BZFGYYVA.cjs → HostingerProvider-qQzo4MYp.cjs} +23 -9
  17. package/dist/HostingerProvider-qQzo4MYp.cjs.map +1 -0
  18. package/dist/LegacyStateStore-BeMRGXRi.cjs +124 -0
  19. package/dist/LegacyStateStore-BeMRGXRi.cjs.map +1 -0
  20. package/dist/LegacyStateStore-DXPHKdMk.mjs +124 -0
  21. package/dist/LegacyStateStore-DXPHKdMk.mjs.map +1 -0
  22. package/dist/LocalStateStore-BYQ9lPje.mjs +167 -0
  23. package/dist/LocalStateStore-BYQ9lPje.mjs.map +1 -0
  24. package/dist/LocalStateStore-E_sa5GR2.cjs +178 -0
  25. package/dist/LocalStateStore-E_sa5GR2.cjs.map +1 -0
  26. package/dist/OpenApiTsGenerator-5xPn-p65.mjs +534 -0
  27. package/dist/OpenApiTsGenerator-5xPn-p65.mjs.map +1 -0
  28. package/dist/OpenApiTsGenerator-CzrLGzC0.cjs +539 -0
  29. package/dist/OpenApiTsGenerator-CzrLGzC0.cjs.map +1 -0
  30. package/dist/{Route53Provider-Cvj40A8I.mjs → Route53Provider-Di_SD9CF.mjs} +3 -3
  31. package/dist/Route53Provider-Di_SD9CF.mjs.map +1 -0
  32. package/dist/{Route53Provider-DVILBsvV.cjs → Route53Provider-emLuQHVw.cjs} +3 -3
  33. package/dist/Route53Provider-emLuQHVw.cjs.map +1 -0
  34. package/dist/S3StateStore-BQaGVNRf.mjs +223 -0
  35. package/dist/S3StateStore-BQaGVNRf.mjs.map +1 -0
  36. package/dist/S3StateStore-Cjr4Rtsf.cjs +222 -0
  37. package/dist/S3StateStore-Cjr4Rtsf.cjs.map +1 -0
  38. package/dist/SSMStateStore-Bq_S7x5_.mjs +205 -0
  39. package/dist/SSMStateStore-Bq_S7x5_.mjs.map +1 -0
  40. package/dist/SSMStateStore-Cnfwdlme.cjs +204 -0
  41. package/dist/SSMStateStore-Cnfwdlme.cjs.map +1 -0
  42. package/dist/SubscriberGenerator-CfZWX0lT.mjs +783 -0
  43. package/dist/SubscriberGenerator-CfZWX0lT.mjs.map +1 -0
  44. package/dist/SubscriberGenerator-DMi4siph.cjs +848 -0
  45. package/dist/SubscriberGenerator-DMi4siph.cjs.map +1 -0
  46. package/dist/add-3_IHpF5F.cjs +713 -0
  47. package/dist/add-3_IHpF5F.cjs.map +1 -0
  48. package/dist/add-CNQFnG0C.mjs +711 -0
  49. package/dist/add-CNQFnG0C.mjs.map +1 -0
  50. package/dist/appPorts-BoXMwolc.mjs +249 -0
  51. package/dist/appPorts-BoXMwolc.mjs.map +1 -0
  52. package/dist/appPorts-IW-OZmRi.cjs +296 -0
  53. package/dist/appPorts-IW-OZmRi.cjs.map +1 -0
  54. package/dist/apps-BGu47YRF.cjs +6404 -0
  55. package/dist/apps-BGu47YRF.cjs.map +1 -0
  56. package/dist/apps-DGod3aS9.mjs +5765 -0
  57. package/dist/apps-DGod3aS9.mjs.map +1 -0
  58. package/dist/aws-C5LAU_Ii.mjs +97 -0
  59. package/dist/aws-C5LAU_Ii.mjs.map +1 -0
  60. package/dist/aws-DKC2m3sT.cjs +108 -0
  61. package/dist/aws-DKC2m3sT.cjs.map +1 -0
  62. package/dist/awsStore-Bx5nCFnS.mjs +121 -0
  63. package/dist/awsStore-Bx5nCFnS.mjs.map +1 -0
  64. package/dist/awsStore-u3ehhMoY.cjs +138 -0
  65. package/dist/awsStore-u3ehhMoY.cjs.map +1 -0
  66. package/dist/{backup-provisioner-DIVCbfee.mjs → backup-provisioner-C8DnCmxK.mjs} +2 -2
  67. package/dist/backup-provisioner-C8DnCmxK.mjs.map +1 -0
  68. package/dist/{backup-provisioner-BmhIO_Yr.cjs → backup-provisioner-oDEsPj02.cjs} +2 -2
  69. package/dist/backup-provisioner-oDEsPj02.cjs.map +1 -0
  70. package/dist/backups/runner.cjs +519 -0
  71. package/dist/backups/runner.cjs.map +1 -0
  72. package/dist/backups/runner.d.cts +102 -0
  73. package/dist/backups/runner.d.cts.map +1 -0
  74. package/dist/backups/runner.d.mts +102 -0
  75. package/dist/backups/runner.d.mts.map +1 -0
  76. package/dist/backups/runner.mjs +506 -0
  77. package/dist/backups/runner.mjs.map +1 -0
  78. package/dist/{bundler-mjqGAvu1.cjs → bundler-DWGxNGSB.cjs} +59 -14
  79. package/dist/bundler-DWGxNGSB.cjs.map +1 -0
  80. package/dist/{bundler-mwH7WOb1.mjs → bundler-Dm0mB7EK.mjs} +59 -14
  81. package/dist/bundler-Dm0mB7EK.mjs.map +1 -0
  82. package/dist/cli-CYeZF85I.cjs +80 -0
  83. package/dist/cli-CYeZF85I.cjs.map +1 -0
  84. package/dist/cli-Qm-8tG46.mjs +80 -0
  85. package/dist/cli-Qm-8tG46.mjs.map +1 -0
  86. package/dist/compose-BVeevJO_.mjs +3139 -0
  87. package/dist/compose-BVeevJO_.mjs.map +1 -0
  88. package/dist/compose-CXgwCuqv.mjs +1560 -0
  89. package/dist/compose-CXgwCuqv.mjs.map +1 -0
  90. package/dist/compose-CshnO-Th.cjs +1919 -0
  91. package/dist/compose-CshnO-Th.cjs.map +1 -0
  92. package/dist/compose-IsvqY6iX.cjs +3240 -0
  93. package/dist/compose-IsvqY6iX.cjs.map +1 -0
  94. package/dist/config-B8gSu59v.d.mts +291 -0
  95. package/dist/config-B8gSu59v.d.mts.map +1 -0
  96. package/dist/config-u5XdE1Cq.d.cts +291 -0
  97. package/dist/config-u5XdE1Cq.d.cts.map +1 -0
  98. package/dist/config.cjs +457 -9
  99. package/dist/config.cjs.map +1 -0
  100. package/dist/config.d.cts +4 -117
  101. package/dist/config.d.mts +4 -117
  102. package/dist/config.mjs +441 -3
  103. package/dist/config.mjs.map +1 -0
  104. package/dist/credentialSchemas-BzJiK1nQ.mjs +236 -0
  105. package/dist/credentialSchemas-BzJiK1nQ.mjs.map +1 -0
  106. package/dist/credentialSchemas-OVXofU-r.cjs +271 -0
  107. package/dist/credentialSchemas-OVXofU-r.cjs.map +1 -0
  108. package/dist/credentials-CKIeLL7T.mjs +1838 -0
  109. package/dist/credentials-CKIeLL7T.mjs.map +1 -0
  110. package/dist/credentials-DzR2j8h1.cjs +2293 -0
  111. package/dist/credentials-DzR2j8h1.cjs.map +1 -0
  112. package/dist/databases-CuTL1e7s.cjs +703 -0
  113. package/dist/databases-CuTL1e7s.cjs.map +1 -0
  114. package/dist/databases-zN-gEox0.mjs +588 -0
  115. package/dist/databases-zN-gEox0.mjs.map +1 -0
  116. package/dist/define-6poNqm5O.mjs +106 -0
  117. package/dist/define-6poNqm5O.mjs.map +1 -0
  118. package/dist/define-crmMcXFS.cjs +153 -0
  119. package/dist/define-crmMcXFS.cjs.map +1 -0
  120. package/dist/deploy/public.cjs +211 -0
  121. package/dist/deploy/public.cjs.map +1 -0
  122. package/dist/deploy/public.d.cts +658 -0
  123. package/dist/deploy/public.d.cts.map +1 -0
  124. package/dist/deploy/public.d.mts +658 -0
  125. package/dist/deploy/public.d.mts.map +1 -0
  126. package/dist/deploy/public.mjs +144 -0
  127. package/dist/deploy/public.mjs.map +1 -0
  128. package/dist/deploy/sniffer-envparser-worker.cjs +54 -0
  129. package/dist/deploy/sniffer-envparser-worker.cjs.map +1 -0
  130. package/dist/deploy/sniffer-envparser-worker.d.cts +1 -0
  131. package/dist/deploy/sniffer-envparser-worker.d.mts +1 -0
  132. package/dist/deploy/sniffer-envparser-worker.mjs +55 -0
  133. package/dist/deploy/sniffer-envparser-worker.mjs.map +1 -0
  134. package/dist/deploy/sniffer-hooks.cjs +1 -1
  135. package/dist/deploy/sniffer-hooks.mjs +1 -1
  136. package/dist/deploy/sniffer-loader.cjs +2 -2
  137. package/dist/deploy/sniffer-loader.mjs +1 -1
  138. package/dist/deploy/sniffer-routes-worker.cjs +2 -2
  139. package/dist/deploy/sniffer-routes-worker.mjs +1 -1
  140. package/dist/deploy-CjubyZlP.mjs +3848 -0
  141. package/dist/deploy-CjubyZlP.mjs.map +1 -0
  142. package/dist/deploy-DQjEjUfB.cjs +3904 -0
  143. package/dist/deploy-DQjEjUfB.cjs.map +1 -0
  144. package/dist/destroy-D1375m8C.cjs +789 -0
  145. package/dist/destroy-D1375m8C.cjs.map +1 -0
  146. package/dist/destroy-D4m5aO9k.mjs +788 -0
  147. package/dist/destroy-D4m5aO9k.mjs.map +1 -0
  148. package/dist/discover-39VKSE2i.cjs +1085 -0
  149. package/dist/discover-39VKSE2i.cjs.map +1 -0
  150. package/dist/discover-B_PDDaVj.mjs +940 -0
  151. package/dist/discover-B_PDDaVj.mjs.map +1 -0
  152. package/dist/docker-C27YUUMQ.mjs +1413 -0
  153. package/dist/docker-C27YUUMQ.mjs.map +1 -0
  154. package/dist/docker-CSEAKwFr.cjs +1520 -0
  155. package/dist/docker-CSEAKwFr.cjs.map +1 -0
  156. package/dist/dokploy-CSqDsvY-.mjs +38 -0
  157. package/dist/dokploy-CSqDsvY-.mjs.map +1 -0
  158. package/dist/dokploy-DJDdiFz6.cjs +38 -0
  159. package/dist/dokploy-DJDdiFz6.cjs.map +1 -0
  160. package/dist/drivers-BhdC9Efj.cjs +248 -0
  161. package/dist/drivers-BhdC9Efj.cjs.map +1 -0
  162. package/dist/drivers-wcDnzf7l.mjs +213 -0
  163. package/dist/drivers-wcDnzf7l.mjs.map +1 -0
  164. package/dist/eas-DC3F8cy0.mjs +334 -0
  165. package/dist/eas-DC3F8cy0.mjs.map +1 -0
  166. package/dist/eas-DryGYjFk.cjs +337 -0
  167. package/dist/eas-DryGYjFk.cjs.map +1 -0
  168. package/dist/emit-C4KSXOeS.mjs +153 -0
  169. package/dist/emit-C4KSXOeS.mjs.map +1 -0
  170. package/dist/emit-DiW0kbue.cjs +164 -0
  171. package/dist/emit-DiW0kbue.cjs.map +1 -0
  172. package/dist/encryption-8qZGm15p.cjs +90 -0
  173. package/dist/encryption-8qZGm15p.cjs.map +1 -0
  174. package/dist/encryption-C8Y8Ly6n.mjs +89 -0
  175. package/dist/encryption-C8Y8Ly6n.mjs.map +1 -0
  176. package/dist/engine-C9E0MeLm.mjs +3216 -0
  177. package/dist/engine-C9E0MeLm.mjs.map +1 -0
  178. package/dist/engine-DI7JAyiD.cjs +3329 -0
  179. package/dist/engine-DI7JAyiD.cjs.map +1 -0
  180. package/dist/errors-D8Gwp5kU.mjs +23 -0
  181. package/dist/errors-D8Gwp5kU.mjs.map +1 -0
  182. package/dist/errors-DMC4Umsb.cjs +34 -0
  183. package/dist/errors-DMC4Umsb.cjs.map +1 -0
  184. package/dist/github-DdaV-Gll.mjs +977 -0
  185. package/dist/github-DdaV-Gll.mjs.map +1 -0
  186. package/dist/github-g3nRZlli.cjs +978 -0
  187. package/dist/github-g3nRZlli.cjs.map +1 -0
  188. package/dist/googlePlay-BHJ_iThq.cjs +931 -0
  189. package/dist/googlePlay-BHJ_iThq.cjs.map +1 -0
  190. package/dist/googlePlay-BmeR1kY4.mjs +931 -0
  191. package/dist/googlePlay-BmeR1kY4.mjs.map +1 -0
  192. package/dist/iam-BoYPPNdM.cjs +521 -0
  193. package/dist/iam-BoYPPNdM.cjs.map +1 -0
  194. package/dist/iam-ra1_Y405.mjs +442 -0
  195. package/dist/iam-ra1_Y405.mjs.map +1 -0
  196. package/dist/{index-RCUizGxL.d.cts → index-1H93w_H6.d.cts} +38 -14
  197. package/dist/index-1H93w_H6.d.cts.map +1 -0
  198. package/dist/{index-B4H4XF7A.d.mts → index-DFZ0SMwN.d.mts} +38 -14
  199. package/dist/index-DFZ0SMwN.d.mts.map +1 -0
  200. package/dist/index.cjs +15142 -13470
  201. package/dist/index.cjs.map +1 -1
  202. package/dist/index.mjs +14959 -13285
  203. package/dist/index.mjs.map +1 -1
  204. package/dist/local-Bkv-e8uM.mjs +224 -0
  205. package/dist/local-Bkv-e8uM.mjs.map +1 -0
  206. package/dist/local-DTidpa-a.cjs +241 -0
  207. package/dist/local-DTidpa-a.cjs.map +1 -0
  208. package/dist/migrate-BZRsJwni.mjs +181 -0
  209. package/dist/migrate-BZRsJwni.mjs.map +1 -0
  210. package/dist/migrate-CXLhrHwu.cjs +272 -0
  211. package/dist/migrate-CXLhrHwu.cjs.map +1 -0
  212. package/dist/migrate-DNOI23QA.mjs +267 -0
  213. package/dist/migrate-DNOI23QA.mjs.map +1 -0
  214. package/dist/migrate-DU4MtKxz.cjs +181 -0
  215. package/dist/migrate-DU4MtKxz.cjs.map +1 -0
  216. package/dist/next.cjs +59 -0
  217. package/dist/next.cjs.map +1 -0
  218. package/dist/next.d.cts +44 -0
  219. package/dist/next.d.cts.map +1 -0
  220. package/dist/next.d.mts +44 -0
  221. package/dist/next.d.mts.map +1 -0
  222. package/dist/next.mjs +58 -0
  223. package/dist/next.mjs.map +1 -0
  224. package/dist/notes-1TM_Vzi7.mjs +408 -0
  225. package/dist/notes-1TM_Vzi7.mjs.map +1 -0
  226. package/dist/notes-BpaXOAkA.cjs +509 -0
  227. package/dist/notes-BpaXOAkA.cjs.map +1 -0
  228. package/dist/openapi.cjs +213 -7
  229. package/dist/openapi.cjs.map +1 -0
  230. package/dist/openapi.d.cts +32 -8
  231. package/dist/openapi.d.cts.map +1 -1
  232. package/dist/openapi.d.mts +32 -8
  233. package/dist/openapi.d.mts.map +1 -1
  234. package/dist/openapi.mjs +208 -2
  235. package/dist/openapi.mjs.map +1 -0
  236. package/dist/projectBucket-BRgsSv2P.mjs +222 -0
  237. package/dist/projectBucket-BRgsSv2P.mjs.map +1 -0
  238. package/dist/projectBucket-DbEWuLGX.cjs +263 -0
  239. package/dist/projectBucket-DbEWuLGX.cjs.map +1 -0
  240. package/dist/provider-BqpjG9QM.cjs +57 -0
  241. package/dist/provider-BqpjG9QM.cjs.map +1 -0
  242. package/dist/provider-CEOKk8NS.mjs +46 -0
  243. package/dist/provider-CEOKk8NS.mjs.map +1 -0
  244. package/dist/publish-BN1l3tPF.cjs +124 -0
  245. package/dist/publish-BN1l3tPF.cjs.map +1 -0
  246. package/dist/publish-DjFgxu2v.mjs +123 -0
  247. package/dist/publish-DjFgxu2v.mjs.map +1 -0
  248. package/dist/ready-COJHr1Yi.mjs +375 -0
  249. package/dist/ready-COJHr1Yi.mjs.map +1 -0
  250. package/dist/ready-DcD0SCnV.cjs +404 -0
  251. package/dist/ready-DcD0SCnV.cjs.map +1 -0
  252. package/dist/reconcile/public.cjs +3 -5
  253. package/dist/reconcile/public.d.cts +33 -89
  254. package/dist/reconcile/public.d.cts.map +1 -1
  255. package/dist/reconcile/public.d.mts +33 -89
  256. package/dist/reconcile/public.d.mts.map +1 -1
  257. package/dist/reconcile/public.mjs +3 -3
  258. package/dist/reconcile--I7V4Klj.mjs +34 -0
  259. package/dist/reconcile--I7V4Klj.mjs.map +1 -0
  260. package/dist/reconcile-CuCQBa5-.cjs +34 -0
  261. package/dist/reconcile-CuCQBa5-.cjs.map +1 -0
  262. package/dist/resolve-BHVyg4Hg.cjs +316 -0
  263. package/dist/resolve-BHVyg4Hg.cjs.map +1 -0
  264. package/dist/resolve-NEKsqNAw.mjs +263 -0
  265. package/dist/resolve-NEKsqNAw.mjs.map +1 -0
  266. package/dist/rollback-BVgyLE7B.mjs +136 -0
  267. package/dist/rollback-BVgyLE7B.mjs.map +1 -0
  268. package/dist/rollback-CUjvOIDE.cjs +165 -0
  269. package/dist/rollback-CUjvOIDE.cjs.map +1 -0
  270. package/dist/runtime-CKOkIrw0.d.cts +82 -0
  271. package/dist/runtime-CKOkIrw0.d.cts.map +1 -0
  272. package/dist/runtime-Cdvv8SfU.d.mts +82 -0
  273. package/dist/runtime-Cdvv8SfU.d.mts.map +1 -0
  274. package/dist/s3-BO4yr61G.mjs +240 -0
  275. package/dist/s3-BO4yr61G.mjs.map +1 -0
  276. package/dist/s3-DnPbDfQN.cjs +240 -0
  277. package/dist/s3-DnPbDfQN.cjs.map +1 -0
  278. package/dist/sandbox/config-worker.cjs +43 -0
  279. package/dist/sandbox/config-worker.cjs.map +1 -0
  280. package/dist/sandbox/config-worker.d.cts +1 -0
  281. package/dist/sandbox/config-worker.d.mts +1 -0
  282. package/dist/sandbox/config-worker.mjs +44 -0
  283. package/dist/sandbox/config-worker.mjs.map +1 -0
  284. package/dist/sandbox/credentials-worker.cjs +53 -0
  285. package/dist/sandbox/credentials-worker.cjs.map +1 -0
  286. package/dist/sandbox/credentials-worker.d.cts +1 -0
  287. package/dist/sandbox/credentials-worker.d.mts +1 -0
  288. package/dist/sandbox/credentials-worker.mjs +54 -0
  289. package/dist/sandbox/credentials-worker.mjs.map +1 -0
  290. package/dist/sandbox/discover-worker.cjs +47 -0
  291. package/dist/sandbox/discover-worker.cjs.map +1 -0
  292. package/dist/sandbox/discover-worker.d.cts +1 -0
  293. package/dist/sandbox/discover-worker.d.mts +1 -0
  294. package/dist/sandbox/discover-worker.mjs +48 -0
  295. package/dist/sandbox/discover-worker.mjs.map +1 -0
  296. package/dist/sandbox/migrate-worker.cjs +75 -0
  297. package/dist/sandbox/migrate-worker.cjs.map +1 -0
  298. package/dist/sandbox/migrate-worker.d.cts +1 -0
  299. package/dist/sandbox/migrate-worker.d.mts +1 -0
  300. package/dist/sandbox/migrate-worker.mjs +76 -0
  301. package/dist/sandbox/migrate-worker.mjs.map +1 -0
  302. package/dist/{workspace-B8NLb54N.cjs → schemas-BCwKKA42.mjs} +399 -1173
  303. package/dist/schemas-BCwKKA42.mjs.map +1 -0
  304. package/dist/{workspace-DI-M3BnN.mjs → schemas-BQ_v0lEX.cjs} +487 -982
  305. package/dist/schemas-BQ_v0lEX.cjs.map +1 -0
  306. package/dist/secretsManager-CJyxFcBH.mjs +113 -0
  307. package/dist/secretsManager-CJyxFcBH.mjs.map +1 -0
  308. package/dist/secretsManager-D8on44WI.cjs +124 -0
  309. package/dist/secretsManager-D8on44WI.cjs.map +1 -0
  310. package/dist/seeds-Bc3niNVb.cjs +382 -0
  311. package/dist/seeds-Bc3niNVb.cjs.map +1 -0
  312. package/dist/seeds-Ccn0Ru2T.mjs +299 -0
  313. package/dist/seeds-Ccn0Ru2T.mjs.map +1 -0
  314. package/dist/serverSetup-BxnCM11A.mjs +685 -0
  315. package/dist/serverSetup-BxnCM11A.mjs.map +1 -0
  316. package/dist/serverSetup-DScJ7tQs.cjs +685 -0
  317. package/dist/serverSetup-DScJ7tQs.cjs.map +1 -0
  318. package/dist/sniffer-9smKtb86.mjs +1824 -0
  319. package/dist/sniffer-9smKtb86.mjs.map +1 -0
  320. package/dist/sniffer-DHcxlSJF.cjs +1997 -0
  321. package/dist/sniffer-DHcxlSJF.cjs.map +1 -0
  322. package/dist/snsSubscriptions-B8TYeAM-.cjs +1184 -0
  323. package/dist/snsSubscriptions-B8TYeAM-.cjs.map +1 -0
  324. package/dist/snsSubscriptions-CygsiXhb.mjs +1053 -0
  325. package/dist/snsSubscriptions-CygsiXhb.mjs.map +1 -0
  326. package/dist/sst-Bgb3WWEl.mjs +478 -0
  327. package/dist/sst-Bgb3WWEl.mjs.map +1 -0
  328. package/dist/sst-DiHVSku5.cjs +501 -0
  329. package/dist/sst-DiHVSku5.cjs.map +1 -0
  330. package/dist/stack-A3evQgbk.cjs +2512 -0
  331. package/dist/stack-A3evQgbk.cjs.map +1 -0
  332. package/dist/stack-Cy2FwO3Z.mjs +2331 -0
  333. package/dist/stack-Cy2FwO3Z.mjs.map +1 -0
  334. package/dist/stage-Bm1x9Anp.cjs +313 -0
  335. package/dist/stage-Bm1x9Anp.cjs.map +1 -0
  336. package/dist/stage-Dgy08WVL.mjs +302 -0
  337. package/dist/stage-Dgy08WVL.mjs.map +1 -0
  338. package/dist/stages-BWg3NU3J.cjs +190 -0
  339. package/dist/stages-BWg3NU3J.cjs.map +1 -0
  340. package/dist/stages-COiipV8N.mjs +190 -0
  341. package/dist/stages-COiipV8N.mjs.map +1 -0
  342. package/dist/target/public.cjs +15 -0
  343. package/dist/target/public.d.cts +28 -0
  344. package/dist/target/public.d.cts.map +1 -0
  345. package/dist/target/public.d.mts +28 -0
  346. package/dist/target/public.d.mts.map +1 -0
  347. package/dist/target/public.mjs +4 -0
  348. package/dist/terminal-BDRxzEZD.cjs +85 -0
  349. package/dist/terminal-BDRxzEZD.cjs.map +1 -0
  350. package/dist/terminal-BRAIvH83.mjs +85 -0
  351. package/dist/terminal-BRAIvH83.mjs.map +1 -0
  352. package/dist/types-Bl_CwZC9.cjs +90 -0
  353. package/dist/types-Bl_CwZC9.cjs.map +1 -0
  354. package/dist/{types-7R81hu0i.d.mts → types-DEmuMHsS.d.cts} +2147 -428
  355. package/dist/types-DEmuMHsS.d.cts.map +1 -0
  356. package/dist/types-Y1NfWlyG.mjs +61 -0
  357. package/dist/types-Y1NfWlyG.mjs.map +1 -0
  358. package/dist/{types-N7c2O2m7.d.cts → types-g_S0_RAi.d.mts} +2145 -428
  359. package/dist/types-g_S0_RAi.d.mts.map +1 -0
  360. package/dist/utils-D2Nk1Nv2.cjs +205 -0
  361. package/dist/utils-D2Nk1Nv2.cjs.map +1 -0
  362. package/dist/utils-D_fxUqvU.mjs +156 -0
  363. package/dist/utils-D_fxUqvU.mjs.map +1 -0
  364. package/dist/vitest.cjs +65 -0
  365. package/dist/vitest.cjs.map +1 -0
  366. package/dist/vitest.d.cts +29 -0
  367. package/dist/vitest.d.cts.map +1 -0
  368. package/dist/vitest.d.mts +29 -0
  369. package/dist/vitest.d.mts.map +1 -0
  370. package/dist/vitest.mjs +65 -0
  371. package/dist/vitest.mjs.map +1 -0
  372. package/dist/workerRuntime-BXfhbe13.cjs +108 -0
  373. package/dist/workerRuntime-BXfhbe13.cjs.map +1 -0
  374. package/dist/workerRuntime-CsOyBRx2.mjs +79 -0
  375. package/dist/workerRuntime-CsOyBRx2.mjs.map +1 -0
  376. package/dist/workspace/index.cjs +6 -2
  377. package/dist/workspace/index.d.cts +3 -3
  378. package/dist/workspace/index.d.mts +3 -3
  379. package/dist/workspace/index.mjs +2 -2
  380. package/dist/workspace-CEpojAus.cjs +3528 -0
  381. package/dist/workspace-CEpojAus.cjs.map +1 -0
  382. package/dist/workspace-_aoe8v6u.mjs +2990 -0
  383. package/dist/workspace-_aoe8v6u.mjs.map +1 -0
  384. package/package.json +75 -13
  385. package/dist/HostingerProvider-BY26bWwB.mjs.map +0 -1
  386. package/dist/HostingerProvider-BZFGYYVA.cjs.map +0 -1
  387. package/dist/LocalStateProvider-7HR6SS2t.cjs +0 -48
  388. package/dist/LocalStateProvider-7HR6SS2t.cjs.map +0 -1
  389. package/dist/LocalStateProvider-D7QyJoLM.mjs +0 -48
  390. package/dist/LocalStateProvider-D7QyJoLM.mjs.map +0 -1
  391. package/dist/Route53Provider-Cvj40A8I.mjs.map +0 -1
  392. package/dist/Route53Provider-DVILBsvV.cjs.map +0 -1
  393. package/dist/SSMStateProvider-B0Hu1MKZ.mjs +0 -75
  394. package/dist/SSMStateProvider-B0Hu1MKZ.mjs.map +0 -1
  395. package/dist/SSMStateProvider-VrQ-yeqd.cjs +0 -74
  396. package/dist/SSMStateProvider-VrQ-yeqd.cjs.map +0 -1
  397. package/dist/backup-provisioner-BmhIO_Yr.cjs.map +0 -1
  398. package/dist/backup-provisioner-DIVCbfee.mjs.map +0 -1
  399. package/dist/bundler-mjqGAvu1.cjs.map +0 -1
  400. package/dist/bundler-mwH7WOb1.mjs.map +0 -1
  401. package/dist/config-CdTMeMU_.cjs +0 -467
  402. package/dist/config-CdTMeMU_.cjs.map +0 -1
  403. package/dist/config-DPnPkWyH.mjs +0 -414
  404. package/dist/config-DPnPkWyH.mjs.map +0 -1
  405. package/dist/config.d.cts.map +0 -1
  406. package/dist/config.d.mts.map +0 -1
  407. package/dist/credentials-fJP5-fa1.mjs +0 -2780
  408. package/dist/credentials-fJP5-fa1.mjs.map +0 -1
  409. package/dist/credentials-tvyReUAd.cjs +0 -2917
  410. package/dist/credentials-tvyReUAd.cjs.map +0 -1
  411. package/dist/discover-BERGFg8v.cjs +0 -288
  412. package/dist/discover-BERGFg8v.cjs.map +0 -1
  413. package/dist/discover-CK-n3w6b.mjs +0 -244
  414. package/dist/discover-CK-n3w6b.mjs.map +0 -1
  415. package/dist/emit-BdoPFjZf.cjs +0 -253
  416. package/dist/emit-BdoPFjZf.cjs.map +0 -1
  417. package/dist/emit-Bzq7JsMP.mjs +0 -224
  418. package/dist/emit-Bzq7JsMP.mjs.map +0 -1
  419. package/dist/generator-LfZU7NlU.mjs +0 -247
  420. package/dist/generator-LfZU7NlU.mjs.map +0 -1
  421. package/dist/generator-Wdfp0jCS.cjs +0 -282
  422. package/dist/generator-Wdfp0jCS.cjs.map +0 -1
  423. package/dist/github-CAfKyYPN.mjs +0 -216
  424. package/dist/github-CAfKyYPN.mjs.map +0 -1
  425. package/dist/github-DVE8Gg_F.cjs +0 -216
  426. package/dist/github-DVE8Gg_F.cjs.map +0 -1
  427. package/dist/index-B4H4XF7A.d.mts.map +0 -1
  428. package/dist/index-RCUizGxL.d.cts.map +0 -1
  429. package/dist/openapi-BeckoaP9.cjs +0 -2038
  430. package/dist/openapi-BeckoaP9.cjs.map +0 -1
  431. package/dist/openapi-DolhBm6r.mjs +0 -1991
  432. package/dist/openapi-DolhBm6r.mjs.map +0 -1
  433. package/dist/reconcile-Cq4cO83R.cjs +0 -136
  434. package/dist/reconcile-Cq4cO83R.cjs.map +0 -1
  435. package/dist/reconcile-fmoluZmZ.mjs +0 -113
  436. package/dist/reconcile-fmoluZmZ.mjs.map +0 -1
  437. package/dist/ssm-BKN1Cg4z.mjs +0 -60
  438. package/dist/ssm-BKN1Cg4z.mjs.map +0 -1
  439. package/dist/ssm-FxeSAt35.cjs +0 -60
  440. package/dist/ssm-FxeSAt35.cjs.map +0 -1
  441. package/dist/storage-DgypfSD6.cjs +0 -351
  442. package/dist/storage-DgypfSD6.cjs.map +0 -1
  443. package/dist/storage-TP0x118M.mjs +0 -304
  444. package/dist/storage-TP0x118M.mjs.map +0 -1
  445. package/dist/transfer-4A4S2hcw.mjs +0 -122
  446. package/dist/transfer-4A4S2hcw.mjs.map +0 -1
  447. package/dist/transfer-DdmtKLzi.cjs +0 -151
  448. package/dist/transfer-DdmtKLzi.cjs.map +0 -1
  449. package/dist/types-7R81hu0i.d.mts.map +0 -1
  450. package/dist/types-N7c2O2m7.d.cts.map +0 -1
  451. package/dist/workspace-B8NLb54N.cjs.map +0 -1
  452. package/dist/workspace-DI-M3BnN.mjs.map +0 -1
@@ -0,0 +1,2512 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
2
+ const require_errors = require("./errors-DMC4Umsb.cjs");
3
+ const require_credentials = require("./credentials-DzR2j8h1.cjs");
4
+ const require_workspace = require("./workspace-CEpojAus.cjs");
5
+ const require_apps = require("./apps-BGu47YRF.cjs");
6
+ const require_compose = require("./compose-CshnO-Th.cjs");
7
+ const require_SubscriberGenerator = require("./SubscriberGenerator-DMi4siph.cjs");
8
+ const require_types = require("./types-Bl_CwZC9.cjs");
9
+ const require_notes = require("./notes-BpaXOAkA.cjs");
10
+ const require_docker = require("./docker-CSEAKwFr.cjs");
11
+ let node_path = require("node:path");
12
+ let node_crypto = require("node:crypto");
13
+ let _geekmidas_manifest = require("@geekmidas/manifest");
14
+ let yaml = require("yaml");
15
+ let bcryptjs = require("bcryptjs");
16
+ bcryptjs = require_rolldown_runtime.__toESM(bcryptjs, 1);
17
+ //#region src/compose/routes.ts
18
+ /**
19
+ * Every host a route answers on — its own, its aliases and its redirects —
20
+ * in that order: what DNS, certificates and the edge's claims cover.
21
+ */
22
+ function routeHosts(route) {
23
+ return [
24
+ route.host,
25
+ ...route.aliases ?? [],
26
+ ...route.redirects?.hosts ?? []
27
+ ];
28
+ }
29
+ /** A route with handlers and a check that would have to hold for each of them. */
30
+ var EdgeRouteConflict = class extends Error {
31
+ route;
32
+ constructor(route) {
33
+ super(`The edge route '${route}' sends some paths to other upstreams and also restricts who or what it answers. The two are not combined: give the restricted paths a host of their own.`);
34
+ this.route = route;
35
+ this.name = "EdgeRouteConflict";
36
+ }
37
+ };
38
+ /** @throws {EdgeRouteConflict} */
39
+ function assertRouteRenderable(route) {
40
+ if (route.handlers?.length && (route.allow || route.paths || route.prefixes || route.requireHeader)) throw new EdgeRouteConflict(route.name);
41
+ }
42
+ /** File descriptors a process holding sockets may open. */
43
+ const NOFILE = {
44
+ soft: 1048576,
45
+ hard: 1048576
46
+ };
47
+ /**
48
+ * What the edge runs with: a descriptor per socket, twice — the client's and
49
+ * the upstream's — and every local port for those upstream connections. One
50
+ * edge address to one upstream has only the ephemeral range to open
51
+ * connections from, ~28k by Linux's default; widened, ~64k per replica.
52
+ */
53
+ const EDGE_LIMITS = {
54
+ sysctls: { "net.ipv4.ip_local_port_range": "1024 65535" },
55
+ ulimits: { nofile: NOFILE }
56
+ };
57
+ //#endregion
58
+ //#region src/compose/caddyfile.ts
59
+ /**
60
+ * The stack's own edge, rendered for Caddy: one site block per route.
61
+ *
62
+ * Deployed, each host is the stage's real domain and Caddy gets it a
63
+ * certificate from Let's Encrypt on first request — the same automatic HTTPS
64
+ * it does anywhere, with nothing to configure but the name — or serves the
65
+ * stage's own certificate (`deploy.compose.tls`). Locally the hosts are
66
+ * `*.localhost` and the certificate is the one gkm's local authority issued,
67
+ * as the `gkm dev` edge's is, so a local stack is `https://` like a deployed
68
+ * one.
69
+ *
70
+ * Pure: the routes are data (`routes.ts`), and rendering them is one string.
71
+ */
72
+ /** Where Caddy reads a stage's own certificate, inside its container. */
73
+ const CADDY_TLS_DIR = "/etc/caddy/tls";
74
+ /** An upstream on the stack's own network: its service name. */
75
+ function address({ service, port }) {
76
+ return `${service}:${port}`;
77
+ }
78
+ /** The Caddyfile for a stack's edge. */
79
+ function edgeCaddyfile(routes, options) {
80
+ const { tls } = options;
81
+ const ask = routes.find((route) => route.wildcard?.tls.kind === "on-demand")?.wildcard?.tls;
82
+ const onDemand = ask?.kind === "on-demand" ? `
83
+ on_demand_tls {
84
+ ask ${ask.ask}
85
+ }` : "";
86
+ const settings = `${options.email ? `\n\temail ${options.email}` : ""}${options.redirects === false ? "\n auto_https disable_redirects" : ""}${onDemand}`;
87
+ const global = settings ? `{${settings}\n}` : "";
88
+ const certificate = tls.kind === "files" ? `
89
+ tls ${tls.certFile} ${tls.keyFile}
90
+ ` : "";
91
+ const blocks = [...routes.filter((route) => !route.wildcard), ...routes.filter((route) => route.wildcard)].map((route) => siteBlock(route, options.edgeToken, route.wildcard?.tls.kind === "on-demand" ? `
92
+ tls {
93
+ on_demand
94
+ }
95
+ ` : certificate));
96
+ return `${HEADER}${global ? `${global}\n\n` : ""}${blocks.join("\n\n")}\n`;
97
+ }
98
+ /** One route's site block. */
99
+ function siteBlock(route, edgeToken, certificate) {
100
+ assertRouteRenderable(route);
101
+ const { host, allow, auth, paths, prefixes, requireHeader, handlers } = route;
102
+ const allowed = [...paths ?? [], ...(prefixes ?? []).map((prefix) => `${prefix}*`)];
103
+ const except = route.wildcard?.except ?? [];
104
+ const checks = `${except.length ? `
105
+ # Labels no tenant may take, although nothing in this stack answers them.
106
+ @protected host ${except.map((label) => `${label}.${route.wildcard?.domain}`).join(" ")}
107
+ respond @protected 404
108
+ ` : ""}${allow ? `
109
+ # Only these addresses — the peer Caddy sees, never a header a client
110
+ # could set. Everything else is refused before it reaches the upstream.
111
+ @denied not remote_ip ${allow.join(" ")}
112
+ respond @denied 403
113
+ ` : ""}${requireHeader ? `
114
+ # Only what the CDN sends: it adds this header to every request, and this
115
+ # host would be reached around the CDN otherwise.
116
+ @forged not header ${requireHeader.name} "${requireHeader.value}"
117
+ respond @forged 403
118
+ ` : ""}${auth ? `
119
+ # The stage's login, asked for before anything reaches the upstream.
120
+ basic_auth {
121
+ ${auth.user} ${auth.hash}
122
+ }
123
+ ` : ""}${allowed.length ? `
124
+ # Only these paths answer. Everything else on this host is refused before
125
+ # it reaches the upstream.
126
+ @elsewhere not path ${allowed.join(" ")}
127
+ respond @elsewhere 404
128
+ ` : ""}`;
129
+ const proxy = proxyBlock(route);
130
+ const body = handlers?.length ? `${handlers.map((handler, index) => `
131
+ # Answered by another service: ${handler.name}.
132
+ @handler${index} path ${handler.prefixes.map((prefix) => `${prefix}*`).join(" ")}
133
+ handle @handler${index} {
134
+ reverse_proxy ${handler.upstreams.map(address).join(" ")}
135
+ }
136
+ `).join("")}
137
+ handle {${proxy.replace(/\n/g, "\n ")}
138
+ }` : proxy;
139
+ const names = [host, ...route.aliases ?? []].map((name) => `https://${name}`).join(", ");
140
+ const redirects = (route.redirects?.hosts ?? []).map((from) => `
141
+
142
+ https://${from} {${certificate}
143
+ redir ${route.redirects?.to}{uri} permanent
144
+ }`).join("");
145
+ return `${names} {${certificate}${require_apps.clientIpRule(edgeToken)}
146
+ ${checks}${body}
147
+ }${redirects}`;
148
+ }
149
+ /** Where a route's requests go, when no handler took them. */
150
+ function proxyBlock(route) {
151
+ const { upstreams, prefix, streaming } = route;
152
+ const health = healthCheck(route);
153
+ return prefix ? `
154
+ # A bucket, served at a host of its own: the bucket is a prefix on MinIO,
155
+ # which routes and signs on the Host header — so it is sent the upstream's.
156
+ reverse_proxy ${upstreams.map(address).join(" ")} {
157
+ rewrite ${prefix}{uri}
158
+ header_up Host {upstream_hostport}${health}
159
+ }` : `
160
+ # Host and X-Forwarded-* are passed through as Caddy does by default, so
161
+ # an app builds redirects, cookies and links on the address a caller used.
162
+ reverse_proxy ${upstreams.map(address).join(" ")}${streaming || health ? ` {${streaming ? `
163
+ # Never buffer: a streamed response — server-sent events, a Next.js
164
+ # RSC payload — reaches the client as each chunk is written.
165
+ flush_interval -1` : ""}${health}
166
+ }` : ""}`;
167
+ }
168
+ /**
169
+ * Caddy's own check of each upstream, as the Traefik edge's
170
+ * `loadBalancer.healthCheck`: one that stops answering is taken out of
171
+ * rotation until it does again. Caddy starts once its apps have — not once
172
+ * they are healthy — so this is what keeps a request from an upstream that
173
+ * is not up, and a route to an app with none up answers an error (503)
174
+ * rather than going missing.
175
+ */
176
+ function healthCheck({ health }) {
177
+ return health ? `
178
+ # Each upstream asked on its own: one that stops answering is out of
179
+ # rotation until it answers again.
180
+ health_uri ${health}
181
+ health_interval 5s
182
+ health_timeout 3s` : "";
183
+ }
184
+ const HEADER = `# Generated by gkm compose from the construct manifest — do not edit.
185
+ #
186
+ # One host per API and site, each in front of its own container, one per
187
+ # file server in front of the stack's MinIO — its processors' paths sent to
188
+ # their own service — one per worker SNS pushes to and per processor unit a
189
+ # CDN reaches, answering only those paths, and — when its logs are served
190
+ # publicly — one for OpenObserve, to the addresses it allows. A site the
191
+ # stage puts behind a password asks for its login first.
192
+ `;
193
+ //#endregion
194
+ //#region src/compose/images.ts
195
+ /**
196
+ * Which image each app runs — and, for a tag, whether every one exists.
197
+ *
198
+ * A tag is a release's identity: `--tag=v1.4.0` means the images CI pushed as
199
+ * v1.4.0, and nothing else. So a stack is never half rolled out: every app's
200
+ * image is asked of the registry before anything is pulled or the running
201
+ * stack is touched, and one missing image stops the whole run naming every
202
+ * one that is missing. Nor is a missing image quietly built instead — a build
203
+ * of whatever is checked out here is not the release the tag names.
204
+ */
205
+ /**
206
+ * The tag a site's image carries for a release.
207
+ *
208
+ * A site's public URLs are inlined when it is built, so one bundle serves one
209
+ * stage: `v1.4.0-production` and `v1.4.0-staging` are two images of the same
210
+ * commit. A backend reads its URLs at runtime, so one image serves every stage
211
+ * and its tag is the release's alone.
212
+ */
213
+ function siteTag(tag, stage) {
214
+ return `${tag}-${stage}`;
215
+ }
216
+ /** Images a tag names that the registry does not have. */
217
+ var ImageTagNotFound = class extends require_errors.GkmError {
218
+ tag;
219
+ refs;
220
+ constructor(tag, refs) {
221
+ super(`The registry has no image for ${refs.length === 1 ? "this app" : `${refs.length} apps`} at '${tag}':\n` + refs.map((ref) => ` - ${ref}`).join("\n") + `\nNothing was pulled or started. Push '${tag}' for every app from CI, pick a tag that exists, or run without --tag to build from this checkout.`);
222
+ this.tag = tag;
223
+ this.refs = refs;
224
+ this.name = "ImageTagNotFound";
225
+ }
226
+ };
227
+ /** The registry did not answer, or did not let this machine in. */
228
+ var RegistryUnreachable = class extends require_errors.GkmError {
229
+ ref;
230
+ detail;
231
+ constructor(ref, detail) {
232
+ super(`Could not ask the registry about ${ref}: ${detail || "no answer"}\nNothing was pulled or started. Check the registry is reachable and that this machine is logged in to it (\`docker login <registry>\`).`);
233
+ this.ref = ref;
234
+ this.detail = detail;
235
+ this.name = "RegistryUnreachable";
236
+ }
237
+ };
238
+ /**
239
+ * Assert every image exists, before anything else happens.
240
+ *
241
+ * Asked all at once and reported all at once: a release missing two images is
242
+ * one problem with two names, and finding the second only after fixing the
243
+ * first is a slower way to learn the same thing.
244
+ *
245
+ * @throws {RegistryUnreachable} when the registry cannot say
246
+ * @throws {ImageTagNotFound} listing every missing image
247
+ */
248
+ async function assertImagesExist(docker, tag, images) {
249
+ const lookups = await Promise.all(images.map((image) => docker.lookup(image.ref)));
250
+ const unreachable = lookups.find((lookup) => lookup.status === "unreachable");
251
+ if (unreachable?.status === "unreachable") throw new RegistryUnreachable(unreachable.ref, unreachable.detail);
252
+ const missing = lookups.filter((lookup) => lookup.status === "missing").map((lookup) => lookup.ref);
253
+ if (missing.length > 0) throw new ImageTagNotFound(tag, missing);
254
+ }
255
+ /**
256
+ * A push or a pull with no `deploy.registry` to push to or pull from.
257
+ *
258
+ * Without one an image is named `<namespace>/<project>-<app>:<tag>`, which
259
+ * Docker resolves to Docker Hub — so a release would be pushed to, or pulled
260
+ * from, somebody else's account. It is never a fallback.
261
+ */
262
+ var RegistryRequired = class extends require_errors.GkmError {
263
+ operation;
264
+ ref;
265
+ constructor(operation, ref) {
266
+ super(`${operation === "push" ? "Pushing" : "Pulling"} images needs a registry, and gkm.config.ts sets no deploy.registry: '${ref}' would be ${operation === "push" ? "pushed to" : "pulled from"} Docker Hub. Set deploy.registry (e.g. registry: 'ghcr.io/acme') in gkm.config.ts.` + (operation === "pull" ? " To run images built here instead, pass --build." : ""));
267
+ this.operation = operation;
268
+ this.ref = ref;
269
+ this.name = "RegistryRequired";
270
+ }
271
+ };
272
+ /** An image pinned to its digest: `<ref>@sha256:…`. */
273
+ function pinnedRef(ref, digest) {
274
+ return `${ref.split("@")[0]}@${digest}`;
275
+ }
276
+ /** A digests file with no entry for an app the stack runs. */
277
+ var ImageDigestMissing = class extends require_errors.GkmError {
278
+ file;
279
+ apps;
280
+ constructor(file, apps) {
281
+ super(`${file} pins no digest for ${apps.join(", ")}. Use the file the same release's \`gkm compose --build --push --digests-file\` wrote, or run without --digests-file to pull by tag.`);
282
+ this.file = file;
283
+ this.apps = apps;
284
+ this.name = "ImageDigestMissing";
285
+ }
286
+ };
287
+ /** A digests file entry that is not this app's image. */
288
+ var ImageDigestMismatch = class extends require_errors.GkmError {
289
+ app;
290
+ expected;
291
+ found;
292
+ constructor(app, expected, found) {
293
+ super(`The digests file pins '${app}' to ${found}, but this release runs ${expected}. It was written for another registry, project, stage or tag; use the file this stage's push of this tag wrote.`);
294
+ this.app = app;
295
+ this.expected = expected;
296
+ this.found = found;
297
+ this.name = "ImageDigestMismatch";
298
+ }
299
+ };
300
+ /** A digests file that is not a JSON object of app to pinned ref. */
301
+ var ImageDigestsInvalid = class extends require_errors.GkmError {
302
+ file;
303
+ detail;
304
+ constructor(file, detail) {
305
+ super(`${file} is not a digests file (${detail}). It should be the JSON object \`gkm compose --build --push --digests-file\` writes: { "api": "<registry>/<image>:<tag>@sha256:…" }.`);
306
+ this.file = file;
307
+ this.detail = detail;
308
+ this.name = "ImageDigestsInvalid";
309
+ }
310
+ };
311
+ /** Parse a digests file's content, checking its shape. */
312
+ function parseDigests(file, content) {
313
+ let parsed;
314
+ try {
315
+ parsed = JSON.parse(content);
316
+ } catch (error) {
317
+ throw new ImageDigestsInvalid(file, error instanceof Error ? error.message : String(error));
318
+ }
319
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new ImageDigestsInvalid(file, "not a JSON object");
320
+ for (const [app, value] of Object.entries(parsed)) if (typeof value !== "string" || !/@sha256:[0-9a-f]{64}$/.test(value)) throw new ImageDigestsInvalid(file, `'${app}' is not an <image>:<tag>@sha256:… ref`);
321
+ return parsed;
322
+ }
323
+ /**
324
+ * Each image pinned to the digest the file names for it.
325
+ *
326
+ * @throws {ImageDigestMissing} naming every app the file has no entry for
327
+ * @throws {ImageDigestMismatch} when an entry is another image or tag
328
+ */
329
+ function pinImages(file, digests, images) {
330
+ const missing = images.filter((image) => !digests[image.app]).map((image) => image.app);
331
+ if (missing.length > 0) throw new ImageDigestMissing(file, missing);
332
+ return images.map((image) => {
333
+ const pinned = digests[image.app];
334
+ if (pinned.split("@")[0] !== image.ref) throw new ImageDigestMismatch(image.app, image.ref, pinned);
335
+ return {
336
+ ...image,
337
+ ref: pinned
338
+ };
339
+ });
340
+ }
341
+ //#endregion
342
+ //#region src/compose/sitePassword.ts
343
+ /**
344
+ * A site served behind a password on some deployed stages — a `StaticSite`'s
345
+ * `password`, naming a `RandomPassword` — so a staging build is not public
346
+ * while it is being tried.
347
+ *
348
+ * The edge asks for it with HTTP basic auth, before a request reaches the
349
+ * site: the browser prompts, and nothing of the site loads until the stage's
350
+ * login is given. The user is the stage's name; the password is the
351
+ * `RandomPassword`'s value on the stage, generated and kept like any other.
352
+ * Only its bcrypt hash reaches the edge's config.
353
+ *
354
+ * Pure.
355
+ */
356
+ /** A site's `password` names a `RandomPassword` the manifest does not hold. */
357
+ var SitePasswordNotDeclared = class extends require_errors.GkmError {
358
+ site;
359
+ secret;
360
+ constructor(site, secret) {
361
+ super(`'${site}' is served behind the password '${secret}', and no RandomPassword '${secret}' was found. Export it from a constructs file, as any construct is: export const ${secret[0].toLowerCase()}${secret.slice(1)} = new RandomPassword('${secret}');`);
362
+ this.site = site;
363
+ this.secret = secret;
364
+ this.name = "SitePasswordNotDeclared";
365
+ }
366
+ };
367
+ /** A site's `password` names a stage the workspace does not deploy. */
368
+ var UnknownPasswordStage = class extends require_errors.GkmError {
369
+ site;
370
+ stage;
371
+ deployed;
372
+ constructor(site, stage, deployed) {
373
+ super(`'${site}' is served behind a password on '${stage}', which is not one of the workspace's deployed stages (${deployed.map((s) => `'${s}'`).join(", ")}). Name one of them in its password's stages.`);
374
+ this.site = site;
375
+ this.stage = stage;
376
+ this.deployed = deployed;
377
+ this.name = "UnknownPasswordStage";
378
+ }
379
+ };
380
+ /** A site behind a password, with none in the stage's secrets. */
381
+ var SitePasswordMissing = class extends require_errors.GkmError {
382
+ stage;
383
+ key;
384
+ constructor(stage, key) {
385
+ super(`A site of '${stage}' is served behind a password, and the stage has no ${key} in its secrets. Run gkm compose --stage ${stage} once to generate it, or set one: gkm secrets:set ${key} '…' --stage ${stage}`);
386
+ this.stage = stage;
387
+ this.key = key;
388
+ this.name = "SitePasswordMissing";
389
+ }
390
+ };
391
+ /**
392
+ * A site behind a password on a stage it deploys through a target that cannot
393
+ * ask for a login. Refused rather than ignored: ignored, the site would be
394
+ * public while its construct says it is not.
395
+ */
396
+ var SitePasswordNeedsCompose = class extends require_errors.GkmError {
397
+ site;
398
+ stage;
399
+ target;
400
+ constructor(site, stage, target) {
401
+ super(`'${site}' is served behind a password on '${stage}', and it deploys through '${target}', which cannot ask for one yet — only compose does. Remove ${stage} from its password's stages, or deploy it with compose.`);
402
+ this.site = site;
403
+ this.stage = stage;
404
+ this.target = target;
405
+ this.name = "SitePasswordNeedsCompose";
406
+ }
407
+ };
408
+ /**
409
+ * The `RandomPassword` a site is served behind on `stage`, by its key —
410
+ * `SITE_PASSWORD` — or `undefined` where the stage asks for none.
411
+ *
412
+ * @throws {SitePasswordNotDeclared} where the password is not in the manifest
413
+ */
414
+ function sitePasswordKey(manifest, site, stage) {
415
+ const password = site.password;
416
+ if (!password?.stages.includes(stage)) return void 0;
417
+ const secret = manifest[password.secret];
418
+ const key = secret?.kind === "secret" ? secret.provides?.[0] : void 0;
419
+ if (!key) throw new SitePasswordNotDeclared(site.id, password.secret);
420
+ return key;
421
+ }
422
+ /**
423
+ * Before anything is deployed: every site behind a password names a deployed
424
+ * stage and a declared `RandomPassword`, and one of `apps` behind it on
425
+ * `stage` deploys through compose.
426
+ *
427
+ * @throws {UnknownPasswordStage}, {SitePasswordNotDeclared},
428
+ * {SitePasswordNeedsCompose}
429
+ */
430
+ function assertSitePasswords(workspace, manifest, stage, apps, target) {
431
+ for (const site of Object.values(manifest)) {
432
+ if (site.kind !== "site" || !site.password) continue;
433
+ for (const named of site.password.stages) if (!workspace.stages.deployed.includes(named)) throw new UnknownPasswordStage(site.id, named, workspace.stages.deployed);
434
+ if (sitePasswordKey(manifest, site, stage) && target !== "compose" && apps.includes(require_workspace.appKey(site.id))) throw new SitePasswordNeedsCompose(site.id, stage, target);
435
+ }
436
+ }
437
+ /**
438
+ * The login a site is served behind on `stage`, from the password kept under
439
+ * `key`.
440
+ *
441
+ * The hash's salt is derived from the password, so the same password always
442
+ * renders the same edge config: a deploy that changed nothing rewrites
443
+ * nothing, and the proxy is not reloaded for it. A per-hash random salt
444
+ * guards against a precomputed table of common passwords; a generated one is
445
+ * 43 random characters, which no table holds.
446
+ *
447
+ * @throws {SitePasswordMissing} where the stage's secrets hold none
448
+ */
449
+ function siteAuth(stage, key, custom) {
450
+ const password = custom[key];
451
+ if (!password) throw new SitePasswordMissing(stage, key);
452
+ return {
453
+ user: stage,
454
+ password,
455
+ hash: bcryptjs.default.hashSync(password, saltFor(password)),
456
+ key
457
+ };
458
+ }
459
+ /** bcrypt's own base-64 alphabet, in which a salt is written. */
460
+ const BCRYPT_ALPHABET = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
461
+ /**
462
+ * A bcrypt salt — `$2a$`, which Caddy and Traefik both read, at cost 10 —
463
+ * derived from the password.
464
+ */
465
+ function saltFor(password) {
466
+ const digest = (0, node_crypto.createHash)("sha256").update(password).digest();
467
+ let salt = "";
468
+ for (let i = 0; i < 22; i++) salt += BCRYPT_ALPHABET[digest[i] % 64];
469
+ return `$2a$10$${salt}`;
470
+ }
471
+ //#endregion
472
+ //#region src/compose/traefik.ts
473
+ /**
474
+ * The server's shared edge, rendered for Traefik: what the edge itself runs
475
+ * with, and what one stack registers with it.
476
+ *
477
+ * One Traefik per server owns 80 and 443, the ACME state and the redirect to
478
+ * HTTPS. It is configured through its file provider alone: each stack writes
479
+ * one file — its routers, services and middlewares, every name prefixed with
480
+ * its compose project — into a directory the edge watches, and removes it
481
+ * when it stops. There is no Docker socket: the edge never learns what runs
482
+ * on the server except from those files.
483
+ *
484
+ * The edge and the stacks meet on one external Docker network. Only a
485
+ * stack's public services join it, each under an alias prefixed with its
486
+ * project (`<project>-api`), because the network is shared: a bare service
487
+ * name there would be answered by every stack's `api`.
488
+ *
489
+ * Pure but for the edge's name, read from the environment once (see
490
+ * {@link EDGE_PROJECT_ENV}): the documents are data, and the edge's side
491
+ * effects are `edge.ts`'s.
492
+ */
493
+ /**
494
+ * The image, pinned: the edge is every stack's way in, so a new version is a
495
+ * change to this line, not whatever `latest` is on the day a server starts.
496
+ */
497
+ const TRAEFIK_IMAGE = "traefik:v3.7.13";
498
+ /** The edge's compose project: `GKM_EDGE_PROJECT`, else `gkm-edge`. */
499
+ function edgeProject(env = process.env) {
500
+ return env["GKM_EDGE_PROJECT"] || "gkm-edge";
501
+ }
502
+ /**
503
+ * The edge's compose project, one per server — read once, when gkm starts,
504
+ * so every step of a run names the same edge.
505
+ */
506
+ const EDGE_PROJECT = edgeProject();
507
+ /**
508
+ * The external network the edge and every stack's public services share:
509
+ * named after the edge, so a renamed edge has a network of its own.
510
+ */
511
+ const EDGE_NETWORK = EDGE_PROJECT;
512
+ /** The edge's compose service. */
513
+ const EDGE_SERVICE = "traefik";
514
+ /** Inside the edge's container: what it watches, and where certificates are. */
515
+ const EDGE_DYNAMIC_DIR = "/etc/gkm-edge/dynamic";
516
+ const EDGE_CERTS_DIR = "/etc/gkm-edge/certs";
517
+ /** The certificate resolver every deployed route without its own certificate uses. */
518
+ const ACME_RESOLVER = "letsencrypt";
519
+ /**
520
+ * The resolver a wildcard site's `*.<domain>` certificate comes from: Let's
521
+ * Encrypt issues a wildcard only over the DNS challenge, which the edge
522
+ * answers by writing an `_acme-challenge` TXT record through Route 53.
523
+ */
524
+ const ACME_DNS_RESOLVER = "letsencrypt-dns";
525
+ /**
526
+ * The key the edge writes those records with, inside its container: written
527
+ * by the deploy of a stage with a wildcard site, and allowed nothing but
528
+ * each such stage's `_acme-challenge` record (see `acmeDns.ts`).
529
+ */
530
+ const EDGE_AWS_CREDENTIALS = `${EDGE_CERTS_DIR}/aws-credentials`;
531
+ /** The internal entrypoint the edge's health check asks; never published. */
532
+ const PING_PORT = 8082;
533
+ /** A stack's service, as the edge — and the stack itself — reach it. */
534
+ function edgeAlias(project, service) {
535
+ return `${project}-${service}`;
536
+ }
537
+ /** A stack's certificate, as the edge's container reads it. */
538
+ function edgeCertificatePaths(project) {
539
+ return {
540
+ certFile: `${EDGE_CERTS_DIR}/${project}.crt`,
541
+ keyFile: `${EDGE_CERTS_DIR}/${project}.key`
542
+ };
543
+ }
544
+ /**
545
+ * The edge's static configuration: the entrypoints, the redirect, ACME, and
546
+ * the directory it watches. No API and no dashboard — nothing about the edge
547
+ * is reachable but the routes stacks register.
548
+ */
549
+ function traefikStatic(ports) {
550
+ return {
551
+ global: {
552
+ checkNewVersion: false,
553
+ sendAnonymousUsage: false
554
+ },
555
+ entryPoints: {
556
+ web: {
557
+ address: ":80",
558
+ http: { redirections: { entryPoint: {
559
+ to: ports.https === 443 ? "websecure" : `:${ports.https}`,
560
+ scheme: "https",
561
+ permanent: true
562
+ } } }
563
+ },
564
+ websecure: { address: ":443" },
565
+ ping: { address: `:${PING_PORT}` }
566
+ },
567
+ ping: { entryPoint: "ping" },
568
+ providers: { file: {
569
+ directory: EDGE_DYNAMIC_DIR,
570
+ watch: true
571
+ } },
572
+ certificatesResolvers: {
573
+ [ACME_RESOLVER]: { acme: {
574
+ storage: "/acme/acme.json",
575
+ httpChallenge: { entryPoint: "web" }
576
+ } },
577
+ [ACME_DNS_RESOLVER]: { acme: {
578
+ storage: "/acme/acme-dns.json",
579
+ dnsChallenge: {
580
+ provider: "route53",
581
+ resolvers: ["1.1.1.1:53", "8.8.8.8:53"]
582
+ }
583
+ } }
584
+ },
585
+ log: { level: "INFO" }
586
+ };
587
+ }
588
+ /** The edge's compose document. */
589
+ function edgeCompose(options) {
590
+ const { ports } = options;
591
+ return {
592
+ name: EDGE_PROJECT,
593
+ services: { [EDGE_SERVICE]: {
594
+ image: TRAEFIK_IMAGE,
595
+ restart: "unless-stopped",
596
+ ports: [`${ports.https}:443`, `${ports.http}:80`],
597
+ configs: [{
598
+ source: "traefik",
599
+ target: "/etc/traefik/traefik.yml"
600
+ }],
601
+ volumes: [
602
+ `dynamic:${EDGE_DYNAMIC_DIR}`,
603
+ `certs:${EDGE_CERTS_DIR}`,
604
+ "acme:/acme"
605
+ ],
606
+ labels: { "dev.geekmidas.edge.config": (0, node_crypto.createHash)("sha256").update(options.staticConfig).digest("hex").slice(0, 16) },
607
+ environment: {
608
+ AWS_SHARED_CREDENTIALS_FILE: EDGE_AWS_CREDENTIALS,
609
+ AWS_REGION: "us-east-1"
610
+ },
611
+ networks: ["edge"],
612
+ ...EDGE_LIMITS,
613
+ healthcheck: {
614
+ test: [
615
+ "CMD",
616
+ "traefik",
617
+ "healthcheck",
618
+ "--ping"
619
+ ],
620
+ interval: "10s",
621
+ timeout: "5s",
622
+ retries: 5
623
+ },
624
+ logging: options.logging
625
+ } },
626
+ configs: { traefik: { content: options.staticConfig } },
627
+ volumes: {
628
+ acme: {},
629
+ dynamic: {},
630
+ certs: {}
631
+ },
632
+ networks: { edge: {
633
+ name: EDGE_NETWORK,
634
+ external: true
635
+ } }
636
+ };
637
+ }
638
+ /** A stack's dynamic configuration, as an object. */
639
+ function traefikDynamic(routes, options) {
640
+ const { project, tls, edgeToken } = options;
641
+ const name = (route, suffix) => `${project}-${route.name}${suffix ? `-${suffix}` : ""}`;
642
+ const url = ({ service, port }) => `http://${edgeAlias(project, service)}:${port}`;
643
+ const routers = {};
644
+ const services = {};
645
+ const middlewares = {};
646
+ const strip = `${project}-strip-gkm-headers`;
647
+ if (routes.length > 0) middlewares[strip] = { headers: { customRequestHeaders: { [_geekmidas_manifest.CLIENT_IP_HEADER]: "" } } };
648
+ for (const route of routes) {
649
+ const chain = [strip];
650
+ const limited = /* @__PURE__ */ new Set();
651
+ if (route.allow) {
652
+ middlewares[name(route, "allow")] = { ipAllowList: { sourceRange: [...route.allow] } };
653
+ chain.push(name(route, "allow"));
654
+ }
655
+ if (route.auth) {
656
+ middlewares[name(route, "auth")] = { basicAuth: { users: [`${route.auth.user}:${route.auth.hash}`] } };
657
+ chain.push(name(route, "auth"));
658
+ }
659
+ if (route.limits?.handshakesPerMinute) {
660
+ const perMinute = route.limits.handshakesPerMinute;
661
+ middlewares[name(route, "rate")] = { rateLimit: {
662
+ average: perMinute,
663
+ period: "1m",
664
+ burst: perMinute
665
+ } };
666
+ chain.push(name(route, "rate"));
667
+ limited.add(name(route, "rate"));
668
+ }
669
+ if (route.limits?.connectionsPerIp) {
670
+ middlewares[name(route, "in-flight")] = { inFlightReq: { amount: route.limits.connectionsPerIp } };
671
+ chain.push(name(route, "in-flight"));
672
+ limited.add(name(route, "in-flight"));
673
+ }
674
+ if (route.prefix) {
675
+ middlewares[name(route, "prefix")] = { addPrefix: { prefix: route.prefix } };
676
+ chain.push(name(route, "prefix"));
677
+ }
678
+ assertRouteRenderable(route);
679
+ const allowed = [...(route.paths ?? []).map((path) => `Path(\`${path}\`)`), ...(route.prefixes ?? []).map((prefix) => `PathPrefix(\`${prefix}\`)`)];
680
+ const paths = allowed.length ? ` && (${allowed.join(" || ")})` : "";
681
+ const header = route.requireHeader ? ` && Header(\`${route.requireHeader.name}\`, \`${route.requireHeader.value}\`)` : "";
682
+ const certificate = () => route.wildcard?.tls.kind === "dns" ? {
683
+ certResolver: ACME_DNS_RESOLVER,
684
+ domains: [{ main: `*.${route.wildcard.domain}` }]
685
+ } : tls.kind === "acme" ? { certResolver: ACME_RESOLVER } : {};
686
+ for (const handler of route.handlers ?? []) {
687
+ const handlerName = name(route, handler.name);
688
+ routers[handlerName] = {
689
+ rule: `${hostRule(route)} && (${handler.prefixes.map((prefix) => `PathPrefix(\`${prefix}\`)`).join(" || ")})`,
690
+ priority: 1e4,
691
+ entryPoints: ["websecure"],
692
+ service: handlerName,
693
+ middlewares: [strip],
694
+ tls: certificate()
695
+ };
696
+ services[handlerName] = { loadBalancer: { servers: handler.upstreams.map((upstream) => ({ url: url(upstream) })) } };
697
+ }
698
+ if (route.redirects?.hosts.length) {
699
+ const redirect = name(route, "redirect");
700
+ middlewares[redirect] = { redirectRegex: {
701
+ regex: "^https?://[^/]+(.*)$",
702
+ replacement: `${route.redirects.to}$\{1}`,
703
+ permanent: true
704
+ } };
705
+ route.redirects.hosts.forEach((host, index) => {
706
+ routers[name(route, `redirect-${index + 1}`)] = {
707
+ rule: `Host(\`${host}\`)`,
708
+ entryPoints: ["websecure"],
709
+ service: "noop@internal",
710
+ middlewares: [redirect],
711
+ tls: certificate()
712
+ };
713
+ });
714
+ }
715
+ const rule = `${hostRule(route)}${paths}${header}`;
716
+ routers[name(route)] = {
717
+ rule,
718
+ ...route.wildcard ? { priority: 1 } : {},
719
+ entryPoints: ["websecure"],
720
+ service: name(route),
721
+ middlewares: chain,
722
+ tls: certificate()
723
+ };
724
+ if (edgeToken && !route.prefix) {
725
+ const trusted = chain.slice(1).filter((m) => !limited.has(m));
726
+ routers[name(route, "stack")] = {
727
+ rule: `${rule} && Header(\`${_geekmidas_manifest.EDGE_TOKEN_HEADER}\`, \`${edgeToken}\`)`,
728
+ ...route.wildcard ? { priority: 2 } : {},
729
+ entryPoints: ["websecure"],
730
+ service: name(route),
731
+ ...trusted.length > 0 ? { middlewares: trusted } : {},
732
+ tls: certificate()
733
+ };
734
+ }
735
+ services[name(route)] = { loadBalancer: {
736
+ servers: route.upstreams.map((upstream) => ({ url: url(upstream) })),
737
+ ...route.prefix ? { passHostHeader: false } : {},
738
+ ...route.streaming ? { responseForwarding: { flushInterval: "-1ms" } } : {},
739
+ ...route.health ? { healthCheck: {
740
+ path: route.health,
741
+ interval: "5s",
742
+ timeout: "3s"
743
+ } } : {}
744
+ } };
745
+ }
746
+ return {
747
+ http: {
748
+ routers,
749
+ services,
750
+ ...Object.keys(middlewares).length > 0 ? { middlewares } : {}
751
+ },
752
+ ...tls.kind === "files" ? { tls: { certificates: [{
753
+ certFile: tls.certFile,
754
+ keyFile: tls.keyFile
755
+ }] } } : {}
756
+ };
757
+ }
758
+ /**
759
+ * The hosts a route answers, as a Traefik rule: its own and its aliases', or
760
+ * — for a wildcard site — exactly one label under its domain, but the ones
761
+ * it never takes. One label, as a wildcard certificate covers: a stage at
762
+ * `staging.example.com` is never reached through `example.com`'s wildcard.
763
+ *
764
+ * Several hosts are parenthesised, `(Host(a) || Host(b))`, so whatever is
765
+ * joined to the rule with `&&` — the path allowlist, a required header, the
766
+ * stack's token — holds on every one of them. One router's hosts are one
767
+ * certificate's names under ACME.
768
+ */
769
+ function hostRule(route) {
770
+ if (!route.wildcard) {
771
+ const hosts = [route.host, ...route.aliases ?? []].map((host) => `Host(\`${host}\`)`);
772
+ return hosts.length === 1 ? hosts[0] : `(${hosts.join(" || ")})`;
773
+ }
774
+ const { domain, except } = route.wildcard;
775
+ return [`HostRegexp(\`${`^[a-z0-9-]+\\.${domain.replace(/\./g, "\\.")}$`}\`)`, ...except.map((label) => `!Host(\`${label}.${domain}\`)`)].join(" && ");
776
+ }
777
+ /**
778
+ * What a stack's routes claim on the edge, from the route model: one claim
779
+ * per host, each route's aliases and redirects included.
780
+ */
781
+ function edgeClaims(routes) {
782
+ return routes.flatMap((route) => route.wildcard ? [{
783
+ wildcard: route.wildcard.domain.toLowerCase(),
784
+ except: [...route.wildcard.except]
785
+ }] : routeHosts(route).map((host) => ({ host: host.toLowerCase() })));
786
+ }
787
+ /**
788
+ * The comment line a stack's file carries its claims on: a comment, because
789
+ * Traefik's file provider refuses a whole file over a key it does not know,
790
+ * and gkm reads it back rather than taking the routers' rules apart.
791
+ */
792
+ const CLAIMS_PREFIX = "# gkm-claims: ";
793
+ /**
794
+ * The hosts a stack's file on the edge claims: from its claims line, or — a
795
+ * file written before gkm wrote one — from its routers' rules, in the shapes
796
+ * `traefikDynamic` renders them.
797
+ */
798
+ function readEdgeClaims(file) {
799
+ for (const line of file.split("\n")) {
800
+ if (!line.startsWith(CLAIMS_PREFIX)) continue;
801
+ try {
802
+ const claims = JSON.parse(line.slice(14));
803
+ if (Array.isArray(claims)) return claims.filter(isClaim);
804
+ } catch {}
805
+ }
806
+ let document;
807
+ try {
808
+ document = (0, yaml.parse)(file);
809
+ } catch {
810
+ return [];
811
+ }
812
+ const routers = document?.http?.routers;
813
+ if (!routers || typeof routers !== "object") return [];
814
+ const claims = [];
815
+ for (const router of Object.values(routers)) {
816
+ const rule = router?.rule;
817
+ if (typeof rule === "string") claims.push(...ruleClaims(rule));
818
+ }
819
+ return claims;
820
+ }
821
+ function isClaim(value) {
822
+ if (!value || typeof value !== "object") return false;
823
+ const claim = value;
824
+ return typeof claim.host === "string" || typeof claim.wildcard === "string" && Array.isArray(claim.except);
825
+ }
826
+ /**
827
+ * The hosts a rule matches: each `Host(\`a\`)` not negated, and a
828
+ * `HostRegexp` of a wildcard site — one label under a domain — with the
829
+ * `!Host` labels it leaves out.
830
+ */
831
+ function ruleClaims(rule) {
832
+ const negated = [...rule.matchAll(/!\s*Host\(`([^`]+)`\)/g)].map((match) => match[1].toLowerCase());
833
+ const wildcard = /HostRegexp\(`\^\[a-z0-9-\]\+\\\.(.+)\$`\)/.exec(rule);
834
+ if (wildcard) {
835
+ const domain = wildcard[1].replace(/\\\./g, ".").toLowerCase();
836
+ const suffix = `.${domain}`;
837
+ return [{
838
+ wildcard: domain,
839
+ except: negated.filter((host) => host.endsWith(suffix)).map((host) => host.slice(0, -suffix.length))
840
+ }];
841
+ }
842
+ return [...rule.matchAll(/(?<![!\w])Host\(`([^`]+)`\)/g)].map((match) => ({ host: match[1].toLowerCase() }));
843
+ }
844
+ /**
845
+ * Where two claims meet, as a host to name — or undefined where they never
846
+ * do. A wildcard takes one label under its domain, so it meets a name one
847
+ * label under it that it does not leave out, and another wildcard on the
848
+ * same domain.
849
+ */
850
+ function claimsOverlap(a, b) {
851
+ if ("host" in a && "host" in b) return a.host === b.host ? a.host : void 0;
852
+ if ("wildcard" in a && "wildcard" in b) return a.wildcard === b.wildcard ? `*.${a.wildcard}` : void 0;
853
+ const [name, wildcard] = "host" in a ? [a, b] : [b, a];
854
+ const suffix = `.${wildcard.wildcard}`;
855
+ if (!name.host.endsWith(suffix)) return void 0;
856
+ const label = name.host.slice(0, -suffix.length);
857
+ if (!/^[a-z0-9-]+$/.test(label) || wildcard.except.includes(label)) return;
858
+ return name.host;
859
+ }
860
+ /** A stack's dynamic configuration file, as written to the edge's directory. */
861
+ function traefikDynamicFile(routes, options) {
862
+ return `# Generated by gkm compose for ${options.project} — do not edit.
863
+ # The shared edge (${EDGE_PROJECT}) reads every file in this directory; this
864
+ # one is removed by gkm compose --down. The hosts it routes, which no other
865
+ # stack on the edge may route:
866
+ ${CLAIMS_PREFIX}${JSON.stringify(edgeClaims(routes))}
867
+ ${yaml$1(traefikDynamic(routes, options))}`;
868
+ }
869
+ /** The edge's static configuration file. */
870
+ function traefikStaticFile(ports) {
871
+ return `# Generated by gkm compose — the server's shared edge. Do not edit.
872
+ ${yaml$1(traefikStatic(ports))}`;
873
+ }
874
+ /** The edge's compose file. */
875
+ function edgeComposeFile(options) {
876
+ return `# Generated by gkm compose — the server's shared edge. Do not edit.
877
+ #
878
+ # Started by the first stack that runs with proxy: 'traefik', and left
879
+ # running by gkm compose --down. Stop it, once nothing uses it, with:
880
+ #
881
+ # docker compose -p ${EDGE_PROJECT} down
882
+ ${yaml$1(edgeCompose(options))}`;
883
+ }
884
+ function yaml$1(value) {
885
+ return (0, yaml.stringify)(value, {
886
+ lineWidth: 0,
887
+ aliasDuplicateObjects: false
888
+ });
889
+ }
890
+ //#endregion
891
+ //#region src/compose/stack.ts
892
+ /**
893
+ * The stack a workspace runs as for one stage — pure.
894
+ *
895
+ * Everything `gkm compose` writes is decided here, as data: the compose file,
896
+ * the Caddyfile, one env file per process that reads one — each backend,
897
+ * worker and site that runs a server — and the image each app runs. The
898
+ * command around it reads the workspace, asks the registry, writes the files
899
+ * and starts Docker; none of those decide anything, so all of it can be
900
+ * asserted without a daemon.
901
+ *
902
+ * The values come from the same derivations every other target uses. The
903
+ * plan is reconcile's `planFor`, the keys a process reads are
904
+ * `processEnvKeys` — the rule `gkm dev` and `gkm exec` apply — and every URL
905
+ * is `envFor`'s, with each app at its public address: a browser and a sibling
906
+ * service reach an API by the same name, through the edge.
907
+ */
908
+ /** Where a stack's files are written, relative to the workspace root. */
909
+ function stackDir(stage) {
910
+ return `.gkm/compose/${stage}`;
911
+ }
912
+ /**
913
+ * The compose project a stage's stack runs as.
914
+ *
915
+ * The deploy identity's scope, so two workspaces with one name in different
916
+ * namespaces never share containers or volumes — and the stage, so a
917
+ * machine can run two stages side by side.
918
+ */
919
+ function composeProject(identity) {
920
+ return `${identity.scope}-${identity.stage}`;
921
+ }
922
+ /** The ports the edge is published on, and the variables that move them. */
923
+ const EDGE_PORT_ENV = {
924
+ https: "GKM_COMPOSE_HTTPS_PORT",
925
+ http: "GKM_COMPOSE_HTTP_PORT"
926
+ };
927
+ /**
928
+ * The variable that moves the local stage's OpenObserve off its loopback
929
+ * port, 5080 — which the local stage takes from nowhere else, since it
930
+ * ignores `deploy.telemetry`. Another stack, or another tool, may hold 5080.
931
+ */
932
+ const LOGS_PORT_ENV = "GKM_COMPOSE_LOGS_PORT";
933
+ /**
934
+ * Containers this target does not run.
935
+ *
936
+ * The AWS emulator never applies: a stack is a server target, whose events
937
+ * are pg-boss. Reconcile's Caddy fronts `gkm dev`'s host processes; the stack
938
+ * brings its own edge.
939
+ *
940
+ * MinIO and Mailpit run on the local stage always, and on a deployed stage
941
+ * only where `--allow-dev-services` allowed them and its secrets configure no
942
+ * real bucket or mail server — see `devServices.ts`.
943
+ */
944
+ const NOT_RUN = {
945
+ localstack: true,
946
+ caddy: true
947
+ };
948
+ /** The kinds a deployed stage takes from its secrets, or a dev service. */
949
+ const SERVICE_KINDS = {
950
+ email: "email",
951
+ objects: "objects",
952
+ "file-server": "file-server"
953
+ };
954
+ /** The region MinIO is addressed with. It has no regions; the SDK wants one. */
955
+ const MINIO_REGION = "us-east-1";
956
+ /** The S3 client's credentials, read beside a bucket's URL when it has them. */
957
+ const STORAGE_KEYS = [
958
+ "AWS_ACCESS_KEY_ID",
959
+ "AWS_SECRET_ACCESS_KEY",
960
+ "AWS_REGION"
961
+ ];
962
+ /**
963
+ * Every service's Docker logs, rotated. The json-file driver keeps a
964
+ * container's output in one file that grows until the disk is full — on a
965
+ * small server, in weeks. Three files of 10 MB each per container is enough
966
+ * to see what happened and never fills anything. A project's own override
967
+ * file that sets `logging` wins over it.
968
+ */
969
+ const LOG_ROTATION = {
970
+ driver: "json-file",
971
+ options: {
972
+ "max-size": "10m",
973
+ "max-file": "3"
974
+ }
975
+ };
976
+ /** A CDN serves the bucket, and the secret it sends the processors is not in the stage. */
977
+ var ProcessorOriginSecretMissing = class extends require_errors.GkmError {
978
+ fileServer;
979
+ key;
980
+ stage;
981
+ constructor(fileServer, key, stage) {
982
+ super(`'${fileServer}' has processors, and its bucket is not the stack's MinIO, so they are reached through the CDN in front of it — which sends ${key}, and stage '${stage}' has none. It is written by the deploy that creates the CDN (\`deploy.objects.${stage}\` on s3, cdn on): run gkm deploy --stage ${stage}.`);
983
+ this.fileServer = fileServer;
984
+ this.key = key;
985
+ this.stage = stage;
986
+ this.name = "ProcessorOriginSecretMissing";
987
+ }
988
+ };
989
+ /**
990
+ * The stack with Caddy's files inline: its Caddyfile and, where the stage has
991
+ * one, its own certificate — `configs` with their `content`, which compose
992
+ * copies into the container through the engine's API. Nothing is mounted from
993
+ * a path, so the stack runs the same on a server's engine, over SSH, as on
994
+ * this machine's. Their hash is a label: a changed file is a changed service,
995
+ * which `up` recreates (compose does not, for a config's content alone).
996
+ */
997
+ function withCaddyConfigs(compose, files) {
998
+ const caddy = compose.services.caddy;
999
+ if (!caddy) return compose;
1000
+ const configs = {
1001
+ caddyfile: { content: files.caddyfile },
1002
+ ...files.tls ? {
1003
+ "tls-cert": { content: files.tls.cert },
1004
+ "tls-key": { content: files.tls.key }
1005
+ } : {}
1006
+ };
1007
+ const hash = (0, node_crypto.createHash)("sha256");
1008
+ for (const [name, { content }] of Object.entries(configs)) hash.update(`${name}\0${content}\0`);
1009
+ return {
1010
+ ...compose,
1011
+ services: {
1012
+ ...compose.services,
1013
+ caddy: {
1014
+ ...caddy,
1015
+ configs: [{
1016
+ source: "caddyfile",
1017
+ target: "/etc/caddy/Caddyfile"
1018
+ }, ...files.tls ? [{
1019
+ source: "tls-cert",
1020
+ target: `${CADDY_TLS_DIR}/cert.pem`
1021
+ }, {
1022
+ source: "tls-key",
1023
+ target: `${CADDY_TLS_DIR}/key.pem`,
1024
+ mode: 256
1025
+ }] : []],
1026
+ labels: {
1027
+ ...caddy.labels,
1028
+ "dev.geekmidas.caddy.config": hash.digest("hex").slice(0, 16)
1029
+ }
1030
+ }
1031
+ },
1032
+ configs: {
1033
+ ...compose.configs,
1034
+ ...configs
1035
+ }
1036
+ };
1037
+ }
1038
+ /** The label the local stage's Mailpit inbox answers on. */
1039
+ const MAIL_INBOX_LABEL = "mail";
1040
+ /** Mailpit's web UI and API, inside the stack's network. */
1041
+ const MAILPIT_WEB_PORT = 8025;
1042
+ /** An app of the local stage on the host its Mailpit inbox is served at. */
1043
+ var MailInboxHostTaken = class extends require_errors.GkmError {
1044
+ host;
1045
+ app;
1046
+ constructor(host, app) {
1047
+ super(`'${app}' answers on ${host}, which the local stage serves its Mailpit inbox at. Give '${app}' another subdomain — '${MAIL_INBOX_LABEL}' is reserved for the inbox on the local stage.`);
1048
+ this.host = host;
1049
+ this.app = app;
1050
+ this.name = "MailInboxHostTaken";
1051
+ }
1052
+ };
1053
+ /**
1054
+ * The services a stack publishes on its engine's loopback, and the port each
1055
+ * answers on inside — what gkm reaches from this machine to provision the
1056
+ * stack and run its migrations and seeds. Everything else is reached only on
1057
+ * the stack's network.
1058
+ */
1059
+ const LOOPBACK_SERVICES = {
1060
+ postgres: 5432,
1061
+ minio: 9e3
1062
+ };
1063
+ /** The local stage's stack, without the logins `gkm dev` generates. */
1064
+ var LocalCredentialsMissing = class extends require_errors.GkmError {
1065
+ stage;
1066
+ constructor(stage) {
1067
+ super(`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.`);
1068
+ this.stage = stage;
1069
+ this.name = "LocalCredentialsMissing";
1070
+ }
1071
+ };
1072
+ /**
1073
+ * A deployed stage's container logins, derived from its seed like its role
1074
+ * passwords — so every deploy of the stage computes the same ones, and no one
1075
+ * reading the repo can.
1076
+ */
1077
+ function derivedCredentials(project, plan, seed) {
1078
+ const derive = (purpose) => require_apps.localRolePassword(project, plan, purpose, seed);
1079
+ return {
1080
+ postgres: {
1081
+ user: require_compose.postgresSuperuser(project),
1082
+ password: derive("master")
1083
+ },
1084
+ minio: {
1085
+ user: `${project}-minio`,
1086
+ password: derive("minio")
1087
+ },
1088
+ rabbitmq: {
1089
+ user: require_compose.LOCAL_RABBITMQ_USER,
1090
+ password: derive("rabbitmq")
1091
+ },
1092
+ redis: { password: derive("redis") },
1093
+ cacheToken: derive("cache-token"),
1094
+ emulator: {
1095
+ accessKeyId: require_compose.EMULATOR_ACCESS_KEY_ID,
1096
+ secretAccessKey: derive("emulator")
1097
+ },
1098
+ logs: {
1099
+ email: `admin@${project}`,
1100
+ password: derive("logs")
1101
+ }
1102
+ };
1103
+ }
1104
+ /** A value only the stage's secrets can hold, and they do not. */
1105
+ var StageSecretMissing = class extends require_errors.GkmError {
1106
+ app;
1107
+ key;
1108
+ stage;
1109
+ constructor(app, key, stage) {
1110
+ super(`'${app}' reads ${key}, and the stage '${stage}' has none. Nothing in the stack can derive it; set it in the stage's secrets: gkm secrets:set ${key} '…' --stage ${stage}`);
1111
+ this.app = app;
1112
+ this.key = key;
1113
+ this.stage = stage;
1114
+ this.name = "StageSecretMissing";
1115
+ }
1116
+ };
1117
+ /**
1118
+ * One key of a deployed inbox — the one rule every target reads it by.
1119
+ *
1120
+ * Its domain is the stage's, which mail is addressed to. Everything else (where
1121
+ * its raw messages are read, its topic's publisher string) is what its
1122
+ * provider made and wrote to the stage's secrets; nothing can derive it.
1123
+ *
1124
+ * @throws {NoDomainForStage} for its domain when the stage has none.
1125
+ * @throws {StageSecretMissing} when the provider has not written the key.
1126
+ */
1127
+ function deployedInboxValue(inbox, key, sources) {
1128
+ if (key === (0, _geekmidas_manifest.providedKeyFor)(inbox, "inbox", "domain")) {
1129
+ if (!sources.domain) throw new require_compose.NoDomainForStage(sources.stage);
1130
+ return sources.domain;
1131
+ }
1132
+ const value = sources.secrets[key];
1133
+ if (value === void 0) throw new StageSecretMissing(sources.reader, key, sources.stage);
1134
+ return value;
1135
+ }
1136
+ /**
1137
+ * Every deployed inbox's keys, and its topic's publisher string, by key: what
1138
+ * a target that provisions nothing of the inbox's (SST) is handed, read by
1139
+ * {@link deployedInboxValue} as the compose stack reads each.
1140
+ */
1141
+ function deployedInboxEnv(manifest, sources) {
1142
+ const env = {};
1143
+ for (const declaration of Object.values(manifest)) {
1144
+ if (declaration.kind !== "inbox") continue;
1145
+ const keys = [...declaration.provides ?? [], (0, _geekmidas_manifest.providedKeyFor)(declaration.topic, "topic", "publisherConnectionString")];
1146
+ for (const key of keys) env[key] = deployedInboxValue(declaration.id, key, sources);
1147
+ }
1148
+ return env;
1149
+ }
1150
+ /** A deployed stage's secrets with no seed to derive its passwords from. */
1151
+ var StageSeedMissing = class extends require_errors.GkmError {
1152
+ stage;
1153
+ constructor(stage) {
1154
+ super(`The stage '${stage}' has no seed in its secrets, and a deployed stage's database passwords are derived from it. Run gkm compose --stage ${stage} without --dry-run once, or gkm deploy, to generate it.`);
1155
+ this.stage = stage;
1156
+ this.name = "StageSeedMissing";
1157
+ }
1158
+ };
1159
+ /** A workspace with no API and no site to run. */
1160
+ var NothingToCompose = class extends require_errors.GkmError {
1161
+ root;
1162
+ constructor(root) {
1163
+ super(`${root} declares no RestApi, no site and no Worker with work to do, so a stack would run nothing. Mobile apps ship through their own toolchain.`);
1164
+ this.root = root;
1165
+ this.name = "NothingToCompose";
1166
+ }
1167
+ };
1168
+ /** A value that cannot be written to an env file a line at a time. */
1169
+ var EnvValueMultiline = class extends require_errors.GkmError {
1170
+ app;
1171
+ key;
1172
+ constructor(app, key) {
1173
+ super(`${key} for '${app}' spans more than one line, and an env file holds one value per line. Store it on one line — base64, or JSON — and decode it where it is read.`);
1174
+ this.app = app;
1175
+ this.key = key;
1176
+ this.name = "EnvValueMultiline";
1177
+ }
1178
+ };
1179
+ /** The services a stack's apps wait on. */
1180
+ const HEALTHY = { condition: "service_healthy" };
1181
+ /**
1182
+ * What Caddy waits on of each app: that it started, never that it is
1183
+ * healthy. Its routes are served whatever an app's health — Caddy's own
1184
+ * upstream health checks take one out of rotation — so one app that never
1185
+ * turns healthy leaves the others routed, and a site whose health check goes
1186
+ * through the edge can turn healthy at all.
1187
+ */
1188
+ const STARTED = { condition: "service_started" };
1189
+ /**
1190
+ * An app's health check: its own server, asked on 127.0.0.1 — not
1191
+ * `localhost`, which resolves to `::1` first in an Alpine container while a
1192
+ * server may listen on IPv4 alone.
1193
+ */
1194
+ function probe(port, path) {
1195
+ return {
1196
+ test: [
1197
+ "CMD",
1198
+ "wget",
1199
+ "-q",
1200
+ "-O",
1201
+ "/dev/null",
1202
+ `http://127.0.0.1:${port}${path}`
1203
+ ],
1204
+ interval: "5s",
1205
+ timeout: "3s",
1206
+ retries: 20,
1207
+ start_period: "10s"
1208
+ };
1209
+ }
1210
+ /**
1211
+ * What a stage's stack provisions: reconcile's plan, with a server target's
1212
+ * backends whatever `deploy.default` says — the stack is one machine running
1213
+ * containers, so events are pg-boss beside the declared database, and every
1214
+ * cache, one declared from that database included, is in the stack's own
1215
+ * Redis.
1216
+ */
1217
+ function stackPlan(workspace, manifest, stage) {
1218
+ const protectedSubdomains = [...workspace.protectedSubdomains ?? [], ...nestedStageLabels(workspace.domains, stage)];
1219
+ return require_apps.planFor(manifest, stage, (0, _geekmidas_manifest.provisionOrder)(manifest), {
1220
+ localStage: workspace.stages.local,
1221
+ ...protectedSubdomains.length > 0 ? { protectedSubdomains } : {},
1222
+ events: require_types.DEFAULT_EVENTS.server,
1223
+ cache: require_compose.STACK_CACHE,
1224
+ edge: false
1225
+ });
1226
+ }
1227
+ /** The stack for one stage. */
1228
+ function composeStack(input) {
1229
+ const { workspace, manifest, stage, identity } = input;
1230
+ const local = stage === workspace.stages.local;
1231
+ const project = composeProject(identity);
1232
+ const custom = input.secrets?.custom ?? {};
1233
+ const https = input.ports?.https ?? 443;
1234
+ const http = input.ports?.http ?? 80;
1235
+ const proxy = require_workspace.proxyFor(workspace.deploy?.compose, stage, local);
1236
+ const certificate = require_workspace.certificateFor(workspace.deploy?.compose, stage, workspace.root);
1237
+ const plan = stackPlan(workspace, manifest, stage);
1238
+ const byId = new Map(plan.resources.map((r) => [r.id, r]));
1239
+ if (local && !input.localCredentials) throw new LocalCredentialsMissing(stage);
1240
+ const seed = local ? input.localCredentials.seed : input.secrets?.seed;
1241
+ if (!seed) throw new StageSeedMissing(stage);
1242
+ const containers = local ? input.localCredentials : derivedCredentials(workspace.name, plan, seed);
1243
+ const credential = {
1244
+ containers: {
1245
+ ...containers,
1246
+ minio: {
1247
+ user: custom.AWS_ACCESS_KEY_ID ?? containers.minio.user,
1248
+ password: custom.AWS_SECRET_ACCESS_KEY ?? containers.minio.password
1249
+ }
1250
+ },
1251
+ seed
1252
+ };
1253
+ const apps = stackApps(workspace, manifest, plan, {
1254
+ local,
1255
+ stage,
1256
+ https,
1257
+ identity,
1258
+ images: input.images
1259
+ });
1260
+ const workers = stackWorkers(require_apps.workerUnits(workspace, manifest, input.background ?? {}), {
1261
+ stage,
1262
+ identity,
1263
+ images: input.images
1264
+ });
1265
+ const processors = stackProcessors(require_apps.processorUnits(workspace, manifest), {
1266
+ manifest,
1267
+ stage,
1268
+ identity,
1269
+ images: input.images
1270
+ });
1271
+ if (apps.length === 0 && workers.length === 0 && processors.length === 0) throw new NothingToCompose(workspace.root);
1272
+ const owners = /* @__PURE__ */ new Map();
1273
+ for (const resource of plan.resources) {
1274
+ owners.set(resource.envKey, resource);
1275
+ if (resource.kind === "email") {
1276
+ owners.set((0, _geekmidas_manifest.providedKeyFor)(resource.id, resource.kind, "from"), resource);
1277
+ owners.set((0, _geekmidas_manifest.providedKeyFor)(resource.id, resource.kind, "inboxUrl"), resource);
1278
+ }
1279
+ if (resource.kind === "objects") owners.set((0, _geekmidas_manifest.providedKeyFor)(resource.id, resource.kind, "signedOrigin"), resource);
1280
+ if (resource.kind === "external-api") owners.set((0, _geekmidas_manifest.providedKeyFor)(resource.id, resource.kind, "credentials"), resource);
1281
+ if (resource.kind === "inbox") owners.set((0, _geekmidas_manifest.providedKeyFor)(resource.id, resource.kind, "domain"), resource);
1282
+ if (resource.kind === "websocket-api") owners.set((0, _geekmidas_manifest.providedKeyFor)(resource.id, resource.kind, "publisherConnectionString"), resource);
1283
+ }
1284
+ const domain = workspace.domains?.[stage];
1285
+ const telemetry = require_workspace.resolveStageTelemetry({
1286
+ ...workspace.deploy?.telemetry ? { telemetry: workspace.deploy.telemetry } : {},
1287
+ stage,
1288
+ local,
1289
+ target: "compose",
1290
+ runtime: "server",
1291
+ selfHosted: true,
1292
+ used: require_apps.usesTelemetry(manifest)
1293
+ });
1294
+ const logsBase = telemetry?.provider === "self-hosted" ? require_compose.stackLogs({
1295
+ config: local && input.ports?.logs ? {
1296
+ ...telemetry.selfHosted,
1297
+ port: input.ports.logs
1298
+ } : telemetry.selfHosted,
1299
+ stage,
1300
+ local,
1301
+ project: workspace.name,
1302
+ ...domain ? { domain } : {},
1303
+ custom,
1304
+ https,
1305
+ ...local ? { localLogin: input.localCredentials.logs } : {}
1306
+ }) : void 0;
1307
+ const services = local ? {
1308
+ missing: [],
1309
+ minio: plan.resources.filter((r) => r.kind === "objects").map((r) => r.id),
1310
+ mailpit: plan.resources.filter((r) => r.kind === "email" || r.kind === "inbox").map((r) => r.id)
1311
+ } : require_notes.externalServices({
1312
+ stage,
1313
+ declarations: require_notes.stageServiceDeclarations({ manifest }),
1314
+ supplied: custom,
1315
+ allow: input.allowDevServices === true,
1316
+ ...domain ? { domain } : {},
1317
+ providers: require_notes.stageProviderNotes(workspace, stage)
1318
+ });
1319
+ const redis = require_compose.stackRedis({
1320
+ plan,
1321
+ stage,
1322
+ local,
1323
+ custom,
1324
+ ...local ? { localPassword: input.localCredentials.redis.password } : {}
1325
+ });
1326
+ const infra = [...plan.containers.filter((c) => !NOT_RUN[c]).filter((c) => c !== require_compose.LOGS_SERVICE).filter((c) => c !== "minio" || services.minio.length > 0).filter((c) => c !== "mailpit" || services.mailpit.length > 0).filter((c) => c !== "redis" || redis !== void 0), ...logsBase ? [require_compose.LOGS_SERVICE] : []].sort();
1327
+ const mailInbox = local && infra.includes("mailpit") ? (() => {
1328
+ const host = [
1329
+ MAIL_INBOX_LABEL,
1330
+ workspace.name,
1331
+ require_apps.LOCAL_TLD
1332
+ ].filter(Boolean).join(".");
1333
+ return {
1334
+ host,
1335
+ url: `https://${host}${https !== 443 ? `:${https}` : ""}`
1336
+ };
1337
+ })() : void 0;
1338
+ const storage = infra.includes("minio") ? (() => {
1339
+ const buckets = services.minio.map((id) => byId.get(id)?.name).filter((name) => Boolean(name)).sort();
1340
+ return {
1341
+ ...credential.containers.minio,
1342
+ buckets,
1343
+ policies: require_apps.bucketPolicies(plan).filter((p) => buckets.includes(p.bucket)),
1344
+ objects: services.minio.map((id) => ({
1345
+ id,
1346
+ name: byId.get(id)?.name
1347
+ })).filter((b) => Boolean(b.name)).sort((a, b) => a.name.localeCompare(b.name)),
1348
+ webhooks: [],
1349
+ lifecycles: require_apps.bucketLifecycles(plan).filter((l) => buckets.includes(l.bucket))
1350
+ };
1351
+ })() : void 0;
1352
+ const bucketEventKeys = /* @__PURE__ */ new Map();
1353
+ for (const resource of plan.resources) {
1354
+ if (resource.kind !== "objects") continue;
1355
+ bucketEventKeys.set((0, _geekmidas_manifest.providedKeyFor)(resource.id, resource.kind, "eventsConnectionString"), resource.id);
1356
+ bucketEventKeys.set((0, _geekmidas_manifest.providedKeyFor)(resource.id, resource.kind, "eventsToken"), resource.id);
1357
+ }
1358
+ const fileServers = /* @__PURE__ */ new Map();
1359
+ if (storage) for (const resource of plan.resources) {
1360
+ if (resource.kind !== "file-server" || !resource.of) continue;
1361
+ if (!services.minio.includes(resource.of)) continue;
1362
+ if (custom[resource.envKey] !== void 0) continue;
1363
+ const bucket = byId.get(resource.of);
1364
+ if (!bucket) continue;
1365
+ let host;
1366
+ if (local) host = require_apps.hostFor(resource, workspace.name);
1367
+ else {
1368
+ if (!domain) throw new require_compose.NoDomainForStage(stage);
1369
+ host = `${require_workspace.fileServerLabel(resource.id)}.${domain}`;
1370
+ }
1371
+ fileServers.set(resource.id, {
1372
+ url: `https://${host}${local && https !== 443 ? `:${https}` : ""}`,
1373
+ route: {
1374
+ name: `files-${require_workspace.appKey(resource.id)}`,
1375
+ host,
1376
+ upstreams: [{
1377
+ service: "minio",
1378
+ port: 9e3
1379
+ }],
1380
+ streaming: false,
1381
+ prefix: `/${bucket.name}`
1382
+ }
1383
+ });
1384
+ }
1385
+ const edgeServices = new Set(proxy === "traefik" ? [
1386
+ ...apps.flatMap(replicaNames),
1387
+ ...fileServers.size > 0 ? ["minio"] : [],
1388
+ ...logsBase?.host && logsBase.public ? [require_compose.LOGS_SERVICE] : [],
1389
+ ...mailInbox ? ["mailpit"] : []
1390
+ ] : []);
1391
+ const hostOf = (service) => edgeServices.has(service) ? edgeAlias(project, service) : service;
1392
+ const logs = logsBase && {
1393
+ ...logsBase,
1394
+ appEnv: {
1395
+ ...logsBase.appEnv,
1396
+ OTEL_EXPORTER_OTLP_ENDPOINT: logsBase.appEnv.OTEL_EXPORTER_OTLP_ENDPOINT.replace(`//openobserve:`, `//${hostOf("openobserve")}:`)
1397
+ }
1398
+ };
1399
+ const derivation = {
1400
+ project: workspace.name,
1401
+ credentials: credential.containers,
1402
+ seed: credential.seed,
1403
+ ...!local && domain ? { mailDomain: domain } : {},
1404
+ relayedBuckets: [...require_compose.watchedBuckets(manifest, input.subscribers ?? {}).keys()].filter((bucket) => services.minio.includes(bucket))
1405
+ };
1406
+ const publicAddresses = Object.fromEntries(apps.map((app) => [app.id, app.url]));
1407
+ const aliasAddresses = Object.fromEntries(apps.map((app) => [app.id, (app.aliases ?? []).map((alias) => `https://${alias}${local && https !== 443 ? `:${https}` : ""}`)]));
1408
+ const outside = require_apps.networkEnv(plan, {
1409
+ ...derivation,
1410
+ addresses: publicAddresses,
1411
+ aliasAddresses
1412
+ }, hostOf);
1413
+ /**
1414
+ * What a key resolves to for one app, from the stage's secrets where only
1415
+ * they can hold it, and the derivations otherwise.
1416
+ */
1417
+ const valueFor = (app, key, owner) => {
1418
+ if (require_workspace.isReservedStageKey(key)) return void 0;
1419
+ const watching = bucketEventKeys.get(key);
1420
+ if (watching) {
1421
+ if (custom[key] !== void 0) return custom[key];
1422
+ return services.minio.includes(watching) ? outside[key] : void 0;
1423
+ }
1424
+ if (owner?.kind === "inbox") {
1425
+ if (local) return outside[key];
1426
+ return deployedInboxValue(owner.id, key, {
1427
+ reader: app.name,
1428
+ stage,
1429
+ domain,
1430
+ secrets: custom
1431
+ });
1432
+ }
1433
+ if (!local && owner?.kind === "email" && key.endsWith("_INBOX_URL")) return;
1434
+ if (owner && SERVICE_KINDS[owner.kind]) {
1435
+ if (custom[key] !== void 0) return custom[key];
1436
+ if (owner.kind === "file-server") return fileServers.get(owner.id)?.url;
1437
+ if (owner.kind === "objects") {
1438
+ if (key === (0, _geekmidas_manifest.providedKeyFor)(owner.id, owner.kind, "signedOrigin")) return require_apps.signedOrigins([owner.id], (k) => valueFor(app, k, owner))[key];
1439
+ if (!services.minio.includes(owner.id)) return void 0;
1440
+ }
1441
+ return outside[key];
1442
+ }
1443
+ if (owner && require_notes.suppliedOnly(owner.kind, owner.id, key, local)) {
1444
+ const value = custom[key];
1445
+ if (value === void 0) throw new StageSecretMissing(app.name, key, stage);
1446
+ return value;
1447
+ }
1448
+ if (custom[key] !== void 0) return custom[key];
1449
+ if (owner?.kind === "cache") return redis?.urls[key];
1450
+ if (owner?.kind === "websocket-api" && key === (0, _geekmidas_manifest.providedKeyFor)(owner.id, owner.kind, "publisherConnectionString")) return redis?.urls[key];
1451
+ return outside[key];
1452
+ };
1453
+ const telemetryValues = logs ? require_workspace.telemetryEnv({
1454
+ endpoint: logs.appEnv.OTEL_EXPORTER_OTLP_ENDPOINT,
1455
+ headers: logs.appEnv.OTEL_EXPORTER_OTLP_HEADERS
1456
+ }, telemetry?.sampleRate ?? 1) : telemetry?.provider === "otlp" ? require_workspace.otlpTelemetryEnv(telemetry) : void 0;
1457
+ /** Each key one backend process reads, resolved for this stage. */
1458
+ const valuesFor = (app, keys) => {
1459
+ const values = {};
1460
+ for (const key of [...keys].sort()) {
1461
+ if (require_apps.isTelemetryKey(key)) continue;
1462
+ const owner = owners.get(key) ?? storageOwner(key, plan);
1463
+ if (STORAGE_KEYS.includes(key)) {
1464
+ const value = custom[key] ?? storageValue(key, storage);
1465
+ if (value !== void 0) values[key] = value;
1466
+ continue;
1467
+ }
1468
+ const value = valueFor(app, key, owner);
1469
+ if (value !== void 0) values[key] = value;
1470
+ }
1471
+ return values;
1472
+ };
1473
+ const stageKeys = Object.keys(custom);
1474
+ for (const app of apps) {
1475
+ const site = manifest[app.id];
1476
+ if (site?.kind === "site") {
1477
+ const args = require_apps.publicBuildValues(site, manifest, (key) => valueFor(app, key, owners.get(key)), custom, !local && app.build ? { requireFileOrigins: { stage } } : {});
1478
+ if (app.prerender && input.prerenderRun) args[require_apps.PRERENDER_RUN_ARG] = input.prerenderRun;
1479
+ if (app.build && Object.keys(args).length > 0) app.build.args = args;
1480
+ const offline = require_apps.offlineBuildHosts(site, manifest, (key) => valueFor(app, key, owners.get(key)));
1481
+ if (app.build && offline.length > 0) app.build.offlineHosts = offline;
1482
+ if (!app.runtime) continue;
1483
+ }
1484
+ if (input.buildOnly) continue;
1485
+ const values = valuesFor(app, require_apps.processEnvKeys(manifest, { app: app.name }, stageKeys) ?? /* @__PURE__ */ new Set());
1486
+ app.env = {
1487
+ ...require_apps.scopeTelemetryEnv(values, {
1488
+ uses: app.kind !== "site" && require_apps.telemetryOf(manifest, app.id) !== void 0,
1489
+ serviceName: app.name,
1490
+ ...telemetryValues ? { telemetry: telemetryValues } : {}
1491
+ }),
1492
+ NODE_ENV: "production",
1493
+ PORT: String(app.port),
1494
+ STAGE: stage
1495
+ };
1496
+ for (const [key, value] of Object.entries(app.env)) if (/[\r\n]/.test(value)) throw new EnvValueMultiline(app.name, key);
1497
+ }
1498
+ const mobileApps = [];
1499
+ for (const declaration of Object.values(manifest)) {
1500
+ if (declaration.kind !== "mobile-app") continue;
1501
+ const app = {
1502
+ name: require_workspace.appKey(declaration.id),
1503
+ id: declaration.id,
1504
+ kind: "site"
1505
+ };
1506
+ mobileApps.push({
1507
+ name: app.name,
1508
+ id: app.id,
1509
+ values: require_apps.publicBuildValues(declaration, manifest, (key) => valueFor(app, key, owners.get(key)), custom)
1510
+ });
1511
+ }
1512
+ for (const worker of input.buildOnly ? [] : workers) {
1513
+ const keys = require_apps.processEnvKeys(manifest, { workers: [worker.id] }, stageKeys) ?? /* @__PURE__ */ new Set();
1514
+ const resolved = valuesFor({
1515
+ name: worker.name,
1516
+ id: worker.id,
1517
+ kind: "rest-api"
1518
+ }, keys);
1519
+ const push = local ? void 0 : workerPush(worker, input.subscribers?.[worker.id] ?? [], resolved, {
1520
+ stage,
1521
+ ...domain ? { domain } : {}
1522
+ });
1523
+ if (push) {
1524
+ worker.push = push;
1525
+ if (proxy === "traefik") edgeServices.add(worker.name);
1526
+ }
1527
+ worker.env = {
1528
+ ...require_apps.scopeTelemetryEnv(resolved, {
1529
+ uses: require_apps.telemetryOf(manifest, worker.id) !== void 0,
1530
+ serviceName: worker.name,
1531
+ ...telemetryValues ? { telemetry: telemetryValues } : {}
1532
+ }),
1533
+ ...push && !input.recordingSubscriptions ? { [require_SubscriberGenerator.SNS_SUBSCRIPTIONS_KEY]: recordedSubscriptions(worker, push, input.pushSubscriptions?.[worker.id]) } : {},
1534
+ NODE_ENV: "production",
1535
+ PORT: String(worker.port),
1536
+ STAGE: stage
1537
+ };
1538
+ for (const [key, value] of Object.entries(worker.env)) if (/[\r\n]/.test(value)) throw new EnvValueMultiline(worker.name, key);
1539
+ }
1540
+ for (const unit of processors) {
1541
+ const served = fileServers.get(unit.id);
1542
+ if (served) served.route = {
1543
+ ...served.route,
1544
+ handlers: [{
1545
+ name: unit.name,
1546
+ prefixes: unit.prefixes,
1547
+ upstreams: [{
1548
+ service: unit.name,
1549
+ port: unit.port
1550
+ }]
1551
+ }]
1552
+ };
1553
+ else if (!local && !input.buildOnly) {
1554
+ if (!domain) throw new require_compose.NoDomainForStage(stage);
1555
+ const key = require_apps.originSecretKey(unit.id);
1556
+ const secret = custom[key];
1557
+ if (!secret) throw new ProcessorOriginSecretMissing(unit.id, key, stage);
1558
+ unit.origin = {
1559
+ host: require_apps.processorOriginHost(unit.id, domain),
1560
+ secret
1561
+ };
1562
+ }
1563
+ if (proxy === "traefik" && (served || unit.origin)) edgeServices.add(unit.name);
1564
+ if (input.buildOnly) continue;
1565
+ const keys = require_apps.processEnvKeys(manifest, { processors: [unit.id] }, stageKeys) ?? /* @__PURE__ */ new Set();
1566
+ unit.env = {
1567
+ ...require_apps.scopeTelemetryEnv(valuesFor({
1568
+ name: unit.name,
1569
+ id: unit.id,
1570
+ kind: "rest-api"
1571
+ }, keys), {
1572
+ uses: require_apps.telemetryOf(manifest, unit.id) !== void 0,
1573
+ serviceName: unit.name,
1574
+ ...telemetryValues ? { telemetry: telemetryValues } : {}
1575
+ }),
1576
+ NODE_ENV: "production",
1577
+ PORT: String(unit.port),
1578
+ STAGE: stage
1579
+ };
1580
+ for (const [key, value] of Object.entries(unit.env)) if (/[\r\n]/.test(value)) throw new EnvValueMultiline(unit.name, key);
1581
+ }
1582
+ if (storage && !input.buildOnly) {
1583
+ const watched = require_compose.watchedBuckets(manifest, input.subscribers ?? {});
1584
+ for (const [bucket, workerId] of watched) {
1585
+ if (!services.minio.includes(bucket)) continue;
1586
+ const worker = workers.find((w) => w.id === workerId);
1587
+ const relay = worker?.env?.[(0, _geekmidas_manifest.providedKeyFor)(bucket, "objects", "eventsConnectionString")];
1588
+ const token = worker?.env?.[(0, _geekmidas_manifest.providedKeyFor)(bucket, "objects", "eventsToken")];
1589
+ if (!worker || !relay || relay.startsWith("sns:") || !token) continue;
1590
+ storage.webhooks.push({
1591
+ bucket,
1592
+ endpoint: `http://${hostOf(worker.name)}:${worker.port}${require_SubscriberGenerator.objectsRoute(bucket)}`,
1593
+ token
1594
+ });
1595
+ }
1596
+ }
1597
+ let inboxRelay;
1598
+ if (local && infra.includes("mailpit") && !input.buildOnly) {
1599
+ const relayId = require_SubscriberGenerator.inboxRelayWorker(manifest, input.subscribers ?? {});
1600
+ const relay = workers.find((w) => w.id === relayId);
1601
+ const token = relay?.env?.[require_SubscriberGenerator.INBOX_RELAY_TOKEN_KEY];
1602
+ if (relay && token) inboxRelay = require_SubscriberGenerator.inboxWebhookUrl(`http://${hostOf(relay.name)}:${relay.port}`, token);
1603
+ }
1604
+ const tls = certificate || local ? {
1605
+ kind: "files",
1606
+ ...proxy === "caddy" ? {
1607
+ certFile: `${CADDY_TLS_DIR}/cert.pem`,
1608
+ keyFile: `${CADDY_TLS_DIR}/key.pem`
1609
+ } : edgeCertificatePaths(project)
1610
+ } : { kind: "acme" };
1611
+ const authority = local && !certificate ? input.localAuthority ?? require_apps.localAuthorityPaths() : void 0;
1612
+ const root = authority?.certFile ?? certificate?.caFile;
1613
+ const backupsChoice = input.buildOnly ? void 0 : require_apps.stageBackups(workspace, manifest, stage);
1614
+ const backups = backupsChoice?.mode === "on" && infra.includes("postgres") ? require_apps.stackBackups({
1615
+ workspace,
1616
+ stage,
1617
+ project,
1618
+ plan,
1619
+ backups: backupsChoice.backups,
1620
+ custom,
1621
+ seed,
1622
+ superuser: credential.containers.postgres,
1623
+ ...telemetryValues ? { telemetry: telemetryValues } : {}
1624
+ }) : void 0;
1625
+ if (!local) for (const app of apps) {
1626
+ const site = manifest[app.id];
1627
+ if (site?.kind !== "site") continue;
1628
+ const key = sitePasswordKey(manifest, site, stage);
1629
+ if (key) app.auth = siteAuth(stage, key, custom);
1630
+ }
1631
+ const wildcard = local ? void 0 : stackWildcard(apps, {
1632
+ manifest,
1633
+ byId,
1634
+ workspace,
1635
+ stage,
1636
+ proxy,
1637
+ certificate: certificate !== void 0,
1638
+ hostOf
1639
+ });
1640
+ const routes = [
1641
+ ...apps.map((app) => ({
1642
+ name: app.name,
1643
+ host: app.host,
1644
+ ...app.aliases?.length ? { aliases: app.aliases } : {},
1645
+ ...app.redirects?.length ? { redirects: {
1646
+ hosts: app.redirects,
1647
+ to: app.url
1648
+ } } : {},
1649
+ ...wildcard?.site === app.id ? { wildcard: wildcard.edge } : {},
1650
+ upstreams: replicaNames(app).map((service) => ({
1651
+ service,
1652
+ port: app.port
1653
+ })),
1654
+ streaming: true,
1655
+ ...app.auth ? { auth: {
1656
+ user: app.auth.user,
1657
+ hash: app.auth.hash
1658
+ } } : {},
1659
+ ...app.limits ? { limits: app.limits } : {},
1660
+ health: app.kind === "site" ? "/" : "/health"
1661
+ })),
1662
+ ...[...fileServers.values()].map(({ route }) => route),
1663
+ ...processors.flatMap(({ name, port, prefixes, origin }) => origin ? [{
1664
+ name,
1665
+ host: origin.host,
1666
+ upstreams: [{
1667
+ service: name,
1668
+ port
1669
+ }],
1670
+ streaming: false,
1671
+ prefixes,
1672
+ requireHeader: {
1673
+ name: require_apps.ORIGIN_VERIFY_HEADER,
1674
+ value: origin.secret
1675
+ },
1676
+ health: "/health"
1677
+ }] : []),
1678
+ ...workers.flatMap(({ name, port, push }) => push ? [{
1679
+ name,
1680
+ host: push.host,
1681
+ upstreams: [{
1682
+ service: name,
1683
+ port
1684
+ }],
1685
+ streaming: false,
1686
+ paths: push.paths,
1687
+ health: "/health"
1688
+ }] : []),
1689
+ ...logs?.host && logs.public ? [{
1690
+ name: require_compose.LOGS_SERVICE,
1691
+ host: logs.host,
1692
+ upstreams: [{
1693
+ service: require_compose.LOGS_SERVICE,
1694
+ port: require_workspace.LOGS_PORT
1695
+ }],
1696
+ streaming: true,
1697
+ allow: logs.public.allow
1698
+ }] : []
1699
+ ];
1700
+ if (mailInbox) {
1701
+ const taken = routes.find((route) => routeHosts(route).includes(mailInbox.host));
1702
+ if (taken) throw new MailInboxHostTaken(mailInbox.host, taken.name);
1703
+ routes.push({
1704
+ name: "mailpit",
1705
+ host: mailInbox.host,
1706
+ upstreams: [{
1707
+ service: "mailpit",
1708
+ port: MAILPIT_WEB_PORT
1709
+ }],
1710
+ streaming: true
1711
+ });
1712
+ }
1713
+ assertHostsUnique(routes);
1714
+ const layout = input.layout ?? defaultLayout(workspace.root);
1715
+ const compose = stackFile({
1716
+ project,
1717
+ plan,
1718
+ infra,
1719
+ apps,
1720
+ workers,
1721
+ processors,
1722
+ credentials: credential.containers,
1723
+ ...storage ? { storage } : {},
1724
+ ...inboxRelay ? { inboxRelay } : {},
1725
+ ...logs ? { logs } : {},
1726
+ ...redis ? { redis } : {},
1727
+ ...backups ? { backups } : {},
1728
+ https,
1729
+ http,
1730
+ composeDir: (0, node_path.join)(workspace.root, stackDir(stage)),
1731
+ buildRoot: layout.buildRoot,
1732
+ workspaceRoot: workspace.root,
1733
+ envFiles: !input.buildOnly,
1734
+ proxy,
1735
+ edge: new Map([...edgeServices].map((service) => [service, hostOf(service)])),
1736
+ ...local ? { localEdge: {
1737
+ hosts: stackPublicHosts(routes),
1738
+ ...root ? { authority: root } : {}
1739
+ } } : {}
1740
+ });
1741
+ const dockerfiles = {};
1742
+ for (const app of apps) {
1743
+ if (!app.build) continue;
1744
+ dockerfiles[app.build.dockerfile] = require_docker.appDockerfile(app.name, workspace.apps[app.name], {
1745
+ layout,
1746
+ workspaceRoot: workspace.root,
1747
+ apps: workspace.apps,
1748
+ manifest,
1749
+ cache: require_compose.STACK_CACHE,
1750
+ workspace,
1751
+ stage,
1752
+ ...app.kind === "site" && app.build.args ? { publicUrlArgs: Object.keys(app.build.args).filter((key) => key !== require_apps.PRERENDER_RUN_ARG) } : {}
1753
+ });
1754
+ }
1755
+ for (const worker of workers) {
1756
+ if (!worker.build) continue;
1757
+ dockerfiles[worker.build.dockerfile] = require_docker.workerDockerfile({
1758
+ id: worker.id,
1759
+ name: worker.name,
1760
+ app: worker.host
1761
+ }, workspace.apps[worker.host], {
1762
+ layout,
1763
+ workspaceRoot: workspace.root,
1764
+ cache: require_compose.STACK_CACHE
1765
+ });
1766
+ }
1767
+ for (const unit of processors) {
1768
+ if (!unit.build) continue;
1769
+ dockerfiles[unit.build.dockerfile] = require_docker.processorDockerfile({
1770
+ id: unit.id,
1771
+ name: unit.name,
1772
+ app: unit.host
1773
+ }, workspace.apps[unit.host], {
1774
+ layout,
1775
+ workspaceRoot: workspace.root,
1776
+ cache: require_compose.STACK_CACHE
1777
+ });
1778
+ }
1779
+ return {
1780
+ project,
1781
+ stage,
1782
+ local,
1783
+ ...authority ? { authority } : {},
1784
+ apps,
1785
+ workers,
1786
+ processors,
1787
+ mobileApps,
1788
+ infra,
1789
+ compose,
1790
+ proxy,
1791
+ routes,
1792
+ ...wildcard ? { wildcard: {
1793
+ site: wildcard.site,
1794
+ host: `*.${wildcard.edge.domain}`,
1795
+ tls: wildcard.edge.tls.kind
1796
+ } } : {},
1797
+ ...proxy === "caddy" ? { caddyfile: edgeCaddyfile(routes, {
1798
+ tls,
1799
+ edgeToken: outside[_geekmidas_manifest.EDGE_TOKEN_KEY],
1800
+ ...local ? { redirects: false } : {}
1801
+ }) } : { traefik: traefikDynamicFile(routes, {
1802
+ project,
1803
+ tls,
1804
+ edgeToken: outside[_geekmidas_manifest.EDGE_TOKEN_KEY]
1805
+ }) },
1806
+ ...certificate ? { tls: certificate } : {},
1807
+ dockerfiles,
1808
+ plan,
1809
+ credential,
1810
+ resolution: {
1811
+ ...derivation,
1812
+ addresses: {
1813
+ ...publicAddresses,
1814
+ ...Object.fromEntries([...fileServers].map(([id, { url }]) => [id, url]))
1815
+ }
1816
+ },
1817
+ ...storage ? { storage } : {},
1818
+ devServices: local ? [] : require_notes.devServicesUsed(services),
1819
+ ...logs ? { logs } : {},
1820
+ ...telemetry ? { telemetry } : {},
1821
+ ...redis ? { redis } : {},
1822
+ ...backups ? { backups } : {},
1823
+ ...mailInbox ? { mailInbox } : {}
1824
+ };
1825
+ }
1826
+ /** The stack's MinIO's value for one of the S3 client's keys. */
1827
+ function storageValue(key, storage) {
1828
+ if (!storage) return void 0;
1829
+ if (key === "AWS_ACCESS_KEY_ID") return storage.user;
1830
+ if (key === "AWS_SECRET_ACCESS_KEY") return storage.password;
1831
+ if (key === "AWS_REGION") return MINIO_REGION;
1832
+ }
1833
+ /** Which bucket an S3 credential key belongs to — the first one declared. */
1834
+ function storageOwner(key, plan) {
1835
+ if (!STORAGE_KEYS.includes(key)) return void 0;
1836
+ return plan.resources.find((r) => r.kind === "objects");
1837
+ }
1838
+ /** The apps a stack runs: every API and every site, at its stage address. */
1839
+ function stackApps(workspace, manifest, plan, options) {
1840
+ const apps = [];
1841
+ const resources = new Map(plan.resources.map((r) => [r.id, r]));
1842
+ for (const [id, declaration] of Object.entries(manifest)) {
1843
+ if (declaration.kind !== "rest-api" && declaration.kind !== "websocket-api" && declaration.kind !== "site") continue;
1844
+ const name = require_workspace.appKey(id);
1845
+ const app = workspace.apps[name];
1846
+ const resource = resources.get(id);
1847
+ if (!app || !resource || !app.port) continue;
1848
+ const { host, aliases, redirects } = appHosts(name, app, workspace, resource, options);
1849
+ const site = declaration.kind === "site";
1850
+ const tag = site ? siteTag(options.images.tag, options.stage) : options.images.tag;
1851
+ const ref = require_docker.validateImageRef(require_credentials.imageRef(options.identity, name, options.images.registry, tag));
1852
+ apps.push({
1853
+ app: name,
1854
+ name,
1855
+ id,
1856
+ kind: declaration.kind,
1857
+ ...declaration.kind === "site" ? { variant: declaration.variant } : {},
1858
+ replicas: declaration.kind === "websocket-api" ? declaration.replicas ?? 1 : 1,
1859
+ ...declaration.kind === "websocket-api" && declaration.limits ? { limits: declaration.limits } : {},
1860
+ runtime: !site || require_apps.runsServer(declaration),
1861
+ path: app.path,
1862
+ port: app.port,
1863
+ host,
1864
+ ...aliases.length ? { aliases } : {},
1865
+ ...redirects.length ? { redirects } : {},
1866
+ url: `${declaration.kind === "websocket-api" ? "wss" : "https"}://${host}${options.local && options.https !== 443 ? `:${options.https}` : ""}`,
1867
+ ref,
1868
+ tag,
1869
+ ...options.images.mode === "build" ? { build: { dockerfile: `${stackDir(options.stage)}/Dockerfile.${name}` } } : {}
1870
+ });
1871
+ }
1872
+ const byId = new Map(apps.map((app) => [app.id, app.name]));
1873
+ for (const app of apps) {
1874
+ const declaration = manifest[app.id];
1875
+ if (declaration?.kind !== "site" || declaration.prerender !== "stage") continue;
1876
+ const against = declaration.dependencies.map(({ target }) => byId.get(target)).filter((name) => !!name && name !== app.name);
1877
+ app.prerender = { against: [...new Set(against)].sort() };
1878
+ }
1879
+ return apps.sort((a, b) => a.name.localeCompare(b.name));
1880
+ }
1881
+ /**
1882
+ * Where SNS pushes to a worker on a deployed stage, or nothing when it pushes
1883
+ * to none of its subscribers.
1884
+ *
1885
+ * A subscriber is pushed to when the connection string its deliveries come
1886
+ * from — its topic's, or its bucket's events — as this stage resolved it for
1887
+ * the worker, is an SNS one — the same test the worker's own
1888
+ * startup makes, so the edge exposes a route exactly when the worker mounts
1889
+ * it. Each such route, and nothing else the worker serves, answers on
1890
+ * `<worker>.<domain>`.
1891
+ */
1892
+ function workerPush(worker, subscribers, env, options) {
1893
+ const pushed = subscribers.filter(({ connectionKey }) => env[connectionKey]?.startsWith("sns:")).filter((subscriber, index, all) => all.findIndex((s) => s.name === subscriber.name) === index).sort((a, b) => a.name.localeCompare(b.name));
1894
+ if (pushed.length === 0) return void 0;
1895
+ if (!options.domain) throw new require_compose.NoDomainForStage(options.stage);
1896
+ const host = `${worker.name}.${options.domain}`;
1897
+ const url = `https://${host}`;
1898
+ return {
1899
+ host,
1900
+ url,
1901
+ paths: pushed.map(({ name }) => require_SubscriberGenerator.subscriberRoute(name)),
1902
+ subscribers: pushed.map(({ name, connectionKey, events }) => ({
1903
+ name,
1904
+ connectionKey,
1905
+ endpoint: `${url}${require_SubscriberGenerator.subscriberRoute(name)}`,
1906
+ ...events ? { events } : {}
1907
+ }))
1908
+ };
1909
+ }
1910
+ /** A pushed subscriber the deploy recorded no SNS subscription for. */
1911
+ var PushSubscriptionMissing = class extends require_errors.GkmError {
1912
+ worker;
1913
+ subscriber;
1914
+ constructor(worker, subscriber) {
1915
+ super(`SNS pushes to '${subscriber}' on the worker '${worker}', and the deploy recorded no subscription for it, so the worker would mount no route and SNS would deliver nowhere. Deploy the stage, which subscribes each pushed subscriber and records its ARN.`);
1916
+ this.worker = worker;
1917
+ this.subscriber = subscriber;
1918
+ this.name = "PushSubscriptionMissing";
1919
+ }
1920
+ };
1921
+ /**
1922
+ * The worker's `GKM_SNS_SUBSCRIPTIONS`: each pushed subscriber's recorded
1923
+ * subscription ARN, and nothing for a subscriber it does not run.
1924
+ *
1925
+ * @throws {PushSubscriptionMissing} when one has none
1926
+ */
1927
+ function recordedSubscriptions(worker, push, recorded = {}) {
1928
+ const arns = {};
1929
+ for (const { name } of push.subscribers) {
1930
+ const arn = recorded[name];
1931
+ if (!arn) throw new PushSubscriptionMissing(worker.name, name);
1932
+ arns[name] = arn;
1933
+ }
1934
+ return JSON.stringify(arns);
1935
+ }
1936
+ /**
1937
+ * A wildcard site on a deployed stage with nowhere to get a certificate for
1938
+ * its tenants' hosts from. Let's Encrypt issues a wildcard certificate only
1939
+ * over the DNS challenge, so the stage either brings its own or gives the
1940
+ * proxy a way to get one.
1941
+ */
1942
+ var WildcardSiteCertificateMissing = class extends require_errors.GkmError {
1943
+ site;
1944
+ stage;
1945
+ proxy;
1946
+ domain;
1947
+ constructor(site, stage, proxy, domain) {
1948
+ super(proxy === "traefik" ? `'${site}' answers on every subdomain of ${domain}, and '${stage}' has no certificate for them. Set deploy.compose.tls for '${stage}' to a *.${domain} certificate, or manage ${domain} with dns: { '<root domain>': { provider: 'route53' } } so the shared edge gets one over the DNS challenge.` : `'${site}' answers on every subdomain of ${domain}, and '${stage}' has no certificate for them. Set deploy.compose.tls for '${stage}' to a *.${domain} certificate, or give the site \`hosts\` so Caddy gets one per tenant, on demand.`);
1949
+ this.site = site;
1950
+ this.stage = stage;
1951
+ this.proxy = proxy;
1952
+ this.domain = domain;
1953
+ this.name = "WildcardSiteCertificateMissing";
1954
+ }
1955
+ };
1956
+ /**
1957
+ * A deployed stage's wildcard site, as its edge serves it: the labels it
1958
+ * never takes, and its certificate — the stage's own (`deploy.compose.tls`)
1959
+ * first; then, on the shared Traefik edge, a `*.<domain>` one over the DNS
1960
+ * challenge when Route 53 manages the domain; on the stack's own Caddy, one
1961
+ * per host on demand, asked of the site's `hosts` route.
1962
+ *
1963
+ * @throws {WildcardSiteCertificateMissing} when neither applies
1964
+ */
1965
+ function stackWildcard(apps, options) {
1966
+ const { manifest, workspace, stage, proxy } = options;
1967
+ const app = apps.find((a) => (0, _geekmidas_manifest.isWildcardSite)(manifest[a.id]));
1968
+ if (!app) return void 0;
1969
+ const declaration = manifest[app.id];
1970
+ if (!(0, _geekmidas_manifest.isWildcardSite)(declaration)) return void 0;
1971
+ const domain = workspace.domains?.[stage];
1972
+ if (!domain) throw new require_compose.NoDomainForStage(stage);
1973
+ const except = options.byId.get(app.id)?.protectedSubdomains ?? [];
1974
+ const tls = (() => {
1975
+ if (options.certificate) return { kind: "stage" };
1976
+ if (proxy === "traefik") {
1977
+ const dns = workspace.dns ? require_credentials.normalizeDnsConfig(workspace.dns) : {};
1978
+ const root = require_credentials.findRootDomain(domain, dns);
1979
+ if (root && dns[root]?.provider === "route53") return { kind: "dns" };
1980
+ } else if (declaration.hosts) {
1981
+ const surface = apps.find((a) => a.id === declaration.hosts?.surface);
1982
+ if (surface) return {
1983
+ kind: "on-demand",
1984
+ ask: `http://${options.hostOf(surface.name)}:${surface.port}${declaration.hosts.path}`
1985
+ };
1986
+ }
1987
+ throw new WildcardSiteCertificateMissing(app.id, stage, proxy, domain);
1988
+ })();
1989
+ return {
1990
+ site: app.id,
1991
+ edge: {
1992
+ domain,
1993
+ except,
1994
+ tls
1995
+ }
1996
+ };
1997
+ }
1998
+ /**
1999
+ * The first label under `stage`'s domain of every other stage's domain that
2000
+ * sits beneath it — `staging` for `staging.example.com` (or
2001
+ * `a.staging.example.com`) under `example.com`.
2002
+ */
2003
+ function nestedStageLabels(domains, stage) {
2004
+ const own = domains?.[stage]?.toLowerCase();
2005
+ if (!own) return [];
2006
+ const labels = /* @__PURE__ */ new Set();
2007
+ for (const [other, domain] of Object.entries(domains ?? {})) {
2008
+ if (other === stage || !domain) continue;
2009
+ const lower = domain.toLowerCase();
2010
+ if (!lower.endsWith(`.${own}`)) continue;
2011
+ const rest = lower.slice(0, -(own.length + 1)).split(".");
2012
+ labels.add(rest.at(-1));
2013
+ }
2014
+ return [...labels].sort();
2015
+ }
2016
+ /** Two constructs the edge would answer on one host. */
2017
+ var EdgeHostTaken = class extends require_errors.GkmError {
2018
+ host;
2019
+ first;
2020
+ second;
2021
+ constructor(host, first, second) {
2022
+ super(`'${first}' and '${second}' would both answer on ${host}, and the edge can send a host to only one of them. Give one a subdomain of its own, or rename it.`);
2023
+ this.host = host;
2024
+ this.first = first;
2025
+ this.second = second;
2026
+ this.name = "EdgeHostTaken";
2027
+ }
2028
+ };
2029
+ /**
2030
+ * Refuse a stack where one host would be routed to two services — every
2031
+ * host of every route, its aliases and redirects included.
2032
+ */
2033
+ function assertHostsUnique(routes) {
2034
+ const claimed = /* @__PURE__ */ new Map();
2035
+ for (const route of routes) for (const host of routeHosts(route)) {
2036
+ const first = claimed.get(host);
2037
+ if (first !== void 0 && first !== route.name) throw new EdgeHostTaken(host, first, route.name);
2038
+ claimed.set(host, route.name);
2039
+ }
2040
+ }
2041
+ /** Each processor unit's image, and where it is built from. */
2042
+ function stackProcessors(units, options) {
2043
+ return units.map((unit) => {
2044
+ const server = options.manifest[unit.id];
2045
+ const processors = server?.kind === "file-server" ? server.processors ?? [] : [];
2046
+ return {
2047
+ app: unit.name,
2048
+ name: unit.name,
2049
+ id: unit.id,
2050
+ host: unit.app,
2051
+ port: require_apps.PROCESSOR_PORT,
2052
+ prefixes: [...new Set(processors.map((p) => p.prefix))].sort(),
2053
+ ref: require_docker.validateImageRef(require_credentials.imageRef(options.identity, unit.name, options.images.registry, options.images.tag)),
2054
+ tag: options.images.tag,
2055
+ ...options.images.mode === "build" ? { build: { dockerfile: `${stackDir(options.stage)}/Dockerfile.${unit.name}` } } : {}
2056
+ };
2057
+ });
2058
+ }
2059
+ /** Each worker's image, and where it is built from. */
2060
+ function stackWorkers(units, options) {
2061
+ return units.map((unit) => ({
2062
+ app: unit.name,
2063
+ name: unit.name,
2064
+ id: unit.id,
2065
+ host: unit.app,
2066
+ port: require_apps.WORKER_PORT,
2067
+ ref: require_docker.validateImageRef(require_credentials.imageRef(options.identity, unit.name, options.images.registry, options.images.tag)),
2068
+ tag: options.images.tag,
2069
+ ...options.images.mode === "build" ? { build: { dockerfile: `${stackDir(options.stage)}/Dockerfile.${unit.name}` } } : {}
2070
+ }));
2071
+ }
2072
+ /**
2073
+ * The hosts an app answers on for a stage: the `gkm dev` edge's
2074
+ * `*.localhost` names for the local stage (`hostsFor`), and the stage's
2075
+ * domain — by the same rule a deploy follows — for any other. Its aliases
2076
+ * and redirects are labels under the stage's domain, as its own is.
2077
+ */
2078
+ function appHosts(name, app, workspace, resource, options) {
2079
+ if (options.local) return require_apps.hostsFor(resource, workspace.name);
2080
+ const domain = workspace.domains?.[options.stage];
2081
+ if (resource.subdomain === _geekmidas_manifest.WILDCARD_SUBDOMAIN) {
2082
+ if (!domain) throw new require_compose.NoDomainForStage(options.stage);
2083
+ return {
2084
+ host: `${_geekmidas_manifest.WILDCARD_SUBDOMAIN}.${domain}`,
2085
+ aliases: [],
2086
+ redirects: []
2087
+ };
2088
+ }
2089
+ const host = require_compose.resolveHost(name, app, options.stage, workspace.domains, require_compose.isMainFrontendApp(name, app, workspace.apps));
2090
+ const under = (label) => {
2091
+ if (!domain) throw new require_compose.NoDomainForStage(options.stage);
2092
+ return `${label}.${domain}`;
2093
+ };
2094
+ return {
2095
+ host,
2096
+ aliases: (resource.aliases ?? []).map(under),
2097
+ redirects: (resource.redirects ?? []).map(under)
2098
+ };
2099
+ }
2100
+ /** An app's compose services, one per replica: `api`, `api-2`, `api-3`. */
2101
+ function replicaNames(app) {
2102
+ return [app.name, ...Array.from({ length: app.replicas - 1 }, (_, i) => `${app.name}-${i + 2}`)];
2103
+ }
2104
+ /** Where an app container reads gkm's root certificate: mounted read-only. */
2105
+ const LOCAL_CA_IN_CONTAINER = "/etc/gkm/local-ca.pem";
2106
+ /**
2107
+ * The local stage's public hosts a container can be pointed at: every
2108
+ * route's but a wildcard's, which no host entry can name.
2109
+ */
2110
+ function stackPublicHosts(routes) {
2111
+ return [...new Set(routes.flatMap(routeHosts))].filter((host) => !host.startsWith("*.")).sort();
2112
+ }
2113
+ /**
2114
+ * What a local stack's container needs to call the stage's own public hosts —
2115
+ * `https://api.<project>.localhost`, which a site's server-side code is
2116
+ * handed because a browser is.
2117
+ *
2118
+ * Inside a container `*.localhost` is its own loopback, so each host is
2119
+ * resolved to the host's gateway, where the edge — the stack's Caddy, or the
2120
+ * shared Traefik edge — publishes its ports. Not a network alias on the edge:
2121
+ * the address may carry the edge's published port
2122
+ * (`https://api.shop.localhost:8443`), which only the host answers on. And the
2123
+ * container trusts the root the edge's certificate chains to — gkm's, or the
2124
+ * one the stage's own certificate names — its public certificate, never a
2125
+ * key, mounted read-only.
2126
+ */
2127
+ function localEdgeAccess(edge) {
2128
+ return {
2129
+ extra_hosts: edge.hosts.map((host) => `${host}:host-gateway`),
2130
+ volumes: edge.authority ? [`${edge.authority}:${LOCAL_CA_IN_CONTAINER}:ro`] : [],
2131
+ environment: edge.authority ? { NODE_EXTRA_CA_CERTS: LOCAL_CA_IN_CONTAINER } : {}
2132
+ };
2133
+ }
2134
+ /**
2135
+ * What the build of a site that pre-renders against its stage needs to reach
2136
+ * the stage's public hosts. A deployed stage's resolve and are trusted as
2137
+ * anywhere. The local stage's are `*.localhost` — the build's own loopback —
2138
+ * so each is pointed at the host's gateway, where the edge publishes its
2139
+ * ports, and the build is handed the root the edge's certificate chains to,
2140
+ * as {@link localEdgeAccess} hands a container both.
2141
+ *
2142
+ * Not the stack's network: BuildKit builds on none but its own.
2143
+ */
2144
+ function prerenderBuildAccess(edge) {
2145
+ if (!edge) return {};
2146
+ const { extra_hosts } = localEdgeAccess(edge);
2147
+ return {
2148
+ ...extra_hosts.length ? { extra_hosts } : {},
2149
+ ...edge.authority ? { secrets: [require_apps.LOCAL_CA_BUILD_SECRET] } : {}
2150
+ };
2151
+ }
2152
+ /** The compose document: the infrastructure, the apps, and the edge. */
2153
+ function stackFile(options) {
2154
+ const { project, plan, apps } = options;
2155
+ const infra = options.infra.filter((name) => name !== require_compose.LOGS_SERVICE);
2156
+ const derived = require_compose.composeFor({
2157
+ ...plan,
2158
+ containers: [...infra]
2159
+ }, {
2160
+ project,
2161
+ ports: Object.fromEntries(require_compose.portKeys(infra, plan.fakes).map((key) => [key, 0])),
2162
+ credentials: options.credentials
2163
+ });
2164
+ const services = {};
2165
+ const volumes = {
2166
+ ...derived.volumes,
2167
+ ...options.proxy === "caddy" ? {
2168
+ "caddy-data": {},
2169
+ "caddy-config": {}
2170
+ } : {},
2171
+ ...options.logs ? { "openobserve-data": {} } : {}
2172
+ };
2173
+ for (const name of infra) {
2174
+ const { ports: _ports, depends_on, profiles: _profiles, ...service } = derived.services[name];
2175
+ services[name] = {
2176
+ ...service,
2177
+ ...depends_on?.length ? { depends_on: Object.fromEntries(depends_on.map((dep) => [dep, HEALTHY])) } : {}
2178
+ };
2179
+ }
2180
+ const postgres = services.postgres;
2181
+ if (postgres) postgres.ports = [`127.0.0.1::${LOOPBACK_SERVICES.postgres}`];
2182
+ const minio = services.minio;
2183
+ if (minio && options.storage) {
2184
+ minio.environment = {
2185
+ ...minio.environment,
2186
+ MINIO_ROOT_USER: options.storage.user,
2187
+ MINIO_ROOT_PASSWORD: options.storage.password,
2188
+ ...require_compose.minioWebhookEnv(options.storage.webhooks)
2189
+ };
2190
+ minio.ports = [`127.0.0.1::${LOOPBACK_SERVICES.minio}`];
2191
+ }
2192
+ const mailpit = services.mailpit;
2193
+ if (mailpit && options.inboxRelay) mailpit.environment = {
2194
+ ...mailpit.environment,
2195
+ MP_WEBHOOK_URL: options.inboxRelay
2196
+ };
2197
+ if (services["redis"] && options.redis) services[require_compose.REDIS_SERVICE] = require_compose.redisService(options.redis);
2198
+ if (options.logs) services[require_compose.LOGS_SERVICE] = require_compose.logsService(options.logs);
2199
+ if (options.backups) services[require_apps.BACKUPS_SERVICE] = require_apps.backupsService(options.backups, options.envFiles);
2200
+ for (const app of apps) {
2201
+ const definition = {
2202
+ image: app.ref,
2203
+ ...app.build ? { build: {
2204
+ ...require_apps.composeBuildPaths({
2205
+ composeDir: options.composeDir,
2206
+ buildRoot: options.buildRoot,
2207
+ workspaceRoot: options.workspaceRoot,
2208
+ dockerfile: app.build.dockerfile
2209
+ }),
2210
+ ...app.build.args ? { args: app.build.args } : {},
2211
+ ...app.build.offlineHosts ? { extra_hosts: app.build.offlineHosts.map((host) => `${host}:${require_apps.OFFLINE_BUILD_ADDRESS}`) } : {},
2212
+ ...app.prerender ? prerenderBuildAccess(options.localEdge) : {}
2213
+ } } : {},
2214
+ restart: "unless-stopped",
2215
+ ...app.runtime ? { env_file: [{
2216
+ path: `./${app.name}.env`,
2217
+ format: "raw"
2218
+ }] } : {},
2219
+ ...app.kind !== "site" && infra.length ? { depends_on: Object.fromEntries(infra.map((name) => [name, HEALTHY])) } : {},
2220
+ healthcheck: probe(app.port, app.kind === "site" ? "/" : "/health"),
2221
+ ...app.kind === "websocket-api" ? { ulimits: { nofile: NOFILE } } : {}
2222
+ };
2223
+ for (const name of replicaNames(app)) services[name] = { ...definition };
2224
+ }
2225
+ for (const worker of [...options.workers, ...options.processors]) services[worker.name] = {
2226
+ image: worker.ref,
2227
+ ...worker.build ? { build: require_apps.composeBuildPaths({
2228
+ composeDir: options.composeDir,
2229
+ buildRoot: options.buildRoot,
2230
+ workspaceRoot: options.workspaceRoot,
2231
+ dockerfile: worker.build.dockerfile
2232
+ }) } : {},
2233
+ restart: "unless-stopped",
2234
+ env_file: [{
2235
+ path: `./${worker.name}.env`,
2236
+ format: "raw"
2237
+ }],
2238
+ ...infra.length ? { depends_on: Object.fromEntries(infra.map((name) => [name, HEALTHY])) } : {},
2239
+ healthcheck: probe(worker.port, "/health")
2240
+ };
2241
+ if (options.localEdge) {
2242
+ const access = localEdgeAccess(options.localEdge);
2243
+ for (const name of [
2244
+ ...apps.flatMap(replicaNames),
2245
+ ...options.workers.map((w) => w.name),
2246
+ ...options.processors.map((p) => p.name)
2247
+ ]) {
2248
+ const service = services[name];
2249
+ if (!service) continue;
2250
+ services[name] = {
2251
+ ...service,
2252
+ environment: {
2253
+ ...service.environment,
2254
+ ...access.environment
2255
+ },
2256
+ ...access.volumes.length ? { volumes: [...service.volumes ?? [], ...access.volumes] } : {},
2257
+ ...access.extra_hosts.length ? { extra_hosts: [...service.extra_hosts ?? [], ...access.extra_hosts] } : {}
2258
+ };
2259
+ }
2260
+ }
2261
+ if (options.proxy === "caddy") services.caddy = {
2262
+ image: require_compose.DEFAULT_IMAGES.caddy,
2263
+ restart: "unless-stopped",
2264
+ ports: [`${options.https}:443`, `${options.http}:80`],
2265
+ volumes: ["caddy-data:/data", "caddy-config:/config"],
2266
+ ...EDGE_LIMITS,
2267
+ depends_on: Object.fromEntries([
2268
+ ...apps.filter((app) => !(app.prerender && app.build)).flatMap(replicaNames),
2269
+ ...options.workers.filter((w) => w.push).map((w) => w.name),
2270
+ ...options.processors.map((p) => p.name)
2271
+ ].map((name) => [name, STARTED])),
2272
+ healthcheck: {
2273
+ test: [
2274
+ "CMD",
2275
+ "caddy",
2276
+ "version"
2277
+ ],
2278
+ interval: "10s",
2279
+ timeout: "5s",
2280
+ retries: 5
2281
+ }
2282
+ };
2283
+ for (const [service, alias] of options.edge) {
2284
+ const definition = services[service];
2285
+ if (!definition) continue;
2286
+ definition.networks = {
2287
+ default: { aliases: [alias] },
2288
+ edge: { aliases: [alias] }
2289
+ };
2290
+ }
2291
+ for (const service of Object.values(services)) {
2292
+ if (!options.envFiles) delete service.env_file;
2293
+ service.logging = {
2294
+ driver: LOG_ROTATION.driver,
2295
+ options: { ...LOG_ROTATION.options }
2296
+ };
2297
+ }
2298
+ const authority = options.localEdge?.authority;
2299
+ return {
2300
+ name: project,
2301
+ services,
2302
+ volumes,
2303
+ ...apps.some((app) => app.prerender && app.build) && authority ? { secrets: { [require_apps.LOCAL_CA_BUILD_SECRET]: { file: authority } } } : {},
2304
+ ...options.edge.size > 0 ? { networks: { edge: {
2305
+ name: EDGE_NETWORK,
2306
+ external: true
2307
+ } } } : {}
2308
+ };
2309
+ }
2310
+ /**
2311
+ * A build without a layout: the workspace is the build root, with pnpm.
2312
+ * What a caller that never looked at the filesystem gets.
2313
+ */
2314
+ function defaultLayout(root) {
2315
+ return {
2316
+ buildRoot: root,
2317
+ gkmRoot: ".",
2318
+ tools: {
2319
+ packageManager: "pnpm",
2320
+ turboVersion: require_apps.TURBO_VERSION,
2321
+ monorepo: true
2322
+ },
2323
+ gkmPaths: ["gkm.config.*"]
2324
+ };
2325
+ }
2326
+ /** Render an app's env file: one `KEY=value` per line, read raw by compose. */
2327
+ function envFile(env) {
2328
+ return `${Object.entries(env).sort(([a], [b]) => a.localeCompare(b)).map(([key, value]) => `${key}=${value}`).join("\n")}\n`;
2329
+ }
2330
+ //#endregion
2331
+ Object.defineProperty(exports, "EDGE_AWS_CREDENTIALS", {
2332
+ enumerable: true,
2333
+ get: function() {
2334
+ return EDGE_AWS_CREDENTIALS;
2335
+ }
2336
+ });
2337
+ Object.defineProperty(exports, "EDGE_CERTS_DIR", {
2338
+ enumerable: true,
2339
+ get: function() {
2340
+ return EDGE_CERTS_DIR;
2341
+ }
2342
+ });
2343
+ Object.defineProperty(exports, "EDGE_DYNAMIC_DIR", {
2344
+ enumerable: true,
2345
+ get: function() {
2346
+ return EDGE_DYNAMIC_DIR;
2347
+ }
2348
+ });
2349
+ Object.defineProperty(exports, "EDGE_NETWORK", {
2350
+ enumerable: true,
2351
+ get: function() {
2352
+ return EDGE_NETWORK;
2353
+ }
2354
+ });
2355
+ Object.defineProperty(exports, "EDGE_PORT_ENV", {
2356
+ enumerable: true,
2357
+ get: function() {
2358
+ return EDGE_PORT_ENV;
2359
+ }
2360
+ });
2361
+ Object.defineProperty(exports, "EDGE_PROJECT", {
2362
+ enumerable: true,
2363
+ get: function() {
2364
+ return EDGE_PROJECT;
2365
+ }
2366
+ });
2367
+ Object.defineProperty(exports, "EDGE_SERVICE", {
2368
+ enumerable: true,
2369
+ get: function() {
2370
+ return EDGE_SERVICE;
2371
+ }
2372
+ });
2373
+ Object.defineProperty(exports, "LOGS_PORT_ENV", {
2374
+ enumerable: true,
2375
+ get: function() {
2376
+ return LOGS_PORT_ENV;
2377
+ }
2378
+ });
2379
+ Object.defineProperty(exports, "LOG_ROTATION", {
2380
+ enumerable: true,
2381
+ get: function() {
2382
+ return LOG_ROTATION;
2383
+ }
2384
+ });
2385
+ Object.defineProperty(exports, "LOOPBACK_SERVICES", {
2386
+ enumerable: true,
2387
+ get: function() {
2388
+ return LOOPBACK_SERVICES;
2389
+ }
2390
+ });
2391
+ Object.defineProperty(exports, "RegistryRequired", {
2392
+ enumerable: true,
2393
+ get: function() {
2394
+ return RegistryRequired;
2395
+ }
2396
+ });
2397
+ Object.defineProperty(exports, "assertImagesExist", {
2398
+ enumerable: true,
2399
+ get: function() {
2400
+ return assertImagesExist;
2401
+ }
2402
+ });
2403
+ Object.defineProperty(exports, "assertSitePasswords", {
2404
+ enumerable: true,
2405
+ get: function() {
2406
+ return assertSitePasswords;
2407
+ }
2408
+ });
2409
+ Object.defineProperty(exports, "claimsOverlap", {
2410
+ enumerable: true,
2411
+ get: function() {
2412
+ return claimsOverlap;
2413
+ }
2414
+ });
2415
+ Object.defineProperty(exports, "composeProject", {
2416
+ enumerable: true,
2417
+ get: function() {
2418
+ return composeProject;
2419
+ }
2420
+ });
2421
+ Object.defineProperty(exports, "composeStack", {
2422
+ enumerable: true,
2423
+ get: function() {
2424
+ return composeStack;
2425
+ }
2426
+ });
2427
+ Object.defineProperty(exports, "deployedInboxEnv", {
2428
+ enumerable: true,
2429
+ get: function() {
2430
+ return deployedInboxEnv;
2431
+ }
2432
+ });
2433
+ Object.defineProperty(exports, "derivedCredentials", {
2434
+ enumerable: true,
2435
+ get: function() {
2436
+ return derivedCredentials;
2437
+ }
2438
+ });
2439
+ Object.defineProperty(exports, "edgeComposeFile", {
2440
+ enumerable: true,
2441
+ get: function() {
2442
+ return edgeComposeFile;
2443
+ }
2444
+ });
2445
+ Object.defineProperty(exports, "envFile", {
2446
+ enumerable: true,
2447
+ get: function() {
2448
+ return envFile;
2449
+ }
2450
+ });
2451
+ Object.defineProperty(exports, "parseDigests", {
2452
+ enumerable: true,
2453
+ get: function() {
2454
+ return parseDigests;
2455
+ }
2456
+ });
2457
+ Object.defineProperty(exports, "pinImages", {
2458
+ enumerable: true,
2459
+ get: function() {
2460
+ return pinImages;
2461
+ }
2462
+ });
2463
+ Object.defineProperty(exports, "pinnedRef", {
2464
+ enumerable: true,
2465
+ get: function() {
2466
+ return pinnedRef;
2467
+ }
2468
+ });
2469
+ Object.defineProperty(exports, "readEdgeClaims", {
2470
+ enumerable: true,
2471
+ get: function() {
2472
+ return readEdgeClaims;
2473
+ }
2474
+ });
2475
+ Object.defineProperty(exports, "replicaNames", {
2476
+ enumerable: true,
2477
+ get: function() {
2478
+ return replicaNames;
2479
+ }
2480
+ });
2481
+ Object.defineProperty(exports, "routeHosts", {
2482
+ enumerable: true,
2483
+ get: function() {
2484
+ return routeHosts;
2485
+ }
2486
+ });
2487
+ Object.defineProperty(exports, "stackDir", {
2488
+ enumerable: true,
2489
+ get: function() {
2490
+ return stackDir;
2491
+ }
2492
+ });
2493
+ Object.defineProperty(exports, "stackPlan", {
2494
+ enumerable: true,
2495
+ get: function() {
2496
+ return stackPlan;
2497
+ }
2498
+ });
2499
+ Object.defineProperty(exports, "traefikStaticFile", {
2500
+ enumerable: true,
2501
+ get: function() {
2502
+ return traefikStaticFile;
2503
+ }
2504
+ });
2505
+ Object.defineProperty(exports, "withCaddyConfigs", {
2506
+ enumerable: true,
2507
+ get: function() {
2508
+ return withCaddyConfigs;
2509
+ }
2510
+ });
2511
+
2512
+ //# sourceMappingURL=stack-A3evQgbk.cjs.map