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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (448) hide show
  1. package/README.md +323 -380
  2. package/bin/adjacent-tsconfig.mjs +46 -8
  3. package/bin/gkm.mjs +11 -3
  4. package/bin/owning-tsconfig-jsx-register.mjs +18 -0
  5. package/bin/owning-tsconfig-jsx.mjs +108 -0
  6. package/dist/EndpointGenerator-CBKH87_b.mjs +1043 -0
  7. package/dist/EndpointGenerator-CBKH87_b.mjs.map +1 -0
  8. package/dist/EndpointGenerator-iyA3HkOH.cjs +1102 -0
  9. package/dist/EndpointGenerator-iyA3HkOH.cjs.map +1 -0
  10. package/dist/LegacyStateStore-DvufVJjQ.cjs +124 -0
  11. package/dist/LegacyStateStore-DvufVJjQ.cjs.map +1 -0
  12. package/dist/LegacyStateStore-p-_Z8ucw.mjs +124 -0
  13. package/dist/LegacyStateStore-p-_Z8ucw.mjs.map +1 -0
  14. package/dist/LocalStateStore-BKAi5XsN.mjs +167 -0
  15. package/dist/LocalStateStore-BKAi5XsN.mjs.map +1 -0
  16. package/dist/LocalStateStore-DLDD6udB.cjs +178 -0
  17. package/dist/LocalStateStore-DLDD6udB.cjs.map +1 -0
  18. package/dist/OpenApiTsGenerator-CoVA3Ykv.mjs +534 -0
  19. package/dist/OpenApiTsGenerator-CoVA3Ykv.mjs.map +1 -0
  20. package/dist/OpenApiTsGenerator-vy-fOJgs.cjs +539 -0
  21. package/dist/OpenApiTsGenerator-vy-fOJgs.cjs.map +1 -0
  22. package/dist/S3StateStore-C8thID2w.mjs +223 -0
  23. package/dist/S3StateStore-C8thID2w.mjs.map +1 -0
  24. package/dist/S3StateStore-J3FztlVC.cjs +222 -0
  25. package/dist/S3StateStore-J3FztlVC.cjs.map +1 -0
  26. package/dist/SSMStateStore-0TQsme40.mjs +205 -0
  27. package/dist/SSMStateStore-0TQsme40.mjs.map +1 -0
  28. package/dist/SSMStateStore-DhkkSF1D.cjs +204 -0
  29. package/dist/SSMStateStore-DhkkSF1D.cjs.map +1 -0
  30. package/dist/SubscriberGenerator-B3jHf26s.mjs +787 -0
  31. package/dist/SubscriberGenerator-B3jHf26s.mjs.map +1 -0
  32. package/dist/SubscriberGenerator-JhwVlWBS.cjs +852 -0
  33. package/dist/SubscriberGenerator-JhwVlWBS.cjs.map +1 -0
  34. package/dist/add-DWCzdPLz.mjs +711 -0
  35. package/dist/add-DWCzdPLz.mjs.map +1 -0
  36. package/dist/add-gs34ewLG.cjs +713 -0
  37. package/dist/add-gs34ewLG.cjs.map +1 -0
  38. package/dist/appPorts-BoXMwolc.mjs +249 -0
  39. package/dist/appPorts-BoXMwolc.mjs.map +1 -0
  40. package/dist/appPorts-IW-OZmRi.cjs +296 -0
  41. package/dist/appPorts-IW-OZmRi.cjs.map +1 -0
  42. package/dist/apps-C27qrbEe.cjs +5174 -0
  43. package/dist/apps-C27qrbEe.cjs.map +1 -0
  44. package/dist/apps-D2oTQasd.mjs +4650 -0
  45. package/dist/apps-D2oTQasd.mjs.map +1 -0
  46. package/dist/aws-BXfiWNbi.cjs +108 -0
  47. package/dist/aws-BXfiWNbi.cjs.map +1 -0
  48. package/dist/aws-BjvSTTcE.mjs +97 -0
  49. package/dist/aws-BjvSTTcE.mjs.map +1 -0
  50. package/dist/awsStore-BYYCmXiq.mjs +121 -0
  51. package/dist/awsStore-BYYCmXiq.mjs.map +1 -0
  52. package/dist/awsStore-DKQUElJL.cjs +138 -0
  53. package/dist/awsStore-DKQUElJL.cjs.map +1 -0
  54. package/dist/{backup-provisioner-DIVCbfee.mjs → backup-provisioner-C8DnCmxK.mjs} +2 -2
  55. package/dist/backup-provisioner-C8DnCmxK.mjs.map +1 -0
  56. package/dist/{backup-provisioner-BmhIO_Yr.cjs → backup-provisioner-oDEsPj02.cjs} +2 -2
  57. package/dist/backup-provisioner-oDEsPj02.cjs.map +1 -0
  58. package/dist/backups/runner.cjs +519 -0
  59. package/dist/backups/runner.cjs.map +1 -0
  60. package/dist/backups/runner.d.cts +102 -0
  61. package/dist/backups/runner.d.cts.map +1 -0
  62. package/dist/backups/runner.d.mts +102 -0
  63. package/dist/backups/runner.d.mts.map +1 -0
  64. package/dist/backups/runner.mjs +506 -0
  65. package/dist/backups/runner.mjs.map +1 -0
  66. package/dist/{bundler-mwH7WOb1.mjs → bundler-CbT4y4H_.mjs} +68 -15
  67. package/dist/bundler-CbT4y4H_.mjs.map +1 -0
  68. package/dist/{bundler-mjqGAvu1.cjs → bundler-DGeOugof.cjs} +67 -14
  69. package/dist/bundler-DGeOugof.cjs.map +1 -0
  70. package/dist/cli-C-jUNT69.cjs +80 -0
  71. package/dist/cli-C-jUNT69.cjs.map +1 -0
  72. package/dist/cli-DKEJryS7.mjs +80 -0
  73. package/dist/cli-DKEJryS7.mjs.map +1 -0
  74. package/dist/clientTelemetry-BAwj6MOf.d.cts +10 -0
  75. package/dist/clientTelemetry-BAwj6MOf.d.cts.map +1 -0
  76. package/dist/clientTelemetry-CvamPJj_.d.mts +10 -0
  77. package/dist/clientTelemetry-CvamPJj_.d.mts.map +1 -0
  78. package/dist/compose-BpnSP2x7.mjs +2434 -0
  79. package/dist/compose-BpnSP2x7.mjs.map +1 -0
  80. package/dist/compose-DJAaJEqL.cjs +2925 -0
  81. package/dist/compose-DJAaJEqL.cjs.map +1 -0
  82. package/dist/compose-DmtR2f0l.cjs +3564 -0
  83. package/dist/compose-DmtR2f0l.cjs.map +1 -0
  84. package/dist/compose-Glqs13is.mjs +3451 -0
  85. package/dist/compose-Glqs13is.mjs.map +1 -0
  86. package/dist/config-BODxZemw.d.mts +291 -0
  87. package/dist/config-BODxZemw.d.mts.map +1 -0
  88. package/dist/config-C3U5HulX.d.cts +291 -0
  89. package/dist/config-C3U5HulX.d.cts.map +1 -0
  90. package/dist/config.cjs +457 -9
  91. package/dist/config.cjs.map +1 -0
  92. package/dist/config.d.cts +4 -117
  93. package/dist/config.d.mts +4 -117
  94. package/dist/config.mjs +441 -3
  95. package/dist/config.mjs.map +1 -0
  96. package/dist/credentialSchemas-D_85KW2k.mjs +236 -0
  97. package/dist/credentialSchemas-D_85KW2k.mjs.map +1 -0
  98. package/dist/credentialSchemas-DjK6xKMk.cjs +271 -0
  99. package/dist/credentialSchemas-DjK6xKMk.cjs.map +1 -0
  100. package/dist/databases-CV22HzrI.mjs +588 -0
  101. package/dist/databases-CV22HzrI.mjs.map +1 -0
  102. package/dist/databases-DwYYH2mX.cjs +703 -0
  103. package/dist/databases-DwYYH2mX.cjs.map +1 -0
  104. package/dist/dbTunnel-DUudiQWj.cjs +154 -0
  105. package/dist/dbTunnel-DUudiQWj.cjs.map +1 -0
  106. package/dist/dbTunnel-KgbAh2v1.mjs +154 -0
  107. package/dist/dbTunnel-KgbAh2v1.mjs.map +1 -0
  108. package/dist/define-BfrNaY82.mjs +106 -0
  109. package/dist/define-BfrNaY82.mjs.map +1 -0
  110. package/dist/define-zKgLY65H.cjs +153 -0
  111. package/dist/define-zKgLY65H.cjs.map +1 -0
  112. package/dist/deploy/public.cjs +211 -0
  113. package/dist/deploy/public.cjs.map +1 -0
  114. package/dist/deploy/public.d.cts +659 -0
  115. package/dist/deploy/public.d.cts.map +1 -0
  116. package/dist/deploy/public.d.mts +659 -0
  117. package/dist/deploy/public.d.mts.map +1 -0
  118. package/dist/deploy/public.mjs +144 -0
  119. package/dist/deploy/public.mjs.map +1 -0
  120. package/dist/deploy/sniffer-envparser-worker.cjs +54 -0
  121. package/dist/deploy/sniffer-envparser-worker.cjs.map +1 -0
  122. package/dist/deploy/sniffer-envparser-worker.d.cts +1 -0
  123. package/dist/deploy/sniffer-envparser-worker.d.mts +1 -0
  124. package/dist/deploy/sniffer-envparser-worker.mjs +55 -0
  125. package/dist/deploy/sniffer-envparser-worker.mjs.map +1 -0
  126. package/dist/deploy/sniffer-hooks.cjs +1 -1
  127. package/dist/deploy/sniffer-hooks.mjs +1 -1
  128. package/dist/deploy/sniffer-loader.cjs +2 -2
  129. package/dist/deploy/sniffer-loader.mjs +1 -1
  130. package/dist/deploy/sniffer-routes-worker.cjs +2 -2
  131. package/dist/deploy/sniffer-routes-worker.mjs +1 -1
  132. package/dist/deploy-UkAiPzTp.mjs +3838 -0
  133. package/dist/deploy-UkAiPzTp.mjs.map +1 -0
  134. package/dist/deploy-ycRCutW9.cjs +3894 -0
  135. package/dist/deploy-ycRCutW9.cjs.map +1 -0
  136. package/dist/destroy-Cq5Un0kf.mjs +789 -0
  137. package/dist/destroy-Cq5Un0kf.mjs.map +1 -0
  138. package/dist/destroy-DzRzQcAR.cjs +790 -0
  139. package/dist/destroy-DzRzQcAR.cjs.map +1 -0
  140. package/dist/discover-Dfmn6HQ7.mjs +940 -0
  141. package/dist/discover-Dfmn6HQ7.mjs.map +1 -0
  142. package/dist/discover-OXczlq08.cjs +1085 -0
  143. package/dist/discover-OXczlq08.cjs.map +1 -0
  144. package/dist/dns-7zc-Mc9k.cjs +2257 -0
  145. package/dist/dns-7zc-Mc9k.cjs.map +1 -0
  146. package/dist/dns-dl7WUWmB.mjs +1820 -0
  147. package/dist/dns-dl7WUWmB.mjs.map +1 -0
  148. package/dist/docker-BDqp9Pfn.cjs +1798 -0
  149. package/dist/docker-BDqp9Pfn.cjs.map +1 -0
  150. package/dist/docker-MjMWQSEN.mjs +1649 -0
  151. package/dist/docker-MjMWQSEN.mjs.map +1 -0
  152. package/dist/dokploy-B0xtYCzY.mjs +38 -0
  153. package/dist/dokploy-B0xtYCzY.mjs.map +1 -0
  154. package/dist/dokploy-D-pBRnSV.cjs +38 -0
  155. package/dist/dokploy-D-pBRnSV.cjs.map +1 -0
  156. package/dist/drivers-BQRb3KsL.mjs +294 -0
  157. package/dist/drivers-BQRb3KsL.mjs.map +1 -0
  158. package/dist/drivers-DP7__dJX.cjs +377 -0
  159. package/dist/drivers-DP7__dJX.cjs.map +1 -0
  160. package/dist/eas-9danFNrJ.mjs +334 -0
  161. package/dist/eas-9danFNrJ.mjs.map +1 -0
  162. package/dist/eas-BJRA27vb.cjs +337 -0
  163. package/dist/eas-BJRA27vb.cjs.map +1 -0
  164. package/dist/emit-C4KSXOeS.mjs +153 -0
  165. package/dist/emit-C4KSXOeS.mjs.map +1 -0
  166. package/dist/emit-DiW0kbue.cjs +164 -0
  167. package/dist/emit-DiW0kbue.cjs.map +1 -0
  168. package/dist/encryption-0IiNCA3O.cjs +90 -0
  169. package/dist/encryption-0IiNCA3O.cjs.map +1 -0
  170. package/dist/encryption-ZDhvgGvu.mjs +89 -0
  171. package/dist/encryption-ZDhvgGvu.mjs.map +1 -0
  172. package/dist/engine-Csnr6XDu.mjs +3217 -0
  173. package/dist/engine-Csnr6XDu.mjs.map +1 -0
  174. package/dist/engine-DpjIgsGn.cjs +3330 -0
  175. package/dist/engine-DpjIgsGn.cjs.map +1 -0
  176. package/dist/errors-C9uIyIDt.mjs +27 -0
  177. package/dist/errors-C9uIyIDt.mjs.map +1 -0
  178. package/dist/errors-D1x8duqI.cjs +38 -0
  179. package/dist/errors-D1x8duqI.cjs.map +1 -0
  180. package/dist/github-Dej8EWxH.mjs +986 -0
  181. package/dist/github-Dej8EWxH.mjs.map +1 -0
  182. package/dist/github-HHxVur1m.cjs +987 -0
  183. package/dist/github-HHxVur1m.cjs.map +1 -0
  184. package/dist/googlePlay-DNrD-67X.mjs +931 -0
  185. package/dist/googlePlay-DNrD-67X.mjs.map +1 -0
  186. package/dist/googlePlay-NK1zgJJm.cjs +931 -0
  187. package/dist/googlePlay-NK1zgJJm.cjs.map +1 -0
  188. package/dist/iam-BzFyFf7T.mjs +442 -0
  189. package/dist/iam-BzFyFf7T.mjs.map +1 -0
  190. package/dist/iam-WIoKnLBp.cjs +521 -0
  191. package/dist/iam-WIoKnLBp.cjs.map +1 -0
  192. package/dist/{index-RCUizGxL.d.cts → index-BKgOlfK2.d.mts} +38 -14
  193. package/dist/index-BKgOlfK2.d.mts.map +1 -0
  194. package/dist/{index-B4H4XF7A.d.mts → index-zPzigXh-.d.cts} +38 -14
  195. package/dist/index-zPzigXh-.d.cts.map +1 -0
  196. package/dist/index.cjs +14502 -12767
  197. package/dist/index.cjs.map +1 -1
  198. package/dist/index.mjs +15137 -13400
  199. package/dist/index.mjs.map +1 -1
  200. package/dist/local-BW_VIsx0.cjs +241 -0
  201. package/dist/local-BW_VIsx0.cjs.map +1 -0
  202. package/dist/local-CVp-4wDb.mjs +224 -0
  203. package/dist/local-CVp-4wDb.mjs.map +1 -0
  204. package/dist/migrate-B8fq5egU.cjs +272 -0
  205. package/dist/migrate-B8fq5egU.cjs.map +1 -0
  206. package/dist/migrate-C8yCZ5P3.mjs +181 -0
  207. package/dist/migrate-C8yCZ5P3.mjs.map +1 -0
  208. package/dist/migrate-CkSq2f7k.mjs +267 -0
  209. package/dist/migrate-CkSq2f7k.mjs.map +1 -0
  210. package/dist/migrate-FOc2erAl.cjs +181 -0
  211. package/dist/migrate-FOc2erAl.cjs.map +1 -0
  212. package/dist/next.cjs +59 -0
  213. package/dist/next.cjs.map +1 -0
  214. package/dist/next.d.cts +44 -0
  215. package/dist/next.d.cts.map +1 -0
  216. package/dist/next.d.mts +44 -0
  217. package/dist/next.d.mts.map +1 -0
  218. package/dist/next.mjs +58 -0
  219. package/dist/next.mjs.map +1 -0
  220. package/dist/notes--JQyDHim.cjs +510 -0
  221. package/dist/notes--JQyDHim.cjs.map +1 -0
  222. package/dist/notes-DXl9qERh.mjs +409 -0
  223. package/dist/notes-DXl9qERh.mjs.map +1 -0
  224. package/dist/openapi.cjs +213 -7
  225. package/dist/openapi.cjs.map +1 -0
  226. package/dist/openapi.d.cts +27 -8
  227. package/dist/openapi.d.cts.map +1 -1
  228. package/dist/openapi.d.mts +27 -8
  229. package/dist/openapi.d.mts.map +1 -1
  230. package/dist/openapi.mjs +208 -2
  231. package/dist/openapi.mjs.map +1 -0
  232. package/dist/projectBucket-CGpcWqyY.cjs +263 -0
  233. package/dist/projectBucket-CGpcWqyY.cjs.map +1 -0
  234. package/dist/projectBucket-TigJy25c.mjs +222 -0
  235. package/dist/projectBucket-TigJy25c.mjs.map +1 -0
  236. package/dist/provider-BvjDbsTR.mjs +46 -0
  237. package/dist/provider-BvjDbsTR.mjs.map +1 -0
  238. package/dist/provider-DLhgo-mB.cjs +57 -0
  239. package/dist/provider-DLhgo-mB.cjs.map +1 -0
  240. package/dist/publish-BPfW3DWi.mjs +123 -0
  241. package/dist/publish-BPfW3DWi.mjs.map +1 -0
  242. package/dist/publish-D4pC6_G0.cjs +124 -0
  243. package/dist/publish-D4pC6_G0.cjs.map +1 -0
  244. package/dist/ready-BcV28QoW.mjs +375 -0
  245. package/dist/ready-BcV28QoW.mjs.map +1 -0
  246. package/dist/ready-ByQvw4-W.cjs +404 -0
  247. package/dist/ready-ByQvw4-W.cjs.map +1 -0
  248. package/dist/reconcile/public.cjs +3 -5
  249. package/dist/reconcile/public.d.cts +33 -89
  250. package/dist/reconcile/public.d.cts.map +1 -1
  251. package/dist/reconcile/public.d.mts +33 -89
  252. package/dist/reconcile/public.d.mts.map +1 -1
  253. package/dist/reconcile/public.mjs +3 -3
  254. package/dist/reconcile--I7V4Klj.mjs +34 -0
  255. package/dist/reconcile--I7V4Klj.mjs.map +1 -0
  256. package/dist/reconcile-CuCQBa5-.cjs +34 -0
  257. package/dist/reconcile-CuCQBa5-.cjs.map +1 -0
  258. package/dist/resolve-BmBR1vBr.cjs +316 -0
  259. package/dist/resolve-BmBR1vBr.cjs.map +1 -0
  260. package/dist/resolve-DA1kORng.mjs +263 -0
  261. package/dist/resolve-DA1kORng.mjs.map +1 -0
  262. package/dist/rollback-DlgQDX8m.mjs +136 -0
  263. package/dist/rollback-DlgQDX8m.mjs.map +1 -0
  264. package/dist/rollback-tsy4pyEp.cjs +165 -0
  265. package/dist/rollback-tsy4pyEp.cjs.map +1 -0
  266. package/dist/runtime-CaejlcZt.d.mts +82 -0
  267. package/dist/runtime-CaejlcZt.d.mts.map +1 -0
  268. package/dist/runtime-D3jD4Dvn.d.cts +82 -0
  269. package/dist/runtime-D3jD4Dvn.d.cts.map +1 -0
  270. package/dist/s3-BLEF-PQU.cjs +240 -0
  271. package/dist/s3-BLEF-PQU.cjs.map +1 -0
  272. package/dist/s3-DVYiOqWs.mjs +240 -0
  273. package/dist/s3-DVYiOqWs.mjs.map +1 -0
  274. package/dist/sandbox/config-worker.cjs +43 -0
  275. package/dist/sandbox/config-worker.cjs.map +1 -0
  276. package/dist/sandbox/config-worker.d.cts +1 -0
  277. package/dist/sandbox/config-worker.d.mts +1 -0
  278. package/dist/sandbox/config-worker.mjs +44 -0
  279. package/dist/sandbox/config-worker.mjs.map +1 -0
  280. package/dist/sandbox/credentials-worker.cjs +53 -0
  281. package/dist/sandbox/credentials-worker.cjs.map +1 -0
  282. package/dist/sandbox/credentials-worker.d.cts +1 -0
  283. package/dist/sandbox/credentials-worker.d.mts +1 -0
  284. package/dist/sandbox/credentials-worker.mjs +54 -0
  285. package/dist/sandbox/credentials-worker.mjs.map +1 -0
  286. package/dist/sandbox/discover-worker.cjs +47 -0
  287. package/dist/sandbox/discover-worker.cjs.map +1 -0
  288. package/dist/sandbox/discover-worker.d.cts +1 -0
  289. package/dist/sandbox/discover-worker.d.mts +1 -0
  290. package/dist/sandbox/discover-worker.mjs +48 -0
  291. package/dist/sandbox/discover-worker.mjs.map +1 -0
  292. package/dist/sandbox/migrate-worker.cjs +75 -0
  293. package/dist/sandbox/migrate-worker.cjs.map +1 -0
  294. package/dist/sandbox/migrate-worker.d.cts +1 -0
  295. package/dist/sandbox/migrate-worker.d.mts +1 -0
  296. package/dist/sandbox/migrate-worker.mjs +76 -0
  297. package/dist/sandbox/migrate-worker.mjs.map +1 -0
  298. package/dist/{workspace-CRD9YinV.cjs → schemas-BCwKKA42.mjs} +399 -1179
  299. package/dist/schemas-BCwKKA42.mjs.map +1 -0
  300. package/dist/{workspace-Bu3xNCej.mjs → schemas-BQ_v0lEX.cjs} +487 -982
  301. package/dist/schemas-BQ_v0lEX.cjs.map +1 -0
  302. package/dist/secretsManager-CjTo6CRq.mjs +113 -0
  303. package/dist/secretsManager-CjTo6CRq.mjs.map +1 -0
  304. package/dist/secretsManager-CvmBGjdM.cjs +124 -0
  305. package/dist/secretsManager-CvmBGjdM.cjs.map +1 -0
  306. package/dist/seeds-Bc3niNVb.cjs +382 -0
  307. package/dist/seeds-Bc3niNVb.cjs.map +1 -0
  308. package/dist/seeds-Ccn0Ru2T.mjs +299 -0
  309. package/dist/seeds-Ccn0Ru2T.mjs.map +1 -0
  310. package/dist/serverSetup-B_O65wLb.cjs +685 -0
  311. package/dist/serverSetup-B_O65wLb.cjs.map +1 -0
  312. package/dist/serverSetup-Dsy8drIb.mjs +685 -0
  313. package/dist/serverSetup-Dsy8drIb.mjs.map +1 -0
  314. package/dist/sniffer-Ckx4cr-o.cjs +1997 -0
  315. package/dist/sniffer-Ckx4cr-o.cjs.map +1 -0
  316. package/dist/sniffer-fBefNUuJ.mjs +1824 -0
  317. package/dist/sniffer-fBefNUuJ.mjs.map +1 -0
  318. package/dist/snsSubscriptions-BJ0LErGk.mjs +1010 -0
  319. package/dist/snsSubscriptions-BJ0LErGk.mjs.map +1 -0
  320. package/dist/snsSubscriptions-ChbFp-QP.cjs +1135 -0
  321. package/dist/snsSubscriptions-ChbFp-QP.cjs.map +1 -0
  322. package/dist/sst-BnuPeGyy.cjs +501 -0
  323. package/dist/sst-BnuPeGyy.cjs.map +1 -0
  324. package/dist/sst-Y7H_zaEZ.mjs +478 -0
  325. package/dist/sst-Y7H_zaEZ.mjs.map +1 -0
  326. package/dist/stack-BAipv5Js.cjs +1887 -0
  327. package/dist/stack-BAipv5Js.cjs.map +1 -0
  328. package/dist/stack-BHrGbsGA.mjs +1777 -0
  329. package/dist/stack-BHrGbsGA.mjs.map +1 -0
  330. package/dist/stage-BSZ9890H.mjs +303 -0
  331. package/dist/stage-BSZ9890H.mjs.map +1 -0
  332. package/dist/stage-D7vBtLXL.cjs +332 -0
  333. package/dist/stage-D7vBtLXL.cjs.map +1 -0
  334. package/dist/stages-BeSQQQ4z.cjs +190 -0
  335. package/dist/stages-BeSQQQ4z.cjs.map +1 -0
  336. package/dist/stages-DjFKQv08.mjs +190 -0
  337. package/dist/stages-DjFKQv08.mjs.map +1 -0
  338. package/dist/target/public.cjs +15 -0
  339. package/dist/target/public.d.cts +28 -0
  340. package/dist/target/public.d.cts.map +1 -0
  341. package/dist/target/public.d.mts +28 -0
  342. package/dist/target/public.d.mts.map +1 -0
  343. package/dist/target/public.mjs +4 -0
  344. package/dist/terminal-B7G-FtkD.cjs +85 -0
  345. package/dist/terminal-B7G-FtkD.cjs.map +1 -0
  346. package/dist/terminal-lp8RwHdX.mjs +85 -0
  347. package/dist/terminal-lp8RwHdX.mjs.map +1 -0
  348. package/dist/{types-7R81hu0i.d.mts → types-CLxsw-QY.d.cts} +2135 -428
  349. package/dist/types-CLxsw-QY.d.cts.map +1 -0
  350. package/dist/{types-N7c2O2m7.d.cts → types-wLlwkSib.d.mts} +2133 -428
  351. package/dist/types-wLlwkSib.d.mts.map +1 -0
  352. package/dist/utils-D2Nk1Nv2.cjs +205 -0
  353. package/dist/utils-D2Nk1Nv2.cjs.map +1 -0
  354. package/dist/utils-D_fxUqvU.mjs +156 -0
  355. package/dist/utils-D_fxUqvU.mjs.map +1 -0
  356. package/dist/vitest.cjs +65 -0
  357. package/dist/vitest.cjs.map +1 -0
  358. package/dist/vitest.d.cts +29 -0
  359. package/dist/vitest.d.cts.map +1 -0
  360. package/dist/vitest.d.mts +29 -0
  361. package/dist/vitest.d.mts.map +1 -0
  362. package/dist/vitest.mjs +65 -0
  363. package/dist/vitest.mjs.map +1 -0
  364. package/dist/workerRuntime-BXfhbe13.cjs +108 -0
  365. package/dist/workerRuntime-BXfhbe13.cjs.map +1 -0
  366. package/dist/workerRuntime-CsOyBRx2.mjs +79 -0
  367. package/dist/workerRuntime-CsOyBRx2.mjs.map +1 -0
  368. package/dist/workspace/index.cjs +6 -2
  369. package/dist/workspace/index.d.cts +3 -3
  370. package/dist/workspace/index.d.mts +3 -3
  371. package/dist/workspace/index.mjs +2 -2
  372. package/dist/workspace-DJjhfAGf.mjs +3027 -0
  373. package/dist/workspace-DJjhfAGf.mjs.map +1 -0
  374. package/dist/workspace-wTLnc1Ef.cjs +3577 -0
  375. package/dist/workspace-wTLnc1Ef.cjs.map +1 -0
  376. package/package.json +76 -13
  377. package/dist/HostingerProvider-BY26bWwB.mjs +0 -243
  378. package/dist/HostingerProvider-BY26bWwB.mjs.map +0 -1
  379. package/dist/HostingerProvider-BZFGYYVA.cjs +0 -243
  380. package/dist/HostingerProvider-BZFGYYVA.cjs.map +0 -1
  381. package/dist/LocalStateProvider-7HR6SS2t.cjs +0 -48
  382. package/dist/LocalStateProvider-7HR6SS2t.cjs.map +0 -1
  383. package/dist/LocalStateProvider-D7QyJoLM.mjs +0 -48
  384. package/dist/LocalStateProvider-D7QyJoLM.mjs.map +0 -1
  385. package/dist/Route53Provider-Cvj40A8I.mjs +0 -209
  386. package/dist/Route53Provider-Cvj40A8I.mjs.map +0 -1
  387. package/dist/Route53Provider-DVILBsvV.cjs +0 -209
  388. package/dist/Route53Provider-DVILBsvV.cjs.map +0 -1
  389. package/dist/SSMStateProvider-B0Hu1MKZ.mjs +0 -75
  390. package/dist/SSMStateProvider-B0Hu1MKZ.mjs.map +0 -1
  391. package/dist/SSMStateProvider-VrQ-yeqd.cjs +0 -74
  392. package/dist/SSMStateProvider-VrQ-yeqd.cjs.map +0 -1
  393. package/dist/backup-provisioner-BmhIO_Yr.cjs.map +0 -1
  394. package/dist/backup-provisioner-DIVCbfee.mjs.map +0 -1
  395. package/dist/bundler-mjqGAvu1.cjs.map +0 -1
  396. package/dist/bundler-mwH7WOb1.mjs.map +0 -1
  397. package/dist/config-DSXI480r.cjs +0 -467
  398. package/dist/config-DSXI480r.cjs.map +0 -1
  399. package/dist/config-DdKkoUE1.mjs +0 -414
  400. package/dist/config-DdKkoUE1.mjs.map +0 -1
  401. package/dist/config.d.cts.map +0 -1
  402. package/dist/config.d.mts.map +0 -1
  403. package/dist/credentials-C6Pfn6GY.cjs +0 -2939
  404. package/dist/credentials-C6Pfn6GY.cjs.map +0 -1
  405. package/dist/credentials-lbv-j0Be.mjs +0 -2802
  406. package/dist/credentials-lbv-j0Be.mjs.map +0 -1
  407. package/dist/discover-BERGFg8v.cjs +0 -288
  408. package/dist/discover-BERGFg8v.cjs.map +0 -1
  409. package/dist/discover-CK-n3w6b.mjs +0 -244
  410. package/dist/discover-CK-n3w6b.mjs.map +0 -1
  411. package/dist/emit-BdoPFjZf.cjs +0 -253
  412. package/dist/emit-BdoPFjZf.cjs.map +0 -1
  413. package/dist/emit-Bzq7JsMP.mjs +0 -224
  414. package/dist/emit-Bzq7JsMP.mjs.map +0 -1
  415. package/dist/generator-LfZU7NlU.mjs +0 -247
  416. package/dist/generator-LfZU7NlU.mjs.map +0 -1
  417. package/dist/generator-Wdfp0jCS.cjs +0 -282
  418. package/dist/generator-Wdfp0jCS.cjs.map +0 -1
  419. package/dist/github-DlIrXPee.mjs +0 -216
  420. package/dist/github-DlIrXPee.mjs.map +0 -1
  421. package/dist/github-n7N9yOff.cjs +0 -216
  422. package/dist/github-n7N9yOff.cjs.map +0 -1
  423. package/dist/index-B4H4XF7A.d.mts.map +0 -1
  424. package/dist/index-RCUizGxL.d.cts.map +0 -1
  425. package/dist/openapi-B8bu_OXN.cjs +0 -2038
  426. package/dist/openapi-B8bu_OXN.cjs.map +0 -1
  427. package/dist/openapi-DfjbhrsM.mjs +0 -1991
  428. package/dist/openapi-DfjbhrsM.mjs.map +0 -1
  429. package/dist/reconcile-Cq4cO83R.cjs +0 -136
  430. package/dist/reconcile-Cq4cO83R.cjs.map +0 -1
  431. package/dist/reconcile-fmoluZmZ.mjs +0 -113
  432. package/dist/reconcile-fmoluZmZ.mjs.map +0 -1
  433. package/dist/ssm-BKN1Cg4z.mjs +0 -60
  434. package/dist/ssm-BKN1Cg4z.mjs.map +0 -1
  435. package/dist/ssm-FxeSAt35.cjs +0 -60
  436. package/dist/ssm-FxeSAt35.cjs.map +0 -1
  437. package/dist/storage-DgypfSD6.cjs +0 -351
  438. package/dist/storage-DgypfSD6.cjs.map +0 -1
  439. package/dist/storage-TP0x118M.mjs +0 -304
  440. package/dist/storage-TP0x118M.mjs.map +0 -1
  441. package/dist/transfer-2aRVVJ6I.mjs +0 -122
  442. package/dist/transfer-2aRVVJ6I.mjs.map +0 -1
  443. package/dist/transfer-C3WZVmj_.cjs +0 -151
  444. package/dist/transfer-C3WZVmj_.cjs.map +0 -1
  445. package/dist/types-7R81hu0i.d.mts.map +0 -1
  446. package/dist/types-N7c2O2m7.d.cts.map +0 -1
  447. package/dist/workspace-Bu3xNCej.mjs.map +0 -1
  448. package/dist/workspace-CRD9YinV.cjs.map +0 -1
@@ -0,0 +1,1777 @@
1
+ import { t as GkmError } from "./errors-C9uIyIDt.mjs";
2
+ import { Y as imageRef, _t as gkmHome, et as stageTag, l as storedCredentials, n as findRootDomain, r as normalizeDnsConfig } from "./dns-dl7WUWmB.mjs";
3
+ import { B as LOGS_PORT, I as otlpTelemetryEnv, L as resolveStageTelemetry, Ot as certificateFor, Rt as isReservedStageKey, U as stageProvider, ht as servesOnCdn, kt as proxyFor, mt as s3Region, nt as bucketName, ot as appKey, ut as fileServerHost, z as telemetryEnv } from "./workspace-DJjhfAGf.mjs";
4
+ import { $ as runsServer, E as processorOriginHost, Et as signedOrigins, F as WORKER_PORT, M as PRERENDER_RUN_ARG, Mt as stageBackups, N as PROCESSOR_PORT, O as composeBuildPaths, P as TURBO_VERSION, Q as publicBuildValues, S as ORIGIN_VERIFY_HEADER, T as originSecretKey, X as OFFLINE_BUILD_ADDRESS, Z as offlineBuildHosts, _t as bucketPolicies, a as networkEnv, at as BACKUPS_SERVICE, gt as bucketLifecycles, it as workerUnits, j as LOCAL_CA_BUILD_SECRET, lt as backupsService, rt as processorUnits, s as processEnvKeys, ut as stackBackups, wt as localRolePassword } from "./apps-D2oTQasd.mjs";
5
+ import { $ as hostFor, C as redisService, Ct as stackLogs, Dt as isMainFrontendApp, F as stackTelemetry, G as EMULATOR_ACCESS_KEY_ID, H as minioWebhookEnv, L as telemetryOf, M as isTelemetryKey, N as scopeTelemetryEnv, Ot as resolveHost, R as usesTelemetry, S as STACK_CACHE, T as stackRedis, Tt as NoDomainForStage, W as watchedBuckets, Z as LOCAL_TLD, bt as logsPorts, et as hostsFor, g as postgresSuperuser, gt as LOGS_SERVICE, it as DEFAULT_IMAGES, k as planFor, n as composeFor, p as LOCAL_RABBITMQ_USER, st as portKeys, x as REDIS_SERVICE, xt as logsService, yt as logsOnPort } from "./compose-BpnSP2x7.mjs";
6
+ import { a as SNS_SUBSCRIPTIONS_KEY, c as INBOX_RELAY_TOKEN_KEY, d as inboxWebhookUrl, o as objectsRoute, s as subscriberRoute, u as inboxRelayWorker } from "./SubscriberGenerator-B3jHf26s.mjs";
7
+ import { d as DEFAULT_EVENTS } from "./drivers-BQRb3KsL.mjs";
8
+ import { _ as suppliedOnly, f as devServicesUsed, g as stageServiceDeclarations, i as stageProviderNotes, p as externalServices } from "./notes-DXl9qERh.mjs";
9
+ import { T as validateImageRef, o as processorDockerfile, r as appDockerfile, s as workerDockerfile } from "./docker-MjMWQSEN.mjs";
10
+ import { join } from "node:path";
11
+ import { createHash } from "node:crypto";
12
+ import { localAuthorityPaths } from "@geekmidas/edge/certificates/local";
13
+ import { CADDY_TLS_DIR, edgeCaddyfile } from "@geekmidas/edge/proxy/caddy";
14
+ import { EDGE_NETWORK, edgeAlias, edgeCertificatePaths, traefikDynamicFile } from "@geekmidas/edge/proxy/traefik";
15
+ import { EDGE_LIMITS, NOFILE, routeHosts } from "@geekmidas/edge/routes";
16
+ import { EDGE_TOKEN_KEY, WILDCARD_SUBDOMAIN, isWildcardSite, providedKeyFor, provisionOrder } from "@geekmidas/manifest";
17
+ import * as s3Url from "@geekmidas/storage/s3-url";
18
+ import bcrypt from "bcryptjs";
19
+ //#region src/providers/aws.ts
20
+ /**
21
+ * The AWS account a provider provisions in — the stage's, found the way the
22
+ * SSM and Secrets Manager stores find it.
23
+ *
24
+ * 1. `--profile`, resolved on its own: exported keys left over from another
25
+ * account never win over a profile someone named.
26
+ * 2. `AWS_PROFILE`, else `AWS_ACCESS_KEY_ID`/`AWS_SECRET_ACCESS_KEY` — the
27
+ * deploy's own `aws` credential kind (`storedCredentials`).
28
+ * 3. The SDK's default chain: `~/.aws` default profile, SSO, a role. In CI,
29
+ * whatever `aws-actions/configure-aws-credentials` exported.
30
+ *
31
+ * None of them: the provider has no provisioning credentials, and the stage
32
+ * is treated as `external`.
33
+ */
34
+ async function awsProvisioningCredentials(lookup) {
35
+ const region = lookup.env.AWS_REGION ?? lookup.env.AWS_DEFAULT_REGION;
36
+ const where = region ? { region } : {};
37
+ if (lookup.profile) return {
38
+ profile: lookup.profile,
39
+ ...where
40
+ };
41
+ const stored = await storedCredentials({
42
+ env: lookup.env,
43
+ ...lookup.home ? { home: lookup.home } : {}
44
+ }).get({
45
+ kind: "aws",
46
+ stage: lookup.stage
47
+ });
48
+ if (stored) return stored;
49
+ try {
50
+ const { fromNodeProviderChain } = await import("@aws-sdk/credential-providers");
51
+ await fromNodeProviderChain({
52
+ timeout: 1e3,
53
+ maxRetries: 0
54
+ })();
55
+ return {
56
+ chain: true,
57
+ ...where
58
+ };
59
+ } catch {
60
+ return;
61
+ }
62
+ }
63
+ /**
64
+ * An S3-compatible endpoint the environment points the SDK at — the AWS
65
+ * emulator in tests. The SDK reads it itself; it is read here too, because
66
+ * an emulator takes path-style requests, and a key written for one has to
67
+ * say where it is.
68
+ */
69
+ function awsEndpoint(env, service) {
70
+ return env[`AWS_ENDPOINT_URL_${service}`] ?? env.AWS_ENDPOINT_URL;
71
+ }
72
+ /** An SDK client's config for a provisioning credential. */
73
+ async function awsClientConfig(credential, region) {
74
+ if ("profile" in credential) {
75
+ const { fromIni } = await import("@aws-sdk/credential-providers");
76
+ return {
77
+ region,
78
+ credentials: fromIni({ profile: credential.profile })
79
+ };
80
+ }
81
+ if ("accessKeyId" in credential) return {
82
+ region,
83
+ credentials: {
84
+ accessKeyId: credential.accessKeyId,
85
+ secretAccessKey: credential.secretAccessKey,
86
+ ...credential.sessionToken ? { sessionToken: credential.sessionToken } : {}
87
+ }
88
+ };
89
+ return { region };
90
+ }
91
+ //#endregion
92
+ //#region src/providers/s3/plannedOrigin.ts
93
+ /**
94
+ * Where a bucket the `s3` provider is to create signs its links, before it
95
+ * has: the origin of the name and region its first deploy gives it.
96
+ *
97
+ * A site's image inlines its buckets' signed origins, and a protected stage's
98
+ * images are built on every push to the default branch, long before the
99
+ * release that first deploys the stage. The connection the origin is
100
+ * otherwise derived from (`signedOrigins`) is written by that deploy, so
101
+ * without this a stage that has never been deployed cannot be built, and a
102
+ * stage that cannot be built is never deployed.
103
+ */
104
+ /**
105
+ * `https://<bucket>.s3.<region>.amazonaws.com` for the bucket's good name.
106
+ *
107
+ * Nothing when it cannot be known ahead: against an S3 emulator
108
+ * (`AWS_ENDPOINT_URL`), or with no region to name. The first deploy names a
109
+ * bucket otherwise only when another account already holds the good name —
110
+ * a suffixed one, which it reports, and whose origin the next build inlines.
111
+ */
112
+ function plannedSignedOrigin(input, env = process.env) {
113
+ if (awsEndpoint(env, "S3")) return void 0;
114
+ let region;
115
+ try {
116
+ region = s3Region(input, env);
117
+ } catch {
118
+ return;
119
+ }
120
+ const bucket = bucketName({
121
+ scope: input.scope,
122
+ stage: input.stage,
123
+ id: appKey(input.bucket)
124
+ });
125
+ return s3Url.signedOrigin({
126
+ bucket,
127
+ region
128
+ });
129
+ }
130
+ //#endregion
131
+ //#region src/compose/sitePassword.ts
132
+ /**
133
+ * A site served behind a password on some deployed stages — a `StaticSite`'s
134
+ * `password`, naming a `RandomPassword` — so a staging build is not public
135
+ * while it is being tried.
136
+ *
137
+ * The edge asks for it with HTTP basic auth, before a request reaches the
138
+ * site: the browser prompts, and nothing of the site loads until the stage's
139
+ * login is given. The user is the stage's name; the password is the
140
+ * `RandomPassword`'s value on the stage, generated and kept like any other.
141
+ * Only its bcrypt hash reaches the edge's config.
142
+ *
143
+ * Pure.
144
+ */
145
+ /** A site's `password` names a `RandomPassword` the manifest does not hold. */
146
+ var SitePasswordNotDeclared = class extends GkmError {
147
+ site;
148
+ secret;
149
+ constructor(site, secret) {
150
+ 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}');`);
151
+ this.site = site;
152
+ this.secret = secret;
153
+ this.name = "SitePasswordNotDeclared";
154
+ }
155
+ };
156
+ /** A site's `password` names a stage the workspace does not deploy. */
157
+ var UnknownPasswordStage = class extends GkmError {
158
+ site;
159
+ stage;
160
+ deployed;
161
+ constructor(site, stage, deployed) {
162
+ 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.`);
163
+ this.site = site;
164
+ this.stage = stage;
165
+ this.deployed = deployed;
166
+ this.name = "UnknownPasswordStage";
167
+ }
168
+ };
169
+ /** A site behind a password, with none in the stage's secrets. */
170
+ var SitePasswordMissing = class extends GkmError {
171
+ stage;
172
+ key;
173
+ constructor(stage, key) {
174
+ 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}`);
175
+ this.stage = stage;
176
+ this.key = key;
177
+ this.name = "SitePasswordMissing";
178
+ }
179
+ };
180
+ /**
181
+ * A site behind a password on a stage it deploys through a target that cannot
182
+ * ask for a login. Refused rather than ignored: ignored, the site would be
183
+ * public while its construct says it is not.
184
+ */
185
+ var SitePasswordNeedsCompose = class extends GkmError {
186
+ site;
187
+ stage;
188
+ target;
189
+ constructor(site, stage, target) {
190
+ 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.`);
191
+ this.site = site;
192
+ this.stage = stage;
193
+ this.target = target;
194
+ this.name = "SitePasswordNeedsCompose";
195
+ }
196
+ };
197
+ /**
198
+ * The `RandomPassword` a site is served behind on `stage`, by its key —
199
+ * `SITE_PASSWORD` — or `undefined` where the stage asks for none.
200
+ *
201
+ * @throws {SitePasswordNotDeclared} where the password is not in the manifest
202
+ */
203
+ function sitePasswordKey(manifest, site, stage) {
204
+ const password = site.password;
205
+ if (!password?.stages.includes(stage)) return void 0;
206
+ const secret = manifest[password.secret];
207
+ const key = secret?.kind === "secret" ? secret.provides?.[0] : void 0;
208
+ if (!key) throw new SitePasswordNotDeclared(site.id, password.secret);
209
+ return key;
210
+ }
211
+ /**
212
+ * Before anything is deployed: every site behind a password names a deployed
213
+ * stage and a declared `RandomPassword`, and one of `apps` behind it on
214
+ * `stage` deploys through compose.
215
+ *
216
+ * @throws {UnknownPasswordStage}, {SitePasswordNotDeclared},
217
+ * {SitePasswordNeedsCompose}
218
+ */
219
+ function assertSitePasswords(workspace, manifest, stage, apps, target) {
220
+ for (const site of Object.values(manifest)) {
221
+ if (site.kind !== "site" || !site.password) continue;
222
+ for (const named of site.password.stages) if (!workspace.stages.deployed.includes(named)) throw new UnknownPasswordStage(site.id, named, workspace.stages.deployed);
223
+ if (sitePasswordKey(manifest, site, stage) && target !== "compose" && apps.includes(appKey(site.id))) throw new SitePasswordNeedsCompose(site.id, stage, target);
224
+ }
225
+ }
226
+ /**
227
+ * The login a site is served behind on `stage`, from the password kept under
228
+ * `key`.
229
+ *
230
+ * The hash's salt is derived from the password, so the same password always
231
+ * renders the same edge config: a deploy that changed nothing rewrites
232
+ * nothing, and the proxy is not reloaded for it. A per-hash random salt
233
+ * guards against a precomputed table of common passwords; a generated one is
234
+ * 43 random characters, which no table holds.
235
+ *
236
+ * @throws {SitePasswordMissing} where the stage's secrets hold none
237
+ */
238
+ function siteAuth(stage, key, custom) {
239
+ const password = custom[key];
240
+ if (!password) throw new SitePasswordMissing(stage, key);
241
+ return {
242
+ user: stage,
243
+ password,
244
+ hash: bcrypt.hashSync(password, saltFor(password)),
245
+ key
246
+ };
247
+ }
248
+ /** bcrypt's own base-64 alphabet, in which a salt is written. */
249
+ const BCRYPT_ALPHABET = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
250
+ /**
251
+ * A bcrypt salt — `$2a$`, which Caddy and Traefik both read, at cost 10 —
252
+ * derived from the password.
253
+ */
254
+ function saltFor(password) {
255
+ const digest = createHash("sha256").update(password).digest();
256
+ let salt = "";
257
+ for (let i = 0; i < 22; i++) salt += BCRYPT_ALPHABET[digest[i] % 64];
258
+ return `$2a$10$${salt}`;
259
+ }
260
+ //#endregion
261
+ //#region src/compose/stack.ts
262
+ /**
263
+ * The stack a workspace runs as for one stage — pure.
264
+ *
265
+ * Everything `gkm compose` writes is decided here, as data: the compose file,
266
+ * the Caddyfile, one env file per process that reads one — each backend,
267
+ * worker and site that runs a server — and the image each app runs. The
268
+ * command around it reads the workspace, asks the registry, writes the files
269
+ * and starts Docker; none of those decide anything, so all of it can be
270
+ * asserted without a daemon.
271
+ *
272
+ * The values come from the same derivations every other target uses. The
273
+ * plan is reconcile's `planFor`, the keys a process reads are
274
+ * `processEnvKeys` — the rule `gkm dev` and `gkm exec` apply — and every URL
275
+ * is `envFor`'s, with each app at its public address: a browser and a sibling
276
+ * service reach an API by the same name, through the edge.
277
+ */
278
+ /** Where a stack's files are written, relative to the workspace root. */
279
+ function stackDir(stage) {
280
+ return `.gkm/compose/${stage}`;
281
+ }
282
+ /**
283
+ * The compose project a stage's stack runs as.
284
+ *
285
+ * The deploy identity's scope, so two workspaces with one name in different
286
+ * namespaces never share containers or volumes — and the stage, so a
287
+ * machine can run two stages side by side.
288
+ */
289
+ function composeProject(identity) {
290
+ return `${identity.scope}-${identity.stage}`;
291
+ }
292
+ /** The ports the edge is published on, and the variables that move them. */
293
+ const EDGE_PORT_ENV = {
294
+ https: "GKM_COMPOSE_HTTPS_PORT",
295
+ http: "GKM_COMPOSE_HTTP_PORT"
296
+ };
297
+ /**
298
+ * The variable that moves the local stage's OpenObserve off its loopback
299
+ * port, 5080 — which the local stage takes from nowhere else, since it
300
+ * ignores `deploy.telemetry`. Another stack, or another tool, may hold 5080.
301
+ */
302
+ const LOGS_PORT_ENV = "GKM_COMPOSE_LOGS_PORT";
303
+ /**
304
+ * Containers this target does not run.
305
+ *
306
+ * The AWS emulator never applies: a stack is a server target, whose events
307
+ * are pg-boss. Reconcile's Caddy fronts `gkm dev`'s host processes; the stack
308
+ * brings its own edge.
309
+ *
310
+ * MinIO and Mailpit run on the local stage always, and on a deployed stage
311
+ * only where `--allow-dev-services` allowed them and its secrets configure no
312
+ * real bucket or mail server — see `devServices.ts`.
313
+ */
314
+ const NOT_RUN = {
315
+ localstack: true,
316
+ caddy: true
317
+ };
318
+ /** The kinds a deployed stage takes from its secrets, or a dev service. */
319
+ const SERVICE_KINDS = {
320
+ email: "email",
321
+ objects: "objects",
322
+ "file-server": "file-server"
323
+ };
324
+ /** The region MinIO is addressed with. It has no regions; the SDK wants one. */
325
+ const MINIO_REGION = "us-east-1";
326
+ /** The S3 client's credentials, read beside a bucket's URL when it has them. */
327
+ const STORAGE_KEYS = [
328
+ "AWS_ACCESS_KEY_ID",
329
+ "AWS_SECRET_ACCESS_KEY",
330
+ "AWS_REGION"
331
+ ];
332
+ /**
333
+ * Every service's Docker logs, rotated. The json-file driver keeps a
334
+ * container's output in one file that grows until the disk is full — on a
335
+ * small server, in weeks. Three files of 10 MB each per container is enough
336
+ * to see what happened and never fills anything. A project's own override
337
+ * file that sets `logging` wins over it.
338
+ */
339
+ const LOG_ROTATION = {
340
+ driver: "json-file",
341
+ options: {
342
+ "max-size": "10m",
343
+ "max-file": "3"
344
+ }
345
+ };
346
+ /** A CDN serves the bucket, and the secret it sends the processors is not in the stage. */
347
+ var ProcessorOriginSecretMissing = class extends GkmError {
348
+ fileServer;
349
+ key;
350
+ stage;
351
+ constructor(fileServer, key, stage) {
352
+ 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}.`);
353
+ this.fileServer = fileServer;
354
+ this.key = key;
355
+ this.stage = stage;
356
+ this.name = "ProcessorOriginSecretMissing";
357
+ }
358
+ };
359
+ /**
360
+ * The stack with Caddy's files inline: its Caddyfile and, where the stage has
361
+ * one, its own certificate — `configs` with their `content`, which compose
362
+ * copies into the container through the engine's API. Nothing is mounted from
363
+ * a path, so the stack runs the same on a server's engine, over SSH, as on
364
+ * this machine's. Their hash is a label: a changed file is a changed service,
365
+ * which `up` recreates (compose does not, for a config's content alone).
366
+ */
367
+ function withCaddyConfigs(compose, files) {
368
+ const caddy = compose.services.caddy;
369
+ if (!caddy) return compose;
370
+ const configs = {
371
+ caddyfile: { content: files.caddyfile },
372
+ ...files.tls ? {
373
+ "tls-cert": { content: files.tls.cert },
374
+ "tls-key": { content: files.tls.key }
375
+ } : {}
376
+ };
377
+ const hash = createHash("sha256");
378
+ for (const [name, { content }] of Object.entries(configs)) hash.update(`${name}\0${content}\0`);
379
+ return {
380
+ ...compose,
381
+ services: {
382
+ ...compose.services,
383
+ caddy: {
384
+ ...caddy,
385
+ configs: [{
386
+ source: "caddyfile",
387
+ target: "/etc/caddy/Caddyfile"
388
+ }, ...files.tls ? [{
389
+ source: "tls-cert",
390
+ target: `${CADDY_TLS_DIR}/cert.pem`
391
+ }, {
392
+ source: "tls-key",
393
+ target: `${CADDY_TLS_DIR}/key.pem`,
394
+ mode: 256
395
+ }] : []],
396
+ labels: {
397
+ ...caddy.labels,
398
+ "dev.geekmidas.caddy.config": hash.digest("hex").slice(0, 16)
399
+ }
400
+ }
401
+ },
402
+ configs: {
403
+ ...compose.configs,
404
+ ...configs
405
+ }
406
+ };
407
+ }
408
+ /** The label the local stage's Mailpit inbox answers on. */
409
+ const MAIL_INBOX_LABEL = "mail";
410
+ /** Mailpit's web UI and API, inside the stack's network. */
411
+ const MAILPIT_WEB_PORT = 8025;
412
+ /** An app of the local stage on the host its Mailpit inbox is served at. */
413
+ var MailInboxHostTaken = class extends GkmError {
414
+ host;
415
+ app;
416
+ constructor(host, app) {
417
+ 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.`);
418
+ this.host = host;
419
+ this.app = app;
420
+ this.name = "MailInboxHostTaken";
421
+ }
422
+ };
423
+ /**
424
+ * The services a stack publishes on its engine's loopback, and the port each
425
+ * answers on inside — what gkm reaches from this machine to provision the
426
+ * stack and run its migrations and seeds. Everything else is reached only on
427
+ * the stack's network.
428
+ */
429
+ const LOOPBACK_SERVICES = {
430
+ postgres: 5432,
431
+ minio: 9e3
432
+ };
433
+ /** The local stage's stack, without the logins `gkm dev` generates. */
434
+ var LocalCredentialsMissing = class extends GkmError {
435
+ stage;
436
+ constructor(stage) {
437
+ 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.`);
438
+ this.stage = stage;
439
+ this.name = "LocalCredentialsMissing";
440
+ }
441
+ };
442
+ /**
443
+ * A deployed stage's container logins, derived from its seed like its role
444
+ * passwords — so every deploy of the stage computes the same ones, and no one
445
+ * reading the repo can.
446
+ */
447
+ function derivedCredentials(project, plan, seed) {
448
+ const derive = (purpose) => localRolePassword(project, plan, purpose, seed);
449
+ return {
450
+ postgres: {
451
+ user: postgresSuperuser(project),
452
+ password: derive("master")
453
+ },
454
+ minio: {
455
+ user: `${project}-minio`,
456
+ password: derive("minio")
457
+ },
458
+ rabbitmq: {
459
+ user: LOCAL_RABBITMQ_USER,
460
+ password: derive("rabbitmq")
461
+ },
462
+ redis: { password: derive("redis") },
463
+ cacheToken: derive("cache-token"),
464
+ emulator: {
465
+ accessKeyId: EMULATOR_ACCESS_KEY_ID,
466
+ secretAccessKey: derive("emulator")
467
+ },
468
+ logs: {
469
+ email: `admin@${project}`,
470
+ password: derive("logs")
471
+ }
472
+ };
473
+ }
474
+ /** A value only the stage's secrets can hold, and they do not. */
475
+ var StageSecretMissing = class extends GkmError {
476
+ app;
477
+ key;
478
+ stage;
479
+ constructor(app, key, stage) {
480
+ 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}`);
481
+ this.app = app;
482
+ this.key = key;
483
+ this.stage = stage;
484
+ this.name = "StageSecretMissing";
485
+ }
486
+ };
487
+ /**
488
+ * One key of a deployed inbox — the one rule every target reads it by.
489
+ *
490
+ * Its domain is the stage's, which mail is addressed to. Everything else (where
491
+ * its raw messages are read, its topic's publisher string) is what its
492
+ * provider made and wrote to the stage's secrets; nothing can derive it.
493
+ *
494
+ * @throws {NoDomainForStage} for its domain when the stage has none.
495
+ * @throws {StageSecretMissing} when the provider has not written the key.
496
+ */
497
+ function deployedInboxValue(inbox, key, sources) {
498
+ if (key === providedKeyFor(inbox, "inbox", "domain")) {
499
+ if (!sources.domain) throw new NoDomainForStage(sources.stage);
500
+ return sources.domain;
501
+ }
502
+ const value = sources.secrets[key];
503
+ if (value === void 0) throw new StageSecretMissing(sources.reader, key, sources.stage);
504
+ return value;
505
+ }
506
+ /**
507
+ * Every deployed inbox's keys, and its topic's publisher string, by key: what
508
+ * a target that provisions nothing of the inbox's (SST) is handed, read by
509
+ * {@link deployedInboxValue} as the compose stack reads each.
510
+ */
511
+ function deployedInboxEnv(manifest, sources) {
512
+ const env = {};
513
+ for (const declaration of Object.values(manifest)) {
514
+ if (declaration.kind !== "inbox") continue;
515
+ const keys = [...declaration.provides ?? [], providedKeyFor(declaration.topic, "topic", "publisherConnectionString")];
516
+ for (const key of keys) env[key] = deployedInboxValue(declaration.id, key, sources);
517
+ }
518
+ return env;
519
+ }
520
+ /** A deployed stage's secrets with no seed to derive its passwords from. */
521
+ var StageSeedMissing = class extends GkmError {
522
+ stage;
523
+ constructor(stage) {
524
+ 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.`);
525
+ this.stage = stage;
526
+ this.name = "StageSeedMissing";
527
+ }
528
+ };
529
+ /** A workspace with no API and no site to run. */
530
+ var NothingToCompose = class extends GkmError {
531
+ root;
532
+ constructor(root) {
533
+ 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.`);
534
+ this.root = root;
535
+ this.name = "NothingToCompose";
536
+ }
537
+ };
538
+ /** A value that cannot be written to an env file a line at a time. */
539
+ var EnvValueMultiline = class extends GkmError {
540
+ app;
541
+ key;
542
+ constructor(app, key) {
543
+ 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.`);
544
+ this.app = app;
545
+ this.key = key;
546
+ this.name = "EnvValueMultiline";
547
+ }
548
+ };
549
+ /** The services a stack's apps wait on. */
550
+ const HEALTHY = { condition: "service_healthy" };
551
+ /**
552
+ * What Caddy waits on of each app: that it started, never that it is
553
+ * healthy. Its routes are served whatever an app's health — Caddy's own
554
+ * upstream health checks take one out of rotation — so one app that never
555
+ * turns healthy leaves the others routed, and a site whose health check goes
556
+ * through the edge can turn healthy at all.
557
+ */
558
+ const STARTED = { condition: "service_started" };
559
+ /**
560
+ * An app's health check: its own server, asked on 127.0.0.1 — not
561
+ * `localhost`, which resolves to `::1` first in an Alpine container while a
562
+ * server may listen on IPv4 alone.
563
+ */
564
+ function probe(port, path) {
565
+ return {
566
+ test: [
567
+ "CMD",
568
+ "wget",
569
+ "-q",
570
+ "-O",
571
+ "/dev/null",
572
+ `http://127.0.0.1:${port}${path}`
573
+ ],
574
+ interval: "5s",
575
+ timeout: "3s",
576
+ retries: 20,
577
+ start_period: "10s"
578
+ };
579
+ }
580
+ /**
581
+ * What a stage's stack provisions: reconcile's plan, with a server target's
582
+ * backends whatever `deploy.default` says — the stack is one machine running
583
+ * containers, so events are pg-boss beside the declared database, and every
584
+ * cache, one declared from that database included, is in the stack's own
585
+ * Redis.
586
+ */
587
+ function stackPlan(workspace, manifest, stage) {
588
+ const protectedSubdomains = [...workspace.protectedSubdomains ?? [], ...nestedStageLabels(workspace.domains, stage)];
589
+ return planFor(manifest, stage, provisionOrder(manifest), {
590
+ localStage: workspace.stages.local,
591
+ ...protectedSubdomains.length > 0 ? { protectedSubdomains } : {},
592
+ events: DEFAULT_EVENTS.server,
593
+ cache: STACK_CACHE,
594
+ edge: false
595
+ });
596
+ }
597
+ /** The stack for one stage. */
598
+ function composeStack(input) {
599
+ const { workspace, manifest, stage, identity } = input;
600
+ const local = stage === workspace.stages.local;
601
+ const project = composeProject(identity);
602
+ const custom = input.secrets?.custom ?? {};
603
+ const https = input.ports?.https ?? 443;
604
+ const http = input.ports?.http ?? 80;
605
+ const proxy = proxyFor(workspace.deploy?.compose, stage, local);
606
+ const certificate = certificateFor(workspace.deploy?.compose, stage, workspace.root);
607
+ const plan = stackPlan(workspace, manifest, stage);
608
+ const byId = new Map(plan.resources.map((r) => [r.id, r]));
609
+ if (local && !input.localCredentials) throw new LocalCredentialsMissing(stage);
610
+ const seed = local ? input.localCredentials.seed : input.secrets?.seed;
611
+ if (!seed) throw new StageSeedMissing(stage);
612
+ const containers = local ? input.localCredentials : derivedCredentials(workspace.name, plan, seed);
613
+ const credential = {
614
+ containers: {
615
+ ...containers,
616
+ minio: {
617
+ user: custom.AWS_ACCESS_KEY_ID ?? containers.minio.user,
618
+ password: custom.AWS_SECRET_ACCESS_KEY ?? containers.minio.password
619
+ }
620
+ },
621
+ seed
622
+ };
623
+ const apps = stackApps(workspace, manifest, plan, {
624
+ local,
625
+ stage,
626
+ https,
627
+ identity,
628
+ images: input.images
629
+ });
630
+ const workers = stackWorkers(workerUnits(workspace, manifest, input.background ?? {}), {
631
+ stage,
632
+ identity,
633
+ images: input.images
634
+ });
635
+ const processors = stackProcessors(processorUnits(workspace, manifest), {
636
+ manifest,
637
+ stage,
638
+ identity,
639
+ images: input.images
640
+ });
641
+ if (apps.length === 0 && workers.length === 0 && processors.length === 0) throw new NothingToCompose(workspace.root);
642
+ const owners = /* @__PURE__ */ new Map();
643
+ for (const resource of plan.resources) {
644
+ owners.set(resource.envKey, resource);
645
+ if (resource.kind === "email") {
646
+ owners.set(providedKeyFor(resource.id, resource.kind, "from"), resource);
647
+ owners.set(providedKeyFor(resource.id, resource.kind, "inboxUrl"), resource);
648
+ }
649
+ if (resource.kind === "objects") owners.set(providedKeyFor(resource.id, resource.kind, "signedOrigin"), resource);
650
+ if (resource.kind === "external-api") owners.set(providedKeyFor(resource.id, resource.kind, "credentials"), resource);
651
+ if (resource.kind === "inbox") owners.set(providedKeyFor(resource.id, resource.kind, "domain"), resource);
652
+ if (resource.kind === "websocket-api") owners.set(providedKeyFor(resource.id, resource.kind, "publisherConnectionString"), resource);
653
+ }
654
+ const domain = workspace.domains?.[stage];
655
+ const telemetry = resolveStageTelemetry({
656
+ ...workspace.deploy?.telemetry ? { telemetry: workspace.deploy.telemetry } : {},
657
+ stage,
658
+ local,
659
+ target: "compose",
660
+ runtime: "server",
661
+ selfHosted: true,
662
+ used: usesTelemetry(manifest)
663
+ });
664
+ const logsBase = telemetry?.provider === "self-hosted" ? stackLogs({
665
+ config: local && input.ports?.logs ? {
666
+ ...telemetry.selfHosted,
667
+ port: input.ports.logs
668
+ } : telemetry.selfHosted,
669
+ stage,
670
+ local,
671
+ project: workspace.name,
672
+ ...domain ? { domain } : {},
673
+ telemetry: stackTelemetry(manifest),
674
+ custom,
675
+ https,
676
+ ...local ? { localLogin: input.localCredentials.logs } : {}
677
+ }) : void 0;
678
+ const services = local ? {
679
+ missing: [],
680
+ minio: plan.resources.filter((r) => r.kind === "objects").map((r) => r.id),
681
+ mailpit: plan.resources.filter((r) => r.kind === "email" || r.kind === "inbox").map((r) => r.id)
682
+ } : externalServices({
683
+ stage,
684
+ declarations: stageServiceDeclarations({ manifest }),
685
+ supplied: custom,
686
+ allow: input.allowDevServices === true,
687
+ ...domain ? { domain } : {},
688
+ providers: stageProviderNotes(workspace, stage)
689
+ });
690
+ const redis = stackRedis({
691
+ plan,
692
+ stage,
693
+ local,
694
+ custom,
695
+ ...local ? { localPassword: input.localCredentials.redis.password } : {}
696
+ });
697
+ const infra = [...plan.containers.filter((c) => !NOT_RUN[c]).filter((c) => c !== 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 ? [LOGS_SERVICE] : []].sort();
698
+ const mailInbox = local && infra.includes("mailpit") ? (() => {
699
+ const host = [
700
+ MAIL_INBOX_LABEL,
701
+ workspace.name,
702
+ LOCAL_TLD
703
+ ].filter(Boolean).join(".");
704
+ return {
705
+ host,
706
+ url: `https://${host}${https !== 443 ? `:${https}` : ""}`
707
+ };
708
+ })() : void 0;
709
+ const storage = infra.includes("minio") ? (() => {
710
+ const buckets = services.minio.map((id) => byId.get(id)?.name).filter((name) => Boolean(name)).sort();
711
+ return {
712
+ ...credential.containers.minio,
713
+ buckets,
714
+ policies: bucketPolicies(plan).filter((p) => buckets.includes(p.bucket)),
715
+ objects: services.minio.map((id) => ({
716
+ id,
717
+ name: byId.get(id)?.name
718
+ })).filter((b) => Boolean(b.name)).sort((a, b) => a.name.localeCompare(b.name)),
719
+ webhooks: [],
720
+ lifecycles: bucketLifecycles(plan).filter((l) => buckets.includes(l.bucket))
721
+ };
722
+ })() : void 0;
723
+ const bucketEventKeys = /* @__PURE__ */ new Map();
724
+ for (const resource of plan.resources) {
725
+ if (resource.kind !== "objects") continue;
726
+ bucketEventKeys.set(providedKeyFor(resource.id, resource.kind, "eventsConnectionString"), resource.id);
727
+ bucketEventKeys.set(providedKeyFor(resource.id, resource.kind, "eventsToken"), resource.id);
728
+ }
729
+ const fileServers = /* @__PURE__ */ new Map();
730
+ if (storage) for (const resource of plan.resources) {
731
+ if (resource.kind !== "file-server" || !resource.of) continue;
732
+ if (!services.minio.includes(resource.of)) continue;
733
+ if (custom[resource.envKey] !== void 0) continue;
734
+ const bucket = byId.get(resource.of);
735
+ if (!bucket) continue;
736
+ let host;
737
+ if (local) host = hostFor(resource, workspace.name);
738
+ else {
739
+ if (!domain) throw new NoDomainForStage(stage);
740
+ host = fileServerHost(resource.id, domain);
741
+ }
742
+ fileServers.set(resource.id, {
743
+ url: `https://${host}${local && https !== 443 ? `:${https}` : ""}`,
744
+ route: {
745
+ name: `files-${appKey(resource.id)}`,
746
+ host,
747
+ upstreams: [{
748
+ service: "minio",
749
+ port: 9e3
750
+ }],
751
+ streaming: false,
752
+ prefix: `/${bucket.name}`
753
+ }
754
+ });
755
+ }
756
+ const warnings = [];
757
+ const objectsProvider = stageProvider(workspace, "objects", stage);
758
+ const onCdn = objectsProvider.mode === "provider" && objectsProvider.name === "s3" && servesOnCdn(objectsProvider.config);
759
+ const plannedOrigins = /* @__PURE__ */ new Map();
760
+ if (!local && objectsProvider.mode === "provider" && objectsProvider.name === "s3") for (const resource of plan.resources) {
761
+ if (resource.kind !== "objects") continue;
762
+ if (services.minio.includes(resource.id)) continue;
763
+ if (custom[providedKeyFor(resource.id, "objects", "connectionString")] !== void 0) continue;
764
+ const origin = plannedSignedOrigin({
765
+ workspace,
766
+ stage,
767
+ scope: identity.scope,
768
+ config: objectsProvider.config,
769
+ bucket: resource.id
770
+ });
771
+ if (origin) plannedOrigins.set(providedKeyFor(resource.id, "objects", "signedOrigin"), origin);
772
+ }
773
+ const fileServerUrls = /* @__PURE__ */ new Map();
774
+ for (const resource of plan.resources) {
775
+ if (resource.kind !== "file-server") continue;
776
+ const key = resource.envKey;
777
+ const stored = custom[key];
778
+ const inMinio = Boolean(resource.of && services.minio.includes(resource.of));
779
+ const derived = fileServers.get(resource.id)?.url ?? (!local && domain ? `https://${fileServerHost(resource.id, domain)}` : void 0);
780
+ if (onCdn && !inMinio && derived) {
781
+ fileServerUrls.set(resource.id, derived);
782
+ if (stored !== void 0 && stored !== derived) warnings.push(`${key} is stored as ${stored}, and '${resource.id}' answers on ${derived} — its CDN on the stage's domain. The stack is built and run with ${derived}; the deploy rewrites the stored copy.`);
783
+ continue;
784
+ }
785
+ if (stored !== void 0) {
786
+ fileServerUrls.set(resource.id, stored);
787
+ if ((inMinio || objectsProvider.mode === "external") && derived && stored !== derived) warnings.push(`${key} is set by hand to ${stored}, and kept. On the stage's domain '${resource.id}' would answer on ${derived}; if ${stored} is a previous domain's, set it again: gkm secrets:set ${key} '${derived}' --stage ${stage}`);
788
+ continue;
789
+ }
790
+ const served = fileServers.get(resource.id)?.url;
791
+ if (served) fileServerUrls.set(resource.id, served);
792
+ }
793
+ const edgeServices = new Set(proxy === "traefik" ? [
794
+ ...apps.flatMap(replicaNames),
795
+ ...fileServers.size > 0 ? ["minio"] : [],
796
+ ...logsBase?.host && logsBase.public ? [LOGS_SERVICE] : [],
797
+ ...mailInbox ? ["mailpit"] : []
798
+ ] : []);
799
+ const hostOf = (service) => edgeServices.has(service) ? edgeAlias(project, service) : service;
800
+ const logs = logsBase && {
801
+ ...logsBase,
802
+ appEnv: {
803
+ ...logsBase.appEnv,
804
+ OTEL_EXPORTER_OTLP_ENDPOINT: logsBase.appEnv.OTEL_EXPORTER_OTLP_ENDPOINT.replace(`//openobserve:`, `//${hostOf("openobserve")}:`)
805
+ }
806
+ };
807
+ const derivation = {
808
+ project: workspace.name,
809
+ credentials: credential.containers,
810
+ seed: credential.seed,
811
+ ...!local && domain ? { mailDomain: domain } : {},
812
+ relayedBuckets: [...watchedBuckets(manifest, input.subscribers ?? {}).keys()].filter((bucket) => services.minio.includes(bucket))
813
+ };
814
+ const publicAddresses = Object.fromEntries(apps.map((app) => [app.id, app.url]));
815
+ const aliasAddresses = Object.fromEntries(apps.map((app) => [app.id, (app.aliases ?? []).map((alias) => `https://${alias}${local && https !== 443 ? `:${https}` : ""}`)]));
816
+ const outside = networkEnv(plan, {
817
+ ...derivation,
818
+ addresses: publicAddresses,
819
+ aliasAddresses
820
+ }, hostOf);
821
+ /**
822
+ * What a key resolves to for one app, from the stage's secrets where only
823
+ * they can hold it, and the derivations otherwise.
824
+ */
825
+ const valueFor = (app, key, owner) => {
826
+ if (isReservedStageKey(key)) return void 0;
827
+ const watching = bucketEventKeys.get(key);
828
+ if (watching) {
829
+ if (custom[key] !== void 0) return custom[key];
830
+ return services.minio.includes(watching) ? outside[key] : void 0;
831
+ }
832
+ if (owner?.kind === "inbox") {
833
+ if (local) return outside[key];
834
+ return deployedInboxValue(owner.id, key, {
835
+ reader: app.name,
836
+ stage,
837
+ domain,
838
+ secrets: custom
839
+ });
840
+ }
841
+ if (!local && owner?.kind === "email" && key.endsWith("_INBOX_URL")) return;
842
+ if (owner && SERVICE_KINDS[owner.kind]) {
843
+ if (owner.kind === "file-server") return fileServerUrls.get(owner.id);
844
+ if (custom[key] !== void 0) return custom[key];
845
+ if (owner.kind === "objects") {
846
+ if (key === providedKeyFor(owner.id, owner.kind, "signedOrigin")) return signedOrigins([owner.id], (k) => valueFor(app, k, owner))[key];
847
+ if (!services.minio.includes(owner.id)) return void 0;
848
+ }
849
+ return outside[key];
850
+ }
851
+ if (owner && suppliedOnly(owner.kind, owner.id, key, local)) {
852
+ const value = custom[key];
853
+ if (value === void 0) throw new StageSecretMissing(app.name, key, stage);
854
+ return value;
855
+ }
856
+ if (custom[key] !== void 0) return custom[key];
857
+ if (owner?.kind === "cache") return redis?.urls[key];
858
+ if (owner?.kind === "websocket-api" && key === providedKeyFor(owner.id, owner.kind, "publisherConnectionString")) return redis?.urls[key];
859
+ return outside[key];
860
+ };
861
+ const telemetryValues = logs ? telemetryEnv({
862
+ endpoint: logs.appEnv.OTEL_EXPORTER_OTLP_ENDPOINT,
863
+ headers: logs.appEnv.OTEL_EXPORTER_OTLP_HEADERS
864
+ }, telemetry?.sampleRate ?? 1) : telemetry?.provider === "otlp" ? otlpTelemetryEnv(telemetry) : void 0;
865
+ /** Each key one backend process reads, resolved for this stage. */
866
+ const valuesFor = (app, keys) => {
867
+ const values = {};
868
+ for (const key of [...keys].sort()) {
869
+ if (isTelemetryKey(key)) continue;
870
+ const owner = owners.get(key) ?? storageOwner(key, plan);
871
+ if (STORAGE_KEYS.includes(key)) {
872
+ const value = custom[key] ?? storageValue(key, storage);
873
+ if (value !== void 0) values[key] = value;
874
+ continue;
875
+ }
876
+ const value = valueFor(app, key, owner);
877
+ if (value !== void 0) values[key] = value;
878
+ }
879
+ return values;
880
+ };
881
+ const stageKeys = Object.keys(custom);
882
+ for (const app of apps) {
883
+ const site = manifest[app.id];
884
+ if (site?.kind === "site") {
885
+ const args = publicBuildValues(site, manifest, (key) => valueFor(app, key, owners.get(key)) ?? plannedOrigins.get(key), custom, !local && app.build ? { requireFileOrigins: { stage } } : {});
886
+ if (app.prerender && input.prerenderRun) args[PRERENDER_RUN_ARG] = input.prerenderRun;
887
+ if (app.build && Object.keys(args).length > 0) app.build.args = args;
888
+ const offline = offlineBuildHosts(site, manifest, (key) => valueFor(app, key, owners.get(key)));
889
+ if (app.build && offline.length > 0) app.build.offlineHosts = offline;
890
+ if (!app.runtime) continue;
891
+ }
892
+ if (input.buildOnly) continue;
893
+ const values = valuesFor(app, processEnvKeys(manifest, { app: app.name }, stageKeys) ?? /* @__PURE__ */ new Set());
894
+ app.env = {
895
+ ...scopeTelemetryEnv(values, {
896
+ uses: app.kind !== "site" && telemetryOf(manifest, app.id) !== void 0,
897
+ serviceName: app.name,
898
+ ...telemetryValues ? { telemetry: telemetryValues } : {}
899
+ }),
900
+ NODE_ENV: "production",
901
+ PORT: String(app.port),
902
+ STAGE: stage
903
+ };
904
+ for (const [key, value] of Object.entries(app.env)) if (/[\r\n]/.test(value)) throw new EnvValueMultiline(app.name, key);
905
+ }
906
+ const mobileApps = [];
907
+ for (const declaration of Object.values(manifest)) {
908
+ if (declaration.kind !== "mobile-app") continue;
909
+ const app = {
910
+ name: appKey(declaration.id),
911
+ id: declaration.id,
912
+ kind: "site"
913
+ };
914
+ mobileApps.push({
915
+ name: app.name,
916
+ id: app.id,
917
+ values: publicBuildValues(declaration, manifest, (key) => valueFor(app, key, owners.get(key)) ?? plannedOrigins.get(key), custom)
918
+ });
919
+ }
920
+ for (const worker of input.buildOnly ? [] : workers) {
921
+ const keys = processEnvKeys(manifest, { workers: [worker.id] }, stageKeys) ?? /* @__PURE__ */ new Set();
922
+ const resolved = valuesFor({
923
+ name: worker.name,
924
+ id: worker.id,
925
+ kind: "rest-api"
926
+ }, keys);
927
+ const push = local ? void 0 : workerPush(worker, input.subscribers?.[worker.id] ?? [], resolved, {
928
+ stage,
929
+ ...domain ? { domain } : {}
930
+ });
931
+ if (push) {
932
+ worker.push = push;
933
+ if (proxy === "traefik") edgeServices.add(worker.name);
934
+ }
935
+ worker.env = {
936
+ ...scopeTelemetryEnv(resolved, {
937
+ uses: telemetryOf(manifest, worker.id) !== void 0,
938
+ serviceName: worker.name,
939
+ ...telemetryValues ? { telemetry: telemetryValues } : {}
940
+ }),
941
+ ...push && !input.recordingSubscriptions ? { [SNS_SUBSCRIPTIONS_KEY]: recordedSubscriptions(worker, push, input.pushSubscriptions?.[worker.id]) } : {},
942
+ NODE_ENV: "production",
943
+ PORT: String(worker.port),
944
+ STAGE: stage
945
+ };
946
+ for (const [key, value] of Object.entries(worker.env)) if (/[\r\n]/.test(value)) throw new EnvValueMultiline(worker.name, key);
947
+ }
948
+ for (const unit of processors) {
949
+ const served = fileServers.get(unit.id);
950
+ if (served) served.route = {
951
+ ...served.route,
952
+ handlers: [{
953
+ name: unit.name,
954
+ prefixes: unit.prefixes,
955
+ upstreams: [{
956
+ service: unit.name,
957
+ port: unit.port
958
+ }]
959
+ }]
960
+ };
961
+ else if (!local && !input.buildOnly) {
962
+ if (!domain) throw new NoDomainForStage(stage);
963
+ const key = originSecretKey(unit.id);
964
+ const secret = custom[key];
965
+ if (!secret) throw new ProcessorOriginSecretMissing(unit.id, key, stage);
966
+ unit.origin = {
967
+ host: processorOriginHost(unit.id, domain),
968
+ secret
969
+ };
970
+ }
971
+ if (proxy === "traefik" && (served || unit.origin)) edgeServices.add(unit.name);
972
+ if (input.buildOnly) continue;
973
+ const keys = processEnvKeys(manifest, { processors: [unit.id] }, stageKeys) ?? /* @__PURE__ */ new Set();
974
+ unit.env = {
975
+ ...scopeTelemetryEnv(valuesFor({
976
+ name: unit.name,
977
+ id: unit.id,
978
+ kind: "rest-api"
979
+ }, keys), {
980
+ uses: telemetryOf(manifest, unit.id) !== void 0,
981
+ serviceName: unit.name,
982
+ ...telemetryValues ? { telemetry: telemetryValues } : {}
983
+ }),
984
+ NODE_ENV: "production",
985
+ PORT: String(unit.port),
986
+ STAGE: stage
987
+ };
988
+ for (const [key, value] of Object.entries(unit.env)) if (/[\r\n]/.test(value)) throw new EnvValueMultiline(unit.name, key);
989
+ }
990
+ if (storage && !input.buildOnly) {
991
+ const watched = watchedBuckets(manifest, input.subscribers ?? {});
992
+ for (const [bucket, workerId] of watched) {
993
+ if (!services.minio.includes(bucket)) continue;
994
+ const worker = workers.find((w) => w.id === workerId);
995
+ const relay = worker?.env?.[providedKeyFor(bucket, "objects", "eventsConnectionString")];
996
+ const token = worker?.env?.[providedKeyFor(bucket, "objects", "eventsToken")];
997
+ if (!worker || !relay || relay.startsWith("sns:") || !token) continue;
998
+ storage.webhooks.push({
999
+ bucket,
1000
+ endpoint: `http://${hostOf(worker.name)}:${worker.port}${objectsRoute(bucket)}`,
1001
+ token
1002
+ });
1003
+ }
1004
+ }
1005
+ let inboxRelay;
1006
+ if (local && infra.includes("mailpit") && !input.buildOnly) {
1007
+ const relayId = inboxRelayWorker(manifest, input.subscribers ?? {});
1008
+ const relay = workers.find((w) => w.id === relayId);
1009
+ const token = relay?.env?.[INBOX_RELAY_TOKEN_KEY];
1010
+ if (relay && token) inboxRelay = inboxWebhookUrl(`http://${hostOf(relay.name)}:${relay.port}`, token);
1011
+ }
1012
+ const tls = certificate || local ? {
1013
+ kind: "files",
1014
+ ...proxy === "caddy" ? {
1015
+ certFile: `${CADDY_TLS_DIR}/cert.pem`,
1016
+ keyFile: `${CADDY_TLS_DIR}/key.pem`
1017
+ } : edgeCertificatePaths(project)
1018
+ } : { kind: "acme" };
1019
+ const authority = local && !certificate ? input.localAuthority ?? localAuthorityPaths(gkmHome()) : void 0;
1020
+ const root = authority?.certFile ?? certificate?.caFile;
1021
+ const backupsChoice = input.buildOnly ? void 0 : stageBackups(workspace, manifest, stage);
1022
+ const backups = backupsChoice?.mode === "on" && infra.includes("postgres") ? stackBackups({
1023
+ workspace,
1024
+ stage,
1025
+ project,
1026
+ plan,
1027
+ backups: backupsChoice.backups,
1028
+ custom,
1029
+ seed,
1030
+ superuser: credential.containers.postgres,
1031
+ ...telemetryValues ? { telemetry: telemetryValues } : {}
1032
+ }) : void 0;
1033
+ if (!local) for (const app of apps) {
1034
+ const site = manifest[app.id];
1035
+ if (site?.kind !== "site") continue;
1036
+ const key = sitePasswordKey(manifest, site, stage);
1037
+ if (key) app.auth = siteAuth(stage, key, custom);
1038
+ }
1039
+ const wildcard = local ? void 0 : stackWildcard(apps, {
1040
+ manifest,
1041
+ byId,
1042
+ workspace,
1043
+ stage,
1044
+ proxy,
1045
+ certificate: certificate !== void 0,
1046
+ hostOf
1047
+ });
1048
+ const routes = [
1049
+ ...apps.map((app) => ({
1050
+ name: app.name,
1051
+ host: app.host,
1052
+ ...app.aliases?.length ? { aliases: app.aliases } : {},
1053
+ ...app.redirects?.length ? { redirects: {
1054
+ hosts: app.redirects,
1055
+ to: app.url
1056
+ } } : {},
1057
+ ...wildcard?.site === app.id ? { wildcard: wildcard.edge } : {},
1058
+ upstreams: replicaNames(app).map((service) => ({
1059
+ service,
1060
+ port: app.port
1061
+ })),
1062
+ streaming: true,
1063
+ ...app.auth ? { auth: {
1064
+ user: app.auth.user,
1065
+ hash: app.auth.hash
1066
+ } } : {},
1067
+ ...app.limits ? { limits: app.limits } : {},
1068
+ health: app.kind === "site" ? "/" : "/health"
1069
+ })),
1070
+ ...[...fileServers.values()].map(({ route }) => route),
1071
+ ...processors.flatMap(({ name, port, prefixes, origin }) => origin ? [{
1072
+ name,
1073
+ host: origin.host,
1074
+ upstreams: [{
1075
+ service: name,
1076
+ port
1077
+ }],
1078
+ streaming: false,
1079
+ prefixes,
1080
+ requireHeader: {
1081
+ name: ORIGIN_VERIFY_HEADER,
1082
+ value: origin.secret
1083
+ },
1084
+ health: "/health"
1085
+ }] : []),
1086
+ ...workers.flatMap(({ name, port, push }) => push ? [{
1087
+ name,
1088
+ host: push.host,
1089
+ upstreams: [{
1090
+ service: name,
1091
+ port
1092
+ }],
1093
+ streaming: false,
1094
+ paths: push.paths,
1095
+ health: "/health"
1096
+ }] : []),
1097
+ ...logs?.host && logs.public ? [{
1098
+ name: LOGS_SERVICE,
1099
+ host: logs.host,
1100
+ upstreams: [{
1101
+ service: LOGS_SERVICE,
1102
+ port: LOGS_PORT
1103
+ }],
1104
+ streaming: true,
1105
+ allow: logs.public.allow
1106
+ }] : []
1107
+ ];
1108
+ if (mailInbox) {
1109
+ const taken = routes.find((route) => routeHosts(route).includes(mailInbox.host));
1110
+ if (taken) throw new MailInboxHostTaken(mailInbox.host, taken.name);
1111
+ routes.push({
1112
+ name: "mailpit",
1113
+ host: mailInbox.host,
1114
+ upstreams: [{
1115
+ service: "mailpit",
1116
+ port: MAILPIT_WEB_PORT
1117
+ }],
1118
+ streaming: true
1119
+ });
1120
+ }
1121
+ assertHostsUnique(routes);
1122
+ const layout = input.layout ?? defaultLayout(workspace.root);
1123
+ const compose = stackFile({
1124
+ project,
1125
+ plan,
1126
+ infra,
1127
+ apps,
1128
+ workers,
1129
+ processors,
1130
+ credentials: credential.containers,
1131
+ ...storage ? { storage } : {},
1132
+ ...inboxRelay ? { inboxRelay } : {},
1133
+ ...logs ? { logs } : {},
1134
+ ...redis ? { redis } : {},
1135
+ ...backups ? { backups } : {},
1136
+ https,
1137
+ http,
1138
+ composeDir: join(workspace.root, stackDir(stage)),
1139
+ buildRoot: layout.buildRoot,
1140
+ workspaceRoot: workspace.root,
1141
+ envFiles: !input.buildOnly,
1142
+ proxy,
1143
+ edge: new Map([...edgeServices].map((service) => [service, hostOf(service)])),
1144
+ ...local ? { localEdge: {
1145
+ hosts: stackPublicHosts(routes),
1146
+ ...root ? { authority: root } : {}
1147
+ } } : {}
1148
+ });
1149
+ const dockerfiles = {};
1150
+ for (const app of apps) {
1151
+ if (!app.build) continue;
1152
+ dockerfiles[app.build.dockerfile] = appDockerfile(app.name, workspace.apps[app.name], {
1153
+ layout,
1154
+ workspaceRoot: workspace.root,
1155
+ apps: workspace.apps,
1156
+ manifest,
1157
+ cache: STACK_CACHE,
1158
+ workspace,
1159
+ stage,
1160
+ ...app.kind === "site" && app.build.args ? { publicUrlArgs: Object.keys(app.build.args).filter((key) => key !== PRERENDER_RUN_ARG) } : {}
1161
+ });
1162
+ }
1163
+ for (const worker of workers) {
1164
+ if (!worker.build) continue;
1165
+ dockerfiles[worker.build.dockerfile] = workerDockerfile({
1166
+ id: worker.id,
1167
+ name: worker.name,
1168
+ app: worker.host
1169
+ }, workspace.apps[worker.host], {
1170
+ layout,
1171
+ workspaceRoot: workspace.root,
1172
+ manifest,
1173
+ cache: STACK_CACHE
1174
+ });
1175
+ }
1176
+ for (const unit of processors) {
1177
+ if (!unit.build) continue;
1178
+ dockerfiles[unit.build.dockerfile] = processorDockerfile({
1179
+ id: unit.id,
1180
+ name: unit.name,
1181
+ app: unit.host
1182
+ }, workspace.apps[unit.host], {
1183
+ layout,
1184
+ workspaceRoot: workspace.root,
1185
+ manifest,
1186
+ cache: STACK_CACHE
1187
+ });
1188
+ }
1189
+ return {
1190
+ project,
1191
+ stage,
1192
+ local,
1193
+ ...authority ? { authority } : {},
1194
+ apps,
1195
+ workers,
1196
+ processors,
1197
+ mobileApps,
1198
+ infra,
1199
+ compose,
1200
+ proxy,
1201
+ routes,
1202
+ ...wildcard ? { wildcard: {
1203
+ site: wildcard.site,
1204
+ host: `*.${wildcard.edge.domain}`,
1205
+ tls: wildcard.edge.tls.kind
1206
+ } } : {},
1207
+ ...proxy === "caddy" ? { caddyfile: edgeCaddyfile(routes, {
1208
+ tls,
1209
+ edgeToken: outside[EDGE_TOKEN_KEY],
1210
+ ...local ? { redirects: false } : {}
1211
+ }) } : { traefik: traefikDynamicFile(routes, {
1212
+ project,
1213
+ tls,
1214
+ edgeToken: outside[EDGE_TOKEN_KEY]
1215
+ }) },
1216
+ ...certificate ? { tls: certificate } : {},
1217
+ dockerfiles,
1218
+ plan,
1219
+ credential,
1220
+ resolution: {
1221
+ ...derivation,
1222
+ addresses: {
1223
+ ...publicAddresses,
1224
+ ...Object.fromEntries(fileServerUrls)
1225
+ }
1226
+ },
1227
+ ...storage ? { storage } : {},
1228
+ devServices: local ? [] : devServicesUsed(services),
1229
+ ...logs ? { logs } : {},
1230
+ ...telemetry ? { telemetry } : {},
1231
+ ...redis ? { redis } : {},
1232
+ ...backups ? { backups } : {},
1233
+ ...mailInbox ? { mailInbox } : {},
1234
+ warnings
1235
+ };
1236
+ }
1237
+ /** The stack's MinIO's value for one of the S3 client's keys. */
1238
+ function storageValue(key, storage) {
1239
+ if (!storage) return void 0;
1240
+ if (key === "AWS_ACCESS_KEY_ID") return storage.user;
1241
+ if (key === "AWS_SECRET_ACCESS_KEY") return storage.password;
1242
+ if (key === "AWS_REGION") return MINIO_REGION;
1243
+ }
1244
+ /** Which bucket an S3 credential key belongs to — the first one declared. */
1245
+ function storageOwner(key, plan) {
1246
+ if (!STORAGE_KEYS.includes(key)) return void 0;
1247
+ return plan.resources.find((r) => r.kind === "objects");
1248
+ }
1249
+ /** The apps a stack runs: every API and every site, at its stage address. */
1250
+ function stackApps(workspace, manifest, plan, options) {
1251
+ const apps = [];
1252
+ const resources = new Map(plan.resources.map((r) => [r.id, r]));
1253
+ for (const [id, declaration] of Object.entries(manifest)) {
1254
+ if (declaration.kind !== "rest-api" && declaration.kind !== "websocket-api" && declaration.kind !== "site") continue;
1255
+ const name = appKey(id);
1256
+ const app = workspace.apps[name];
1257
+ const resource = resources.get(id);
1258
+ if (!app || !resource || !app.port) continue;
1259
+ const { host, aliases, redirects } = appHosts(name, app, workspace, resource, options);
1260
+ const site = declaration.kind === "site";
1261
+ const { ref, tag } = stackImage(name, options);
1262
+ apps.push({
1263
+ app: name,
1264
+ name,
1265
+ id,
1266
+ kind: declaration.kind,
1267
+ ...declaration.kind === "site" ? { variant: declaration.variant } : {},
1268
+ replicas: declaration.kind === "websocket-api" ? declaration.replicas ?? 1 : 1,
1269
+ ...declaration.kind === "websocket-api" && declaration.limits ? { limits: declaration.limits } : {},
1270
+ runtime: !site || runsServer(declaration),
1271
+ path: app.path,
1272
+ port: app.port,
1273
+ host,
1274
+ ...aliases.length ? { aliases } : {},
1275
+ ...redirects.length ? { redirects } : {},
1276
+ url: `${declaration.kind === "websocket-api" ? "wss" : "https"}://${host}${options.local && options.https !== 443 ? `:${options.https}` : ""}`,
1277
+ ref,
1278
+ tag,
1279
+ ...options.images.mode === "build" ? { build: { dockerfile: `${stackDir(options.stage)}/Dockerfile.${name}` } } : {}
1280
+ });
1281
+ }
1282
+ const byId = new Map(apps.map((app) => [app.id, app.name]));
1283
+ for (const app of apps) {
1284
+ const declaration = manifest[app.id];
1285
+ if (declaration?.kind !== "site" || declaration.prerender !== "stage") continue;
1286
+ const against = declaration.dependencies.map(({ target }) => byId.get(target)).filter((name) => !!name && name !== app.name);
1287
+ app.prerender = { against: [...new Set(against)].sort() };
1288
+ }
1289
+ return apps.sort((a, b) => a.name.localeCompare(b.name));
1290
+ }
1291
+ /**
1292
+ * Where SNS pushes to a worker on a deployed stage, or nothing when it pushes
1293
+ * to none of its subscribers.
1294
+ *
1295
+ * A subscriber is pushed to when the connection string its deliveries come
1296
+ * from — its topic's, or its bucket's events — as this stage resolved it for
1297
+ * the worker, is an SNS one — the same test the worker's own
1298
+ * startup makes, so the edge exposes a route exactly when the worker mounts
1299
+ * it. Each such route, and nothing else the worker serves, answers on
1300
+ * `<worker>.<domain>`.
1301
+ */
1302
+ function workerPush(worker, subscribers, env, options) {
1303
+ 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));
1304
+ if (pushed.length === 0) return void 0;
1305
+ if (!options.domain) throw new NoDomainForStage(options.stage);
1306
+ const host = `${worker.name}.${options.domain}`;
1307
+ const url = `https://${host}`;
1308
+ return {
1309
+ host,
1310
+ url,
1311
+ paths: pushed.map(({ name }) => subscriberRoute(name)),
1312
+ subscribers: pushed.map(({ name, connectionKey, events }) => ({
1313
+ name,
1314
+ connectionKey,
1315
+ endpoint: `${url}${subscriberRoute(name)}`,
1316
+ ...events ? { events } : {}
1317
+ }))
1318
+ };
1319
+ }
1320
+ /** A pushed subscriber the deploy recorded no SNS subscription for. */
1321
+ var PushSubscriptionMissing = class extends GkmError {
1322
+ worker;
1323
+ subscriber;
1324
+ constructor(worker, subscriber) {
1325
+ 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.`);
1326
+ this.worker = worker;
1327
+ this.subscriber = subscriber;
1328
+ this.name = "PushSubscriptionMissing";
1329
+ }
1330
+ };
1331
+ /**
1332
+ * The worker's `GKM_SNS_SUBSCRIPTIONS`: each pushed subscriber's recorded
1333
+ * subscription ARN, and nothing for a subscriber it does not run.
1334
+ *
1335
+ * @throws {PushSubscriptionMissing} when one has none
1336
+ */
1337
+ function recordedSubscriptions(worker, push, recorded = {}) {
1338
+ const arns = {};
1339
+ for (const { name } of push.subscribers) {
1340
+ const arn = recorded[name];
1341
+ if (!arn) throw new PushSubscriptionMissing(worker.name, name);
1342
+ arns[name] = arn;
1343
+ }
1344
+ return JSON.stringify(arns);
1345
+ }
1346
+ /**
1347
+ * A wildcard site on a deployed stage with nowhere to get a certificate for
1348
+ * its tenants' hosts from. Let's Encrypt issues a wildcard certificate only
1349
+ * over the DNS challenge, so the stage either brings its own or gives the
1350
+ * proxy a way to get one.
1351
+ */
1352
+ var WildcardSiteCertificateMissing = class extends GkmError {
1353
+ site;
1354
+ stage;
1355
+ proxy;
1356
+ domain;
1357
+ constructor(site, stage, proxy, domain) {
1358
+ 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.`);
1359
+ this.site = site;
1360
+ this.stage = stage;
1361
+ this.proxy = proxy;
1362
+ this.domain = domain;
1363
+ this.name = "WildcardSiteCertificateMissing";
1364
+ }
1365
+ };
1366
+ /**
1367
+ * A deployed stage's wildcard site, as its edge serves it: the labels it
1368
+ * never takes, and its certificate — the stage's own (`deploy.compose.tls`)
1369
+ * first; then, on the shared Traefik edge, a `*.<domain>` one over the DNS
1370
+ * challenge when Route 53 manages the domain; on the stack's own Caddy, one
1371
+ * per host on demand, asked of the site's `hosts` route.
1372
+ *
1373
+ * @throws {WildcardSiteCertificateMissing} when neither applies
1374
+ */
1375
+ function stackWildcard(apps, options) {
1376
+ const { manifest, workspace, stage, proxy } = options;
1377
+ const app = apps.find((a) => isWildcardSite(manifest[a.id]));
1378
+ if (!app) return void 0;
1379
+ const declaration = manifest[app.id];
1380
+ if (!isWildcardSite(declaration)) return void 0;
1381
+ const domain = workspace.domains?.[stage];
1382
+ if (!domain) throw new NoDomainForStage(stage);
1383
+ const except = options.byId.get(app.id)?.protectedSubdomains ?? [];
1384
+ const tls = (() => {
1385
+ if (options.certificate) return { kind: "stage" };
1386
+ if (proxy === "traefik") {
1387
+ const dns = workspace.dns ? normalizeDnsConfig(workspace.dns) : {};
1388
+ const root = findRootDomain(domain, dns);
1389
+ if (root && dns[root]?.provider === "route53") return { kind: "dns" };
1390
+ } else if (declaration.hosts) {
1391
+ const surface = apps.find((a) => a.id === declaration.hosts?.surface);
1392
+ if (surface) return {
1393
+ kind: "on-demand",
1394
+ ask: `http://${options.hostOf(surface.name)}:${surface.port}${declaration.hosts.path}`
1395
+ };
1396
+ }
1397
+ throw new WildcardSiteCertificateMissing(app.id, stage, proxy, domain);
1398
+ })();
1399
+ return {
1400
+ site: app.id,
1401
+ edge: {
1402
+ domain,
1403
+ except,
1404
+ tls
1405
+ }
1406
+ };
1407
+ }
1408
+ /**
1409
+ * The first label under `stage`'s domain of every other stage's domain that
1410
+ * sits beneath it — `staging` for `staging.example.com` (or
1411
+ * `a.staging.example.com`) under `example.com`.
1412
+ */
1413
+ function nestedStageLabels(domains, stage) {
1414
+ const own = domains?.[stage]?.toLowerCase();
1415
+ if (!own) return [];
1416
+ const labels = /* @__PURE__ */ new Set();
1417
+ for (const [other, domain] of Object.entries(domains ?? {})) {
1418
+ if (other === stage || !domain) continue;
1419
+ const lower = domain.toLowerCase();
1420
+ if (!lower.endsWith(`.${own}`)) continue;
1421
+ const rest = lower.slice(0, -(own.length + 1)).split(".");
1422
+ labels.add(rest.at(-1));
1423
+ }
1424
+ return [...labels].sort();
1425
+ }
1426
+ /** Two constructs the edge would answer on one host. */
1427
+ var EdgeHostTaken = class extends GkmError {
1428
+ host;
1429
+ first;
1430
+ second;
1431
+ constructor(host, first, second) {
1432
+ 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.`);
1433
+ this.host = host;
1434
+ this.first = first;
1435
+ this.second = second;
1436
+ this.name = "EdgeHostTaken";
1437
+ }
1438
+ };
1439
+ /**
1440
+ * Refuse a stack where one host would be routed to two services — every
1441
+ * host of every route, its aliases and redirects included.
1442
+ */
1443
+ function assertHostsUnique(routes) {
1444
+ const claimed = /* @__PURE__ */ new Map();
1445
+ for (const route of routes) for (const host of routeHosts(route)) {
1446
+ const first = claimed.get(host);
1447
+ if (first !== void 0 && first !== route.name) throw new EdgeHostTaken(host, first, route.name);
1448
+ claimed.set(host, route.name);
1449
+ }
1450
+ }
1451
+ /**
1452
+ * The image an app, worker or processor runs on the stage: the release's tag
1453
+ * with the stage on it (`stageTag`), as every target names its images.
1454
+ */
1455
+ function stackImage(name, options) {
1456
+ const tag = stageTag(options.images.tag, options.stage);
1457
+ return {
1458
+ ref: validateImageRef(imageRef(options.identity, name, options.images.registry, tag)),
1459
+ tag
1460
+ };
1461
+ }
1462
+ /** Each processor unit's image, and where it is built from. */
1463
+ function stackProcessors(units, options) {
1464
+ return units.map((unit) => {
1465
+ const server = options.manifest[unit.id];
1466
+ const processors = server?.kind === "file-server" ? server.processors ?? [] : [];
1467
+ return {
1468
+ app: unit.name,
1469
+ name: unit.name,
1470
+ id: unit.id,
1471
+ host: unit.app,
1472
+ port: PROCESSOR_PORT,
1473
+ prefixes: [...new Set(processors.map((p) => p.prefix))].sort(),
1474
+ ...stackImage(unit.name, options),
1475
+ ...options.images.mode === "build" ? { build: { dockerfile: `${stackDir(options.stage)}/Dockerfile.${unit.name}` } } : {}
1476
+ };
1477
+ });
1478
+ }
1479
+ /** Each worker's image, and where it is built from. */
1480
+ function stackWorkers(units, options) {
1481
+ return units.map((unit) => ({
1482
+ app: unit.name,
1483
+ name: unit.name,
1484
+ id: unit.id,
1485
+ host: unit.app,
1486
+ port: WORKER_PORT,
1487
+ ...stackImage(unit.name, options),
1488
+ ...options.images.mode === "build" ? { build: { dockerfile: `${stackDir(options.stage)}/Dockerfile.${unit.name}` } } : {}
1489
+ }));
1490
+ }
1491
+ /**
1492
+ * The hosts an app answers on for a stage: the `gkm dev` edge's
1493
+ * `*.localhost` names for the local stage (`hostsFor`), and the stage's
1494
+ * domain — by the same rule a deploy follows — for any other. Its aliases
1495
+ * and redirects are labels under the stage's domain, as its own is.
1496
+ */
1497
+ function appHosts(name, app, workspace, resource, options) {
1498
+ if (options.local) return hostsFor(resource, workspace.name);
1499
+ const domain = workspace.domains?.[options.stage];
1500
+ if (resource.subdomain === WILDCARD_SUBDOMAIN) {
1501
+ if (!domain) throw new NoDomainForStage(options.stage);
1502
+ return {
1503
+ host: `${WILDCARD_SUBDOMAIN}.${domain}`,
1504
+ aliases: [],
1505
+ redirects: []
1506
+ };
1507
+ }
1508
+ const host = resolveHost(name, app, options.stage, workspace.domains, isMainFrontendApp(name, app, workspace.apps));
1509
+ const under = (label) => {
1510
+ if (!domain) throw new NoDomainForStage(options.stage);
1511
+ return `${label}.${domain}`;
1512
+ };
1513
+ return {
1514
+ host,
1515
+ aliases: (resource.aliases ?? []).map(under),
1516
+ redirects: (resource.redirects ?? []).map(under)
1517
+ };
1518
+ }
1519
+ /** An app's compose services, one per replica: `api`, `api-2`, `api-3`. */
1520
+ function replicaNames(app) {
1521
+ return [app.name, ...Array.from({ length: app.replicas - 1 }, (_, i) => `${app.name}-${i + 2}`)];
1522
+ }
1523
+ /** Where an app container reads gkm's root certificate: mounted read-only. */
1524
+ const LOCAL_CA_IN_CONTAINER = "/etc/gkm/local-ca.pem";
1525
+ /**
1526
+ * The local stage's public hosts a container can be pointed at: every
1527
+ * route's but a wildcard's, which no host entry can name.
1528
+ */
1529
+ function stackPublicHosts(routes) {
1530
+ return [...new Set(routes.flatMap(routeHosts))].filter((host) => !host.startsWith("*.")).sort();
1531
+ }
1532
+ /**
1533
+ * What a local stack's container needs to call the stage's own public hosts —
1534
+ * `https://api.<project>.localhost`, which a site's server-side code is
1535
+ * handed because a browser is.
1536
+ *
1537
+ * Inside a container `*.localhost` is its own loopback, so each host is
1538
+ * resolved to the host's gateway, where the edge — the stack's Caddy, or the
1539
+ * shared Traefik edge — publishes its ports. Not a network alias on the edge:
1540
+ * the address may carry the edge's published port
1541
+ * (`https://api.shop.localhost:8443`), which only the host answers on. And the
1542
+ * container trusts the root the edge's certificate chains to — gkm's, or the
1543
+ * one the stage's own certificate names — its public certificate, never a
1544
+ * key, mounted read-only.
1545
+ */
1546
+ function localEdgeAccess(edge) {
1547
+ return {
1548
+ extra_hosts: edge.hosts.map((host) => `${host}:host-gateway`),
1549
+ volumes: edge.authority ? [`${edge.authority}:${LOCAL_CA_IN_CONTAINER}:ro`] : [],
1550
+ environment: edge.authority ? { NODE_EXTRA_CA_CERTS: LOCAL_CA_IN_CONTAINER } : {}
1551
+ };
1552
+ }
1553
+ /**
1554
+ * What the build of a site that pre-renders against its stage needs to reach
1555
+ * the stage's public hosts. A deployed stage's resolve and are trusted as
1556
+ * anywhere. The local stage's are `*.localhost` — the build's own loopback —
1557
+ * so each is pointed at the host's gateway, where the edge publishes its
1558
+ * ports, and the build is handed the root the edge's certificate chains to,
1559
+ * as {@link localEdgeAccess} hands a container both.
1560
+ *
1561
+ * Not the stack's network: BuildKit builds on none but its own.
1562
+ */
1563
+ function prerenderBuildAccess(edge) {
1564
+ if (!edge) return {};
1565
+ const { extra_hosts } = localEdgeAccess(edge);
1566
+ return {
1567
+ ...extra_hosts.length ? { extra_hosts } : {},
1568
+ ...edge.authority ? { secrets: [LOCAL_CA_BUILD_SECRET] } : {}
1569
+ };
1570
+ }
1571
+ /** The compose document: the infrastructure, the apps, and the edge. */
1572
+ function stackFile(options) {
1573
+ const { project, plan, apps } = options;
1574
+ const infra = options.infra.filter((name) => name !== LOGS_SERVICE);
1575
+ const derived = composeFor({
1576
+ ...plan,
1577
+ containers: [...infra]
1578
+ }, {
1579
+ project,
1580
+ ports: Object.fromEntries(portKeys(infra, plan.fakes).map((key) => [key, 0])),
1581
+ credentials: options.credentials
1582
+ });
1583
+ const services = {};
1584
+ const volumes = {
1585
+ ...derived.volumes,
1586
+ ...options.proxy === "caddy" ? {
1587
+ "caddy-data": {},
1588
+ "caddy-config": {}
1589
+ } : {},
1590
+ ...options.logs ? { "openobserve-data": {} } : {}
1591
+ };
1592
+ for (const name of infra) {
1593
+ const { ports: _ports, depends_on, profiles: _profiles, ...service } = derived.services[name];
1594
+ services[name] = {
1595
+ ...service,
1596
+ ...depends_on?.length ? { depends_on: Object.fromEntries(depends_on.map((dep) => [dep, HEALTHY])) } : {}
1597
+ };
1598
+ }
1599
+ const postgres = services.postgres;
1600
+ if (postgres) postgres.ports = [`127.0.0.1::${LOOPBACK_SERVICES.postgres}`];
1601
+ const minio = services.minio;
1602
+ if (minio && options.storage) {
1603
+ minio.environment = {
1604
+ ...minio.environment,
1605
+ MINIO_ROOT_USER: options.storage.user,
1606
+ MINIO_ROOT_PASSWORD: options.storage.password,
1607
+ ...minioWebhookEnv(options.storage.webhooks)
1608
+ };
1609
+ minio.ports = [`127.0.0.1::${LOOPBACK_SERVICES.minio}`];
1610
+ }
1611
+ const mailpit = services.mailpit;
1612
+ if (mailpit && options.inboxRelay) mailpit.environment = {
1613
+ ...mailpit.environment,
1614
+ MP_WEBHOOK_URL: options.inboxRelay
1615
+ };
1616
+ if (services["redis"] && options.redis) services[REDIS_SERVICE] = redisService(options.redis);
1617
+ if (options.logs) services[LOGS_SERVICE] = logsService(options.logs);
1618
+ if (options.backups) services[BACKUPS_SERVICE] = backupsService(options.backups, options.envFiles);
1619
+ for (const app of apps) {
1620
+ const definition = {
1621
+ image: app.ref,
1622
+ ...app.build ? { build: {
1623
+ ...composeBuildPaths({
1624
+ composeDir: options.composeDir,
1625
+ buildRoot: options.buildRoot,
1626
+ workspaceRoot: options.workspaceRoot,
1627
+ dockerfile: app.build.dockerfile
1628
+ }),
1629
+ ...app.build.args ? { args: app.build.args } : {},
1630
+ ...app.build.offlineHosts ? { extra_hosts: app.build.offlineHosts.map((host) => `${host}:${OFFLINE_BUILD_ADDRESS}`) } : {},
1631
+ ...app.prerender ? prerenderBuildAccess(options.localEdge) : {}
1632
+ } } : {},
1633
+ restart: "unless-stopped",
1634
+ ...app.runtime ? { env_file: [{
1635
+ path: `./${app.name}.env`,
1636
+ format: "raw"
1637
+ }] } : {},
1638
+ ...app.kind !== "site" && infra.length ? { depends_on: Object.fromEntries(infra.map((name) => [name, HEALTHY])) } : {},
1639
+ healthcheck: probe(app.port, app.kind === "site" ? "/" : "/health"),
1640
+ ...app.kind === "websocket-api" ? { ulimits: { nofile: NOFILE } } : {}
1641
+ };
1642
+ for (const name of replicaNames(app)) services[name] = { ...definition };
1643
+ }
1644
+ for (const worker of [...options.workers, ...options.processors]) services[worker.name] = {
1645
+ image: worker.ref,
1646
+ ...worker.build ? { build: composeBuildPaths({
1647
+ composeDir: options.composeDir,
1648
+ buildRoot: options.buildRoot,
1649
+ workspaceRoot: options.workspaceRoot,
1650
+ dockerfile: worker.build.dockerfile
1651
+ }) } : {},
1652
+ restart: "unless-stopped",
1653
+ env_file: [{
1654
+ path: `./${worker.name}.env`,
1655
+ format: "raw"
1656
+ }],
1657
+ ...infra.length ? { depends_on: Object.fromEntries(infra.map((name) => [name, HEALTHY])) } : {},
1658
+ healthcheck: probe(worker.port, "/health")
1659
+ };
1660
+ if (options.localEdge) {
1661
+ const access = localEdgeAccess(options.localEdge);
1662
+ for (const name of [
1663
+ ...apps.flatMap(replicaNames),
1664
+ ...options.workers.map((w) => w.name),
1665
+ ...options.processors.map((p) => p.name)
1666
+ ]) {
1667
+ const service = services[name];
1668
+ if (!service) continue;
1669
+ services[name] = {
1670
+ ...service,
1671
+ environment: {
1672
+ ...service.environment,
1673
+ ...access.environment
1674
+ },
1675
+ ...access.volumes.length ? { volumes: [...service.volumes ?? [], ...access.volumes] } : {},
1676
+ ...access.extra_hosts.length ? { extra_hosts: [...service.extra_hosts ?? [], ...access.extra_hosts] } : {}
1677
+ };
1678
+ }
1679
+ }
1680
+ if (options.proxy === "caddy") services.caddy = {
1681
+ image: DEFAULT_IMAGES.caddy,
1682
+ restart: "unless-stopped",
1683
+ ports: [`${options.https}:443`, `${options.http}:80`],
1684
+ volumes: ["caddy-data:/data", "caddy-config:/config"],
1685
+ ...EDGE_LIMITS,
1686
+ depends_on: Object.fromEntries([
1687
+ ...apps.filter((app) => !(app.prerender && app.build)).flatMap(replicaNames),
1688
+ ...options.workers.filter((w) => w.push).map((w) => w.name),
1689
+ ...options.processors.map((p) => p.name)
1690
+ ].map((name) => [name, STARTED])),
1691
+ healthcheck: {
1692
+ test: [
1693
+ "CMD",
1694
+ "caddy",
1695
+ "version"
1696
+ ],
1697
+ interval: "10s",
1698
+ timeout: "5s",
1699
+ retries: 5
1700
+ }
1701
+ };
1702
+ for (const [service, alias] of options.edge) {
1703
+ const definition = services[service];
1704
+ if (!definition) continue;
1705
+ definition.networks = {
1706
+ default: { aliases: [alias] },
1707
+ edge: { aliases: [alias] }
1708
+ };
1709
+ }
1710
+ for (const service of Object.values(services)) {
1711
+ if (!options.envFiles) delete service.env_file;
1712
+ service.logging = {
1713
+ driver: LOG_ROTATION.driver,
1714
+ options: { ...LOG_ROTATION.options }
1715
+ };
1716
+ }
1717
+ const authority = options.localEdge?.authority;
1718
+ return {
1719
+ name: project,
1720
+ services,
1721
+ volumes,
1722
+ ...apps.some((app) => app.prerender && app.build) && authority ? { secrets: { [LOCAL_CA_BUILD_SECRET]: { file: authority } } } : {},
1723
+ ...options.edge.size > 0 ? { networks: { edge: {
1724
+ name: EDGE_NETWORK,
1725
+ external: true
1726
+ } } } : {}
1727
+ };
1728
+ }
1729
+ /**
1730
+ * A build without a layout: the workspace is the build root, with pnpm.
1731
+ * What a caller that never looked at the filesystem gets.
1732
+ */
1733
+ function defaultLayout(root) {
1734
+ return {
1735
+ buildRoot: root,
1736
+ gkmRoot: ".",
1737
+ tools: {
1738
+ packageManager: "pnpm",
1739
+ turboVersion: TURBO_VERSION,
1740
+ monorepo: true
1741
+ },
1742
+ gkmPaths: ["gkm.config.*"]
1743
+ };
1744
+ }
1745
+ /** Render an app's env file: one `KEY=value` per line, read raw by compose. */
1746
+ function envFile(env) {
1747
+ return `${Object.entries(env).sort(([a], [b]) => a.localeCompare(b)).map(([key, value]) => `${key}=${value}`).join("\n")}\n`;
1748
+ }
1749
+ /**
1750
+ * The stack with its OpenObserve on another loopback port — the one its
1751
+ * server has free for it, found before anything is written. Its UI's URL and
1752
+ * its service's published port move together; nothing else reads the port.
1753
+ */
1754
+ function withLogsPort(stack, port) {
1755
+ if (!stack.logs) return stack;
1756
+ const logs = logsOnPort(stack.logs, port);
1757
+ const service = stack.compose.services[LOGS_SERVICE];
1758
+ if (logs === stack.logs || !service) return stack;
1759
+ return {
1760
+ ...stack,
1761
+ logs,
1762
+ compose: {
1763
+ ...stack.compose,
1764
+ services: {
1765
+ ...stack.compose.services,
1766
+ [LOGS_SERVICE]: {
1767
+ ...service,
1768
+ ...logsPorts(logs)
1769
+ }
1770
+ }
1771
+ }
1772
+ };
1773
+ }
1774
+ //#endregion
1775
+ export { awsEndpoint as _, composeProject as a, derivedCredentials as c, stackDir as d, stackPlan as f, awsClientConfig as g, assertSitePasswords as h, LOOPBACK_SERVICES as i, envFile as l, withLogsPort as m, LOGS_PORT_ENV as n, composeStack as o, withCaddyConfigs as p, LOG_ROTATION as r, deployedInboxEnv as s, EDGE_PORT_ENV as t, replicaNames as u, awsProvisioningCredentials as v };
1776
+
1777
+ //# sourceMappingURL=stack-BHrGbsGA.mjs.map