@geekmidas/cli 10.0.0-alpha.15 → 10.0.0-alpha.150

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 (438) hide show
  1. package/README.md +313 -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-CusLH-9S.mjs +1037 -0
  7. package/dist/EndpointGenerator-CusLH-9S.mjs.map +1 -0
  8. package/dist/EndpointGenerator-DyLMYClE.cjs +1096 -0
  9. package/dist/EndpointGenerator-DyLMYClE.cjs.map +1 -0
  10. package/dist/GoDaddyProvider-CytuBrRm.cjs +412 -0
  11. package/dist/GoDaddyProvider-CytuBrRm.cjs.map +1 -0
  12. package/dist/GoDaddyProvider-W0Dxd5v9.mjs +412 -0
  13. package/dist/GoDaddyProvider-W0Dxd5v9.mjs.map +1 -0
  14. package/dist/{HostingerProvider-BZFGYYVA.cjs → HostingerProvider-CCc9xoBN.cjs} +23 -9
  15. package/dist/HostingerProvider-CCc9xoBN.cjs.map +1 -0
  16. package/dist/{HostingerProvider-BY26bWwB.mjs → HostingerProvider-DaQr2ueR.mjs} +23 -9
  17. package/dist/HostingerProvider-DaQr2ueR.mjs.map +1 -0
  18. package/dist/LegacyStateStore-BDA0rx3b.cjs +124 -0
  19. package/dist/LegacyStateStore-BDA0rx3b.cjs.map +1 -0
  20. package/dist/LegacyStateStore-BTcTbCGk.mjs +124 -0
  21. package/dist/LegacyStateStore-BTcTbCGk.mjs.map +1 -0
  22. package/dist/LocalStateStore-BNuQoZYe.cjs +178 -0
  23. package/dist/LocalStateStore-BNuQoZYe.cjs.map +1 -0
  24. package/dist/LocalStateStore-CqpCKVvi.mjs +167 -0
  25. package/dist/LocalStateStore-CqpCKVvi.mjs.map +1 -0
  26. package/dist/OpenApiTsGenerator-BTMuu1WS.mjs +534 -0
  27. package/dist/OpenApiTsGenerator-BTMuu1WS.mjs.map +1 -0
  28. package/dist/OpenApiTsGenerator-CI-tceXV.cjs +539 -0
  29. package/dist/OpenApiTsGenerator-CI-tceXV.cjs.map +1 -0
  30. package/dist/{Route53Provider-Cvj40A8I.mjs → Route53Provider-Di_SD9CF.mjs} +3 -3
  31. package/dist/Route53Provider-Di_SD9CF.mjs.map +1 -0
  32. package/dist/{Route53Provider-DVILBsvV.cjs → Route53Provider-emLuQHVw.cjs} +3 -3
  33. package/dist/Route53Provider-emLuQHVw.cjs.map +1 -0
  34. package/dist/S3StateStore-BpsGWDMK.mjs +223 -0
  35. package/dist/S3StateStore-BpsGWDMK.mjs.map +1 -0
  36. package/dist/S3StateStore-nrmSClXN.cjs +222 -0
  37. package/dist/S3StateStore-nrmSClXN.cjs.map +1 -0
  38. package/dist/SSMStateStore-DrPCC_VN.mjs +205 -0
  39. package/dist/SSMStateStore-DrPCC_VN.mjs.map +1 -0
  40. package/dist/SSMStateStore-hexM8C7n.cjs +204 -0
  41. package/dist/SSMStateStore-hexM8C7n.cjs.map +1 -0
  42. package/dist/SubscriberGenerator-BNJyPmXJ.cjs +848 -0
  43. package/dist/SubscriberGenerator-BNJyPmXJ.cjs.map +1 -0
  44. package/dist/SubscriberGenerator-CzPrixYu.mjs +783 -0
  45. package/dist/SubscriberGenerator-CzPrixYu.mjs.map +1 -0
  46. package/dist/add-DXMYV5ak.mjs +711 -0
  47. package/dist/add-DXMYV5ak.mjs.map +1 -0
  48. package/dist/add-DgAeo6ht.cjs +713 -0
  49. package/dist/add-DgAeo6ht.cjs.map +1 -0
  50. package/dist/appPorts-BoXMwolc.mjs +249 -0
  51. package/dist/appPorts-BoXMwolc.mjs.map +1 -0
  52. package/dist/appPorts-IW-OZmRi.cjs +296 -0
  53. package/dist/appPorts-IW-OZmRi.cjs.map +1 -0
  54. package/dist/apps-Bb05wCBm.mjs +5534 -0
  55. package/dist/apps-Bb05wCBm.mjs.map +1 -0
  56. package/dist/apps-CMLyyVGQ.cjs +6148 -0
  57. package/dist/apps-CMLyyVGQ.cjs.map +1 -0
  58. package/dist/aws-8QQ8n-t6.mjs +89 -0
  59. package/dist/aws-8QQ8n-t6.mjs.map +1 -0
  60. package/dist/aws-DY9NqQIT.cjs +100 -0
  61. package/dist/aws-DY9NqQIT.cjs.map +1 -0
  62. package/dist/awsStore-Bx5nCFnS.mjs +121 -0
  63. package/dist/awsStore-Bx5nCFnS.mjs.map +1 -0
  64. package/dist/awsStore-u3ehhMoY.cjs +138 -0
  65. package/dist/awsStore-u3ehhMoY.cjs.map +1 -0
  66. package/dist/{backup-provisioner-DIVCbfee.mjs → backup-provisioner-C8DnCmxK.mjs} +2 -2
  67. package/dist/backup-provisioner-C8DnCmxK.mjs.map +1 -0
  68. package/dist/{backup-provisioner-BmhIO_Yr.cjs → backup-provisioner-oDEsPj02.cjs} +2 -2
  69. package/dist/backup-provisioner-oDEsPj02.cjs.map +1 -0
  70. package/dist/backups/runner.cjs +519 -0
  71. package/dist/backups/runner.cjs.map +1 -0
  72. package/dist/backups/runner.d.cts +102 -0
  73. package/dist/backups/runner.d.cts.map +1 -0
  74. package/dist/backups/runner.d.mts +102 -0
  75. package/dist/backups/runner.d.mts.map +1 -0
  76. package/dist/backups/runner.mjs +506 -0
  77. package/dist/backups/runner.mjs.map +1 -0
  78. package/dist/{bundler-BodTL4kf.mjs → bundler-C1kDZyQ-.mjs} +59 -14
  79. package/dist/bundler-C1kDZyQ-.mjs.map +1 -0
  80. package/dist/{bundler-BeNDZdHQ.cjs → bundler-CD9Ug2uu.cjs} +59 -14
  81. package/dist/bundler-CD9Ug2uu.cjs.map +1 -0
  82. package/dist/cli-35yoGg9o.cjs +71 -0
  83. package/dist/cli-35yoGg9o.cjs.map +1 -0
  84. package/dist/cli-BAcJaRG7.mjs +71 -0
  85. package/dist/cli-BAcJaRG7.mjs.map +1 -0
  86. package/dist/compose-BZTh5HR3.mjs +1560 -0
  87. package/dist/compose-BZTh5HR3.mjs.map +1 -0
  88. package/dist/compose-CAhGIfG8.mjs +2877 -0
  89. package/dist/compose-CAhGIfG8.mjs.map +1 -0
  90. package/dist/compose-DF08HNJE.cjs +2966 -0
  91. package/dist/compose-DF08HNJE.cjs.map +1 -0
  92. package/dist/compose-KV6q3cEz.cjs +1919 -0
  93. package/dist/compose-KV6q3cEz.cjs.map +1 -0
  94. package/dist/config-BLrAd7Of.mjs +659 -0
  95. package/dist/config-BLrAd7Of.mjs.map +1 -0
  96. package/dist/config-CRk2vdSp.d.mts +268 -0
  97. package/dist/config-CRk2vdSp.d.mts.map +1 -0
  98. package/dist/config-juUyBlb1.cjs +772 -0
  99. package/dist/config-juUyBlb1.cjs.map +1 -0
  100. package/dist/config-oBgsbLip.d.cts +268 -0
  101. package/dist/config-oBgsbLip.d.cts.map +1 -0
  102. package/dist/config.cjs +11 -3
  103. package/dist/config.d.cts +4 -117
  104. package/dist/config.d.mts +4 -117
  105. package/dist/config.mjs +3 -3
  106. package/dist/credentialSchemas-BAklWDna.cjs +271 -0
  107. package/dist/credentialSchemas-BAklWDna.cjs.map +1 -0
  108. package/dist/credentialSchemas-mz9QZTYh.mjs +236 -0
  109. package/dist/credentialSchemas-mz9QZTYh.mjs.map +1 -0
  110. package/dist/credentials-B72Jrk66.mjs +1817 -0
  111. package/dist/credentials-B72Jrk66.mjs.map +1 -0
  112. package/dist/credentials-Dmhuj3FX.cjs +2272 -0
  113. package/dist/credentials-Dmhuj3FX.cjs.map +1 -0
  114. package/dist/databases-DawSdqBI.cjs +703 -0
  115. package/dist/databases-DawSdqBI.cjs.map +1 -0
  116. package/dist/databases-mzSUFBTw.mjs +588 -0
  117. package/dist/databases-mzSUFBTw.mjs.map +1 -0
  118. package/dist/define-6poNqm5O.mjs +106 -0
  119. package/dist/define-6poNqm5O.mjs.map +1 -0
  120. package/dist/define-crmMcXFS.cjs +153 -0
  121. package/dist/define-crmMcXFS.cjs.map +1 -0
  122. package/dist/deploy/public.cjs +211 -0
  123. package/dist/deploy/public.cjs.map +1 -0
  124. package/dist/deploy/public.d.cts +647 -0
  125. package/dist/deploy/public.d.cts.map +1 -0
  126. package/dist/deploy/public.d.mts +647 -0
  127. package/dist/deploy/public.d.mts.map +1 -0
  128. package/dist/deploy/public.mjs +144 -0
  129. package/dist/deploy/public.mjs.map +1 -0
  130. package/dist/deploy/sniffer-envparser-worker.cjs +54 -0
  131. package/dist/deploy/sniffer-envparser-worker.cjs.map +1 -0
  132. package/dist/deploy/sniffer-envparser-worker.d.cts +1 -0
  133. package/dist/deploy/sniffer-envparser-worker.d.mts +1 -0
  134. package/dist/deploy/sniffer-envparser-worker.mjs +55 -0
  135. package/dist/deploy/sniffer-envparser-worker.mjs.map +1 -0
  136. package/dist/deploy/sniffer-hooks.cjs +1 -1
  137. package/dist/deploy/sniffer-hooks.mjs +1 -1
  138. package/dist/deploy/sniffer-loader.cjs +2 -2
  139. package/dist/deploy/sniffer-loader.mjs +1 -1
  140. package/dist/deploy/sniffer-routes-worker.cjs +2 -2
  141. package/dist/deploy/sniffer-routes-worker.mjs +1 -1
  142. package/dist/deploy-BV6Tw73K.cjs +3892 -0
  143. package/dist/deploy-BV6Tw73K.cjs.map +1 -0
  144. package/dist/deploy-C4XjPy-a.mjs +3836 -0
  145. package/dist/deploy-C4XjPy-a.mjs.map +1 -0
  146. package/dist/discover-CRywE7yc.cjs +1085 -0
  147. package/dist/discover-CRywE7yc.cjs.map +1 -0
  148. package/dist/discover-DbDrCQ8h.mjs +940 -0
  149. package/dist/discover-DbDrCQ8h.mjs.map +1 -0
  150. package/dist/docker-B0di7_Ub.cjs +1514 -0
  151. package/dist/docker-B0di7_Ub.cjs.map +1 -0
  152. package/dist/docker-D_NN2Z6W.mjs +1407 -0
  153. package/dist/docker-D_NN2Z6W.mjs.map +1 -0
  154. package/dist/dokploy-DDyZ0o4M.mjs +38 -0
  155. package/dist/dokploy-DDyZ0o4M.mjs.map +1 -0
  156. package/dist/dokploy-FFNHKz37.cjs +38 -0
  157. package/dist/dokploy-FFNHKz37.cjs.map +1 -0
  158. package/dist/drivers-aM87NQJi.cjs +224 -0
  159. package/dist/drivers-aM87NQJi.cjs.map +1 -0
  160. package/dist/drivers-uxLBq3e3.mjs +195 -0
  161. package/dist/drivers-uxLBq3e3.mjs.map +1 -0
  162. package/dist/eas-6_Z1ImVg.mjs +334 -0
  163. package/dist/eas-6_Z1ImVg.mjs.map +1 -0
  164. package/dist/eas-BetrZzjq.cjs +337 -0
  165. package/dist/eas-BetrZzjq.cjs.map +1 -0
  166. package/dist/emit-Bj6XSivk.mjs +136 -0
  167. package/dist/emit-Bj6XSivk.mjs.map +1 -0
  168. package/dist/emit-CDC__ubE.cjs +147 -0
  169. package/dist/emit-CDC__ubE.cjs.map +1 -0
  170. package/dist/encryption-BrRVjItb.cjs +90 -0
  171. package/dist/encryption-BrRVjItb.cjs.map +1 -0
  172. package/dist/encryption-DGnfdO68.mjs +89 -0
  173. package/dist/encryption-DGnfdO68.mjs.map +1 -0
  174. package/dist/engine-8TjM26dd.mjs +3217 -0
  175. package/dist/engine-8TjM26dd.mjs.map +1 -0
  176. package/dist/engine-C36N8por.cjs +3330 -0
  177. package/dist/engine-C36N8por.cjs.map +1 -0
  178. package/dist/errors-D8Gwp5kU.mjs +23 -0
  179. package/dist/errors-D8Gwp5kU.mjs.map +1 -0
  180. package/dist/errors-DMC4Umsb.cjs +34 -0
  181. package/dist/errors-DMC4Umsb.cjs.map +1 -0
  182. package/dist/github-BOu0bETi.cjs +901 -0
  183. package/dist/github-BOu0bETi.cjs.map +1 -0
  184. package/dist/github-Ct6XDkzE.mjs +900 -0
  185. package/dist/github-Ct6XDkzE.mjs.map +1 -0
  186. package/dist/googlePlay-BaRsxlJo.mjs +931 -0
  187. package/dist/googlePlay-BaRsxlJo.mjs.map +1 -0
  188. package/dist/googlePlay-JAxXMaGu.cjs +931 -0
  189. package/dist/googlePlay-JAxXMaGu.cjs.map +1 -0
  190. package/dist/{index-D-iAVHx-.d.cts → index-B35vTdAW.d.cts} +39 -15
  191. package/dist/index-B35vTdAW.d.cts.map +1 -0
  192. package/dist/{index-Cd-qeOam.d.mts → index-Dv1Zj86i.d.mts} +39 -15
  193. package/dist/index-Dv1Zj86i.d.mts.map +1 -0
  194. package/dist/index.cjs +13594 -12347
  195. package/dist/index.cjs.map +1 -1
  196. package/dist/index.mjs +13541 -12292
  197. package/dist/index.mjs.map +1 -1
  198. package/dist/local-D7WVQcJJ.mjs +224 -0
  199. package/dist/local-D7WVQcJJ.mjs.map +1 -0
  200. package/dist/local-DFPeCIJi.cjs +241 -0
  201. package/dist/local-DFPeCIJi.cjs.map +1 -0
  202. package/dist/migrate-BMIUYmpM.mjs +267 -0
  203. package/dist/migrate-BMIUYmpM.mjs.map +1 -0
  204. package/dist/migrate-CnE-X40v.mjs +181 -0
  205. package/dist/migrate-CnE-X40v.mjs.map +1 -0
  206. package/dist/migrate-CvuWFjos.cjs +181 -0
  207. package/dist/migrate-CvuWFjos.cjs.map +1 -0
  208. package/dist/migrate-DdE8kF0j.cjs +272 -0
  209. package/dist/migrate-DdE8kF0j.cjs.map +1 -0
  210. package/dist/notes-C_4SO0x4.mjs +399 -0
  211. package/dist/notes-C_4SO0x4.mjs.map +1 -0
  212. package/dist/notes-ORze6zXA.cjs +500 -0
  213. package/dist/notes-ORze6zXA.cjs.map +1 -0
  214. package/dist/openapi.cjs +213 -7
  215. package/dist/openapi.cjs.map +1 -0
  216. package/dist/openapi.d.cts +32 -8
  217. package/dist/openapi.d.cts.map +1 -1
  218. package/dist/openapi.d.mts +32 -8
  219. package/dist/openapi.d.mts.map +1 -1
  220. package/dist/openapi.mjs +208 -2
  221. package/dist/openapi.mjs.map +1 -0
  222. package/dist/projectBucket-C9x0gzEO.cjs +263 -0
  223. package/dist/projectBucket-C9x0gzEO.cjs.map +1 -0
  224. package/dist/projectBucket-CdRj4IyR.mjs +222 -0
  225. package/dist/projectBucket-CdRj4IyR.mjs.map +1 -0
  226. package/dist/provider-BqpjG9QM.cjs +57 -0
  227. package/dist/provider-BqpjG9QM.cjs.map +1 -0
  228. package/dist/provider-CEOKk8NS.mjs +46 -0
  229. package/dist/provider-CEOKk8NS.mjs.map +1 -0
  230. package/dist/publish-CL376jrq.cjs +124 -0
  231. package/dist/publish-CL376jrq.cjs.map +1 -0
  232. package/dist/publish-DkkWS3Pj.mjs +123 -0
  233. package/dist/publish-DkkWS3Pj.mjs.map +1 -0
  234. package/dist/ready-BNh3zsSn.cjs +404 -0
  235. package/dist/ready-BNh3zsSn.cjs.map +1 -0
  236. package/dist/ready-g25dcGzK.mjs +375 -0
  237. package/dist/ready-g25dcGzK.mjs.map +1 -0
  238. package/dist/reconcile/public.cjs +3 -5
  239. package/dist/reconcile/public.d.cts +31 -89
  240. package/dist/reconcile/public.d.cts.map +1 -1
  241. package/dist/reconcile/public.d.mts +31 -89
  242. package/dist/reconcile/public.d.mts.map +1 -1
  243. package/dist/reconcile/public.mjs +3 -3
  244. package/dist/{reconcile-DhQ00DpU.mjs → reconcile--I7V4Klj.mjs} +2 -2
  245. package/dist/{reconcile-DhQ00DpU.mjs.map → reconcile--I7V4Klj.mjs.map} +1 -1
  246. package/dist/{reconcile-Dd2iyILf.cjs → reconcile-CuCQBa5-.cjs} +3 -3
  247. package/dist/{reconcile-Dd2iyILf.cjs.map → reconcile-CuCQBa5-.cjs.map} +1 -1
  248. package/dist/resolve-BXzDwYUS.cjs +316 -0
  249. package/dist/resolve-BXzDwYUS.cjs.map +1 -0
  250. package/dist/resolve-CZ_Wel7j.mjs +263 -0
  251. package/dist/resolve-CZ_Wel7j.mjs.map +1 -0
  252. package/dist/rollback-D_FXI_K5.mjs +136 -0
  253. package/dist/rollback-D_FXI_K5.mjs.map +1 -0
  254. package/dist/rollback-p1y0KlED.cjs +165 -0
  255. package/dist/rollback-p1y0KlED.cjs.map +1 -0
  256. package/dist/runtime-CFvcLEJW.d.cts +82 -0
  257. package/dist/runtime-CFvcLEJW.d.cts.map +1 -0
  258. package/dist/runtime-dwsH6ddo.d.mts +82 -0
  259. package/dist/runtime-dwsH6ddo.d.mts.map +1 -0
  260. package/dist/s3-CV5baYeq.mjs +215 -0
  261. package/dist/s3-CV5baYeq.mjs.map +1 -0
  262. package/dist/s3-DTX4Kkmn.cjs +215 -0
  263. package/dist/s3-DTX4Kkmn.cjs.map +1 -0
  264. package/dist/sandbox/config-worker.cjs +43 -0
  265. package/dist/sandbox/config-worker.cjs.map +1 -0
  266. package/dist/sandbox/config-worker.d.cts +1 -0
  267. package/dist/sandbox/config-worker.d.mts +1 -0
  268. package/dist/sandbox/config-worker.mjs +44 -0
  269. package/dist/sandbox/config-worker.mjs.map +1 -0
  270. package/dist/sandbox/credentials-worker.cjs +53 -0
  271. package/dist/sandbox/credentials-worker.cjs.map +1 -0
  272. package/dist/sandbox/credentials-worker.d.cts +1 -0
  273. package/dist/sandbox/credentials-worker.d.mts +1 -0
  274. package/dist/sandbox/credentials-worker.mjs +54 -0
  275. package/dist/sandbox/credentials-worker.mjs.map +1 -0
  276. package/dist/sandbox/discover-worker.cjs +47 -0
  277. package/dist/sandbox/discover-worker.cjs.map +1 -0
  278. package/dist/sandbox/discover-worker.d.cts +1 -0
  279. package/dist/sandbox/discover-worker.d.mts +1 -0
  280. package/dist/sandbox/discover-worker.mjs +48 -0
  281. package/dist/sandbox/discover-worker.mjs.map +1 -0
  282. package/dist/sandbox/migrate-worker.cjs +75 -0
  283. package/dist/sandbox/migrate-worker.cjs.map +1 -0
  284. package/dist/sandbox/migrate-worker.d.cts +1 -0
  285. package/dist/sandbox/migrate-worker.d.mts +1 -0
  286. package/dist/sandbox/migrate-worker.mjs +76 -0
  287. package/dist/sandbox/migrate-worker.mjs.map +1 -0
  288. package/dist/{workspace-mFpI_ky_.cjs → schemas-BCwKKA42.mjs} +399 -1162
  289. package/dist/schemas-BCwKKA42.mjs.map +1 -0
  290. package/dist/{workspace-CgwmXEtc.mjs → schemas-BQ_v0lEX.cjs} +487 -971
  291. package/dist/schemas-BQ_v0lEX.cjs.map +1 -0
  292. package/dist/secretsManager-CQORubp9.mjs +97 -0
  293. package/dist/secretsManager-CQORubp9.mjs.map +1 -0
  294. package/dist/secretsManager-RAGcEDX1.cjs +108 -0
  295. package/dist/secretsManager-RAGcEDX1.cjs.map +1 -0
  296. package/dist/seeds-B3xvUAQf.cjs +363 -0
  297. package/dist/seeds-B3xvUAQf.cjs.map +1 -0
  298. package/dist/seeds-BCC8vAXR.mjs +298 -0
  299. package/dist/seeds-BCC8vAXR.mjs.map +1 -0
  300. package/dist/serverSetup-BykJrnYe.cjs +652 -0
  301. package/dist/serverSetup-BykJrnYe.cjs.map +1 -0
  302. package/dist/serverSetup-CkuvIoej.mjs +652 -0
  303. package/dist/serverSetup-CkuvIoej.mjs.map +1 -0
  304. package/dist/sniffer-BIpoMNGz.mjs +1824 -0
  305. package/dist/sniffer-BIpoMNGz.mjs.map +1 -0
  306. package/dist/sniffer-DiBMi93N.cjs +1997 -0
  307. package/dist/sniffer-DiBMi93N.cjs.map +1 -0
  308. package/dist/snsSubscriptions-CkO_zk0j.cjs +1173 -0
  309. package/dist/snsSubscriptions-CkO_zk0j.cjs.map +1 -0
  310. package/dist/snsSubscriptions-CrmfcJfv.mjs +1048 -0
  311. package/dist/snsSubscriptions-CrmfcJfv.mjs.map +1 -0
  312. package/dist/sst-BZ9sTG8H.mjs +462 -0
  313. package/dist/sst-BZ9sTG8H.mjs.map +1 -0
  314. package/dist/sst-D233GoQY.cjs +485 -0
  315. package/dist/sst-D233GoQY.cjs.map +1 -0
  316. package/dist/stack-1yXKqI83.cjs +2287 -0
  317. package/dist/stack-1yXKqI83.cjs.map +1 -0
  318. package/dist/stack-pUz70Rmw.mjs +2124 -0
  319. package/dist/stack-pUz70Rmw.mjs.map +1 -0
  320. package/dist/stage-D6E_TlvR.mjs +302 -0
  321. package/dist/stage-D6E_TlvR.mjs.map +1 -0
  322. package/dist/stage-DAhomyUk.cjs +313 -0
  323. package/dist/stage-DAhomyUk.cjs.map +1 -0
  324. package/dist/stages-Bs1THSy7.cjs +190 -0
  325. package/dist/stages-Bs1THSy7.cjs.map +1 -0
  326. package/dist/stages-_xCG4Ymu.mjs +190 -0
  327. package/dist/stages-_xCG4Ymu.mjs.map +1 -0
  328. package/dist/target/public.cjs +15 -0
  329. package/dist/target/public.d.cts +28 -0
  330. package/dist/target/public.d.cts.map +1 -0
  331. package/dist/target/public.d.mts +28 -0
  332. package/dist/target/public.d.mts.map +1 -0
  333. package/dist/target/public.mjs +4 -0
  334. package/dist/terminal-CKBLsg6b.cjs +85 -0
  335. package/dist/terminal-CKBLsg6b.cjs.map +1 -0
  336. package/dist/terminal-CRinpE1t.mjs +85 -0
  337. package/dist/terminal-CRinpE1t.mjs.map +1 -0
  338. package/dist/types-Bl_CwZC9.cjs +90 -0
  339. package/dist/types-Bl_CwZC9.cjs.map +1 -0
  340. package/dist/{types-BGo5TaNE.d.mts → types-Dk--xVOT.d.cts} +2234 -439
  341. package/dist/types-Dk--xVOT.d.cts.map +1 -0
  342. package/dist/{types-C5ZNpUad.d.cts → types-DwQYpd_0.d.mts} +2232 -439
  343. package/dist/types-DwQYpd_0.d.mts.map +1 -0
  344. package/dist/types-Y1NfWlyG.mjs +61 -0
  345. package/dist/types-Y1NfWlyG.mjs.map +1 -0
  346. package/dist/utils-D2Nk1Nv2.cjs +205 -0
  347. package/dist/utils-D2Nk1Nv2.cjs.map +1 -0
  348. package/dist/utils-D_fxUqvU.mjs +156 -0
  349. package/dist/utils-D_fxUqvU.mjs.map +1 -0
  350. package/dist/vitest.cjs +65 -0
  351. package/dist/vitest.cjs.map +1 -0
  352. package/dist/vitest.d.cts +29 -0
  353. package/dist/vitest.d.cts.map +1 -0
  354. package/dist/vitest.d.mts +29 -0
  355. package/dist/vitest.d.mts.map +1 -0
  356. package/dist/vitest.mjs +65 -0
  357. package/dist/vitest.mjs.map +1 -0
  358. package/dist/workerRuntime-BXfhbe13.cjs +108 -0
  359. package/dist/workerRuntime-BXfhbe13.cjs.map +1 -0
  360. package/dist/workerRuntime-CsOyBRx2.mjs +79 -0
  361. package/dist/workerRuntime-CsOyBRx2.mjs.map +1 -0
  362. package/dist/workspace/index.cjs +6 -2
  363. package/dist/workspace/index.d.cts +3 -3
  364. package/dist/workspace/index.d.mts +3 -3
  365. package/dist/workspace/index.mjs +2 -2
  366. package/dist/workspace-1szcahj9.cjs +2916 -0
  367. package/dist/workspace-1szcahj9.cjs.map +1 -0
  368. package/dist/workspace-DFGsrjGD.mjs +2480 -0
  369. package/dist/workspace-DFGsrjGD.mjs.map +1 -0
  370. package/package.json +66 -14
  371. package/dist/HostingerProvider-BY26bWwB.mjs.map +0 -1
  372. package/dist/HostingerProvider-BZFGYYVA.cjs.map +0 -1
  373. package/dist/LocalStateProvider-7HR6SS2t.cjs +0 -48
  374. package/dist/LocalStateProvider-7HR6SS2t.cjs.map +0 -1
  375. package/dist/LocalStateProvider-D7QyJoLM.mjs +0 -48
  376. package/dist/LocalStateProvider-D7QyJoLM.mjs.map +0 -1
  377. package/dist/Route53Provider-Cvj40A8I.mjs.map +0 -1
  378. package/dist/Route53Provider-DVILBsvV.cjs.map +0 -1
  379. package/dist/SSMStateProvider-B0Hu1MKZ.mjs +0 -75
  380. package/dist/SSMStateProvider-B0Hu1MKZ.mjs.map +0 -1
  381. package/dist/SSMStateProvider-VrQ-yeqd.cjs +0 -74
  382. package/dist/SSMStateProvider-VrQ-yeqd.cjs.map +0 -1
  383. package/dist/backup-provisioner-BmhIO_Yr.cjs.map +0 -1
  384. package/dist/backup-provisioner-DIVCbfee.mjs.map +0 -1
  385. package/dist/bundler-BeNDZdHQ.cjs.map +0 -1
  386. package/dist/bundler-BodTL4kf.mjs.map +0 -1
  387. package/dist/config-Q1rvKHvw.cjs +0 -467
  388. package/dist/config-Q1rvKHvw.cjs.map +0 -1
  389. package/dist/config-pqGD3hF9.mjs +0 -414
  390. package/dist/config-pqGD3hF9.mjs.map +0 -1
  391. package/dist/config.d.cts.map +0 -1
  392. package/dist/config.d.mts.map +0 -1
  393. package/dist/credentials-BekkKtY_.mjs +0 -2780
  394. package/dist/credentials-BekkKtY_.mjs.map +0 -1
  395. package/dist/credentials-Q6F0uqJq.cjs +0 -2917
  396. package/dist/credentials-Q6F0uqJq.cjs.map +0 -1
  397. package/dist/discover-BERGFg8v.cjs +0 -288
  398. package/dist/discover-BERGFg8v.cjs.map +0 -1
  399. package/dist/discover-CK-n3w6b.mjs +0 -244
  400. package/dist/discover-CK-n3w6b.mjs.map +0 -1
  401. package/dist/emit-BdoPFjZf.cjs +0 -253
  402. package/dist/emit-BdoPFjZf.cjs.map +0 -1
  403. package/dist/emit-Bzq7JsMP.mjs +0 -224
  404. package/dist/emit-Bzq7JsMP.mjs.map +0 -1
  405. package/dist/fullstack-secrets-BET8gqwK.mjs +0 -81
  406. package/dist/fullstack-secrets-BET8gqwK.mjs.map +0 -1
  407. package/dist/fullstack-secrets-DXsWO-5m.cjs +0 -92
  408. package/dist/fullstack-secrets-DXsWO-5m.cjs.map +0 -1
  409. package/dist/generator-LfZU7NlU.mjs +0 -247
  410. package/dist/generator-LfZU7NlU.mjs.map +0 -1
  411. package/dist/generator-Wdfp0jCS.cjs +0 -282
  412. package/dist/generator-Wdfp0jCS.cjs.map +0 -1
  413. package/dist/github-BfflNPVe.cjs +0 -203
  414. package/dist/github-BfflNPVe.cjs.map +0 -1
  415. package/dist/github-CRwnxKmD.mjs +0 -203
  416. package/dist/github-CRwnxKmD.mjs.map +0 -1
  417. package/dist/index-Cd-qeOam.d.mts.map +0 -1
  418. package/dist/index-D-iAVHx-.d.cts.map +0 -1
  419. package/dist/keystore-B4PRlbgE.mjs +0 -81
  420. package/dist/keystore-B4PRlbgE.mjs.map +0 -1
  421. package/dist/keystore-DgGRj2Yy.cjs +0 -98
  422. package/dist/keystore-DgGRj2Yy.cjs.map +0 -1
  423. package/dist/openapi-Dcbme-Us.cjs +0 -2038
  424. package/dist/openapi-Dcbme-Us.cjs.map +0 -1
  425. package/dist/openapi-vy4JzhUv.mjs +0 -1991
  426. package/dist/openapi-vy4JzhUv.mjs.map +0 -1
  427. package/dist/storage-C-30BD1e.cjs +0 -272
  428. package/dist/storage-C-30BD1e.cjs.map +0 -1
  429. package/dist/storage-P_b3w7uj.mjs +0 -231
  430. package/dist/storage-P_b3w7uj.mjs.map +0 -1
  431. package/dist/sync-B3xxXtJT.mjs +0 -88
  432. package/dist/sync-B3xxXtJT.mjs.map +0 -1
  433. package/dist/sync-D7uTIIEi.cjs +0 -111
  434. package/dist/sync-D7uTIIEi.cjs.map +0 -1
  435. package/dist/types-BGo5TaNE.d.mts.map +0 -1
  436. package/dist/types-C5ZNpUad.d.cts.map +0 -1
  437. package/dist/workspace-CgwmXEtc.mjs.map +0 -1
  438. package/dist/workspace-mFpI_ky_.cjs.map +0 -1
@@ -0,0 +1,2916 @@
1
+ const require_errors = require("./errors-DMC4Umsb.cjs");
2
+ const require_schemas = require("./schemas-BQ_v0lEX.cjs");
3
+ const require_define = require("./define-crmMcXFS.cjs");
4
+ let node_path = require("node:path");
5
+ let node_net = require("node:net");
6
+ //#region src/compose/dnsConfig.ts
7
+ /**
8
+ * `dns['<root domain>'].records` — how a domain's hosts point at a compose
9
+ * stage's server — checked and read. Pure, and kept apart from the DNS step
10
+ * so the workspace schema checks a config with the same rules and the same
11
+ * named errors the step applies.
12
+ */
13
+ /** The stage-secret key holding the server's public IPv4 address. */
14
+ const SERVER_IPV4_KEY = "GKM_SERVER_IPV4";
15
+ /** The stage-secret key holding the server's public IPv6 address, if any. */
16
+ const SERVER_IPV6_KEY = "GKM_SERVER_IPV6";
17
+ /**
18
+ * Whether a stage secret is gkm's own — the server's address — and so never
19
+ * written into an app's or a worker's environment.
20
+ */
21
+ function isReservedStageKey(key) {
22
+ return key.startsWith("GKM_SERVER_");
23
+ }
24
+ /** A DNS hostname: dot-separated labels of letters, digits and inner '-'. */
25
+ const HOSTNAME = /^(?=.{1,253}$)([a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)(\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/i;
26
+ /** Whether `value` is a DNS hostname with at least two labels. */
27
+ function isHostname(value) {
28
+ return typeof value === "string" && HOSTNAME.test(value);
29
+ }
30
+ /** A CNAME target that is not a hostname under its own domain. */
31
+ var DnsTargetInvalid = class extends require_errors.GkmError {
32
+ domain;
33
+ target;
34
+ stage;
35
+ constructor(domain, target, stage) {
36
+ super(`dns['${domain}'].records.target${stage ? ` for '${stage}'` : ""} is ${JSON.stringify(target)}, which is not a hostname under ${domain}. Every host's CNAME points at it and gkm writes its A record, so it must be a name in the same zone — like 'server.${domain}'.`);
37
+ this.domain = domain;
38
+ this.target = target;
39
+ this.stage = stage;
40
+ this.name = "DnsTargetInvalid";
41
+ }
42
+ };
43
+ /** The CNAME target names under one domain, by the stage they are for, checked. */
44
+ function targets(records) {
45
+ const { target } = records;
46
+ if (target && typeof target === "object" && !Array.isArray(target)) return Object.entries(target);
47
+ return [[void 0, target]];
48
+ }
49
+ /**
50
+ * One domain's records mode checked.
51
+ *
52
+ * @throws {DnsTargetInvalid} for a target that is not a hostname under it
53
+ */
54
+ function checkDnsRecordsMode(domain, records) {
55
+ if (!records || typeof records !== "object") return;
56
+ const mode = records;
57
+ if (mode.mode !== "cname") return;
58
+ for (const [stage, target] of targets(mode)) {
59
+ const name = typeof target === "string" ? target.toLowerCase() : target;
60
+ if (!isHostname(name) || !name.endsWith(`.${domain.toLowerCase()}`)) throw new DnsTargetInvalid(domain, target, stage);
61
+ }
62
+ }
63
+ /**
64
+ * The CNAME target a domain's hosts point at on `stage`, or `undefined` for
65
+ * A records — including a per-stage map that names no target for it.
66
+ */
67
+ function cnameTarget(records, stage) {
68
+ if (!records || records === "a") return void 0;
69
+ return (typeof records.target === "string" ? records.target : records.target[stage])?.toLowerCase();
70
+ }
71
+ /** Where an `every` schedule is counted from: 02:00 UTC. */
72
+ const EVERY_ANCHOR_SECONDS = 7200;
73
+ /** An `every` that is not an interval, or is shorter than an hour. */
74
+ var BackupIntervalInvalid = class extends require_errors.GkmError {
75
+ stage;
76
+ value;
77
+ reason;
78
+ constructor(stage, value, reason) {
79
+ super(`deploy.backups.${stage}.every is '${value}', which ${reason}. Give a number and a unit — '90m', '6h', '1d' — of at least an hour, or a five-field cron expression in UTC: { cron: '0 */6 * * *' }.`);
80
+ this.stage = stage;
81
+ this.value = value;
82
+ this.reason = reason;
83
+ this.name = "BackupIntervalInvalid";
84
+ }
85
+ };
86
+ /** A `cron` that is not a five-field expression, or runs more than hourly. */
87
+ var BackupCronInvalid = class extends require_errors.GkmError {
88
+ stage;
89
+ value;
90
+ reason;
91
+ constructor(stage, value, reason) {
92
+ super(`deploy.backups.${stage}.cron is '${value}', which ${reason}. Give five fields in UTC — minute hour day-of-month month day-of-week, e.g. '0 */6 * * *' — that run at most once an hour.`);
93
+ this.stage = stage;
94
+ this.value = value;
95
+ this.reason = reason;
96
+ this.name = "BackupCronInvalid";
97
+ }
98
+ };
99
+ /** A `keep` that is not a number of days. */
100
+ var BackupRetentionInvalid = class extends require_errors.GkmError {
101
+ stage;
102
+ value;
103
+ constructor(stage, value) {
104
+ super(`deploy.backups.${stage}.keep is '${value}', which is not a number of days. Give one of at least a day: keep: '30d'.`);
105
+ this.stage = stage;
106
+ this.value = value;
107
+ this.name = "BackupRetentionInvalid";
108
+ }
109
+ };
110
+ /** An entry that is neither `false` nor `{ every | cron, keep }`. */
111
+ var BackupsEntryInvalid = class extends require_errors.GkmError {
112
+ stage;
113
+ value;
114
+ reason;
115
+ constructor(stage, value, reason) {
116
+ super(`deploy.backups.${stage} is ${JSON.stringify(value)}, which ${reason}. It takes { every: '6h', keep: '30d' }, { cron: '0 */6 * * *', keep: '30d' }, or false to take no backups.`);
117
+ this.stage = stage;
118
+ this.value = value;
119
+ this.reason = reason;
120
+ this.name = "BackupsEntryInvalid";
121
+ }
122
+ };
123
+ const UNITS = {
124
+ m: 60,
125
+ h: 3600,
126
+ d: 86400
127
+ };
128
+ /** `'6h'` as seconds. */
129
+ function parseInterval(stage, value) {
130
+ const match = /^(\d+)\s*([mhd])$/.exec(value.trim());
131
+ if (!match) throw new BackupIntervalInvalid(stage, value, "is not an interval");
132
+ const seconds = Number(match[1]) * UNITS[match[2]];
133
+ if (seconds < 3600) throw new BackupIntervalInvalid(stage, value, "is shorter than an hour, the shortest interval backups take");
134
+ return seconds;
135
+ }
136
+ /** `'30d'` as days. */
137
+ function parseRetention(stage, value) {
138
+ const match = /^(\d+)\s*d$/.exec(value.trim());
139
+ const days = match ? Number(match[1]) : 0;
140
+ if (!match || days < 1) throw new BackupRetentionInvalid(stage, value);
141
+ return days;
142
+ }
143
+ const CRON_FIELDS = [
144
+ {
145
+ name: "minute",
146
+ min: 0,
147
+ max: 59
148
+ },
149
+ {
150
+ name: "hour",
151
+ min: 0,
152
+ max: 23
153
+ },
154
+ {
155
+ name: "day of month",
156
+ min: 1,
157
+ max: 31
158
+ },
159
+ {
160
+ name: "month",
161
+ min: 1,
162
+ max: 12
163
+ },
164
+ {
165
+ name: "day of week",
166
+ min: 0,
167
+ max: 7
168
+ }
169
+ ];
170
+ /** One cron field's values, or `null` for `*`. */
171
+ function cronField(field, spec) {
172
+ if (field === "*") return null;
173
+ const values = /* @__PURE__ */ new Set();
174
+ for (const part of field.split(",")) {
175
+ const match = /^(\*|(\d+)(?:-(\d+))?)(?:\/(\d+))?$/.exec(part);
176
+ if (!match) return `has '${part}' in its ${spec.name} field`;
177
+ const step = match[4] ? Number(match[4]) : 1;
178
+ if (step < 1) return `steps by 0 in its ${spec.name} field`;
179
+ const from = match[1] === "*" ? spec.min : Number(match[2]);
180
+ const to = match[1] === "*" ? spec.max : match[3] !== void 0 ? Number(match[3]) : match[4] ? spec.max : from;
181
+ if (from < spec.min || to > spec.max || from > to) return `has '${part}' in its ${spec.name} field, outside ${spec.min}-${spec.max}`;
182
+ for (let value = from; value <= to; value += step) values.add(value);
183
+ }
184
+ return [...values].sort((a, b) => a - b);
185
+ }
186
+ /** A five-field cron expression, expanded. */
187
+ function parseCron(stage, expression) {
188
+ const fields = expression.trim().split(/\s+/);
189
+ if (fields.length !== 5) throw new BackupCronInvalid(stage, expression, `has ${fields.length} field${fields.length === 1 ? "" : "s"}, not five`);
190
+ const parsed = fields.map((field, i) => cronField(field, CRON_FIELDS[i]));
191
+ const problem = parsed.find((p) => typeof p === "string");
192
+ if (typeof problem === "string") throw new BackupCronInvalid(stage, expression, problem);
193
+ const [minutes, hours, days, months, weekdays] = parsed;
194
+ return {
195
+ kind: "cron",
196
+ expression: fields.join(" "),
197
+ minutes: minutes ?? range(0, 59),
198
+ hours: hours ?? range(0, 23),
199
+ days: days ?? null,
200
+ months: months ?? null,
201
+ weekdays: weekdays ? [...new Set(weekdays.map((d) => d % 7))].sort((a, b) => a - b) : null
202
+ };
203
+ }
204
+ function range(from, to) {
205
+ return Array.from({ length: to - from + 1 }, (_, i) => from + i);
206
+ }
207
+ /** Whether a cron schedule runs on the UTC day of `date`. */
208
+ function cronDay(schedule, date) {
209
+ if (schedule.months && !schedule.months.includes(date.getUTCMonth() + 1)) return false;
210
+ const dom = schedule.days?.includes(date.getUTCDate());
211
+ const dow = schedule.weekdays?.includes(date.getUTCDay());
212
+ if (schedule.days && schedule.weekdays) return Boolean(dom || dow);
213
+ if (schedule.days) return Boolean(dom);
214
+ if (schedule.weekdays) return Boolean(dow);
215
+ return true;
216
+ }
217
+ /** How far ahead a cron schedule is looked for its next run: four years. */
218
+ const CRON_HORIZON_DAYS = 1464;
219
+ /**
220
+ * The first time after `after` (to the minute) the schedule runs, or `null`
221
+ * when it does not within four years.
222
+ *
223
+ * The container's runner (`runner.ts`) keeps a copy of this, since it ships
224
+ * alone; a test holds the two to the same answers.
225
+ */
226
+ function nextRun(schedule, after) {
227
+ const from = Math.floor(after.getTime() / 6e4) * 6e4 + 6e4;
228
+ if (schedule.kind === "every") {
229
+ const interval = schedule.seconds * 1e3;
230
+ const offset = schedule.offset * 1e3;
231
+ const k = Math.ceil((from - offset) / interval);
232
+ return new Date(offset + k * interval);
233
+ }
234
+ const start = new Date(from);
235
+ const day = Date.UTC(start.getUTCFullYear(), start.getUTCMonth(), start.getUTCDate());
236
+ for (let i = 0; i < CRON_HORIZON_DAYS; i++) {
237
+ const date = new Date(day + i * 864e5);
238
+ if (!cronDay(schedule, date)) continue;
239
+ for (const hour of schedule.hours) for (const minute of schedule.minutes) {
240
+ const at = date.getTime() + hour * 36e5 + minute * 6e4;
241
+ if (at >= from) return new Date(at);
242
+ }
243
+ }
244
+ return null;
245
+ }
246
+ /**
247
+ * The shortest and longest a schedule goes between two runs, in seconds,
248
+ * over the four years from 2026 — leap days and month ends included — or
249
+ * `null` when it does not run twice in them.
250
+ */
251
+ function scheduleGaps(schedule) {
252
+ if (schedule.kind === "every") return {
253
+ shortest: schedule.seconds,
254
+ longest: schedule.seconds
255
+ };
256
+ const start = Date.UTC(2026, 0, 1);
257
+ const end = start + CRON_HORIZON_DAYS * 864e5;
258
+ let previous;
259
+ let longest = 0;
260
+ let shortest = Number.POSITIVE_INFINITY;
261
+ let at = /* @__PURE__ */ new Date(start - 6e4);
262
+ while (at && at.getTime() < end) {
263
+ at = nextRun(schedule, at);
264
+ if (!at) break;
265
+ if (previous !== void 0) {
266
+ longest = Math.max(longest, at.getTime() - previous);
267
+ shortest = Math.min(shortest, at.getTime() - previous);
268
+ if (shortest < 36e5) break;
269
+ }
270
+ previous = at.getTime();
271
+ }
272
+ if (longest === 0) return null;
273
+ return {
274
+ shortest: shortest / 1e3,
275
+ longest: longest / 1e3
276
+ };
277
+ }
278
+ /** `21600` as `6h`, `86400` as `1d`. */
279
+ function duration(seconds) {
280
+ if (seconds % 86400 === 0) return `${seconds / 86400}d`;
281
+ if (seconds % 3600 === 0) return `${seconds / 3600}h`;
282
+ return `${seconds / 60}m`;
283
+ }
284
+ /**
285
+ * One stage's entry, checked and resolved: `false`, or its schedule and
286
+ * retention — the defaults filling what it leaves out.
287
+ *
288
+ * @throws {BackupsEntryInvalid} for an entry of the wrong shape
289
+ * @throws {BackupIntervalInvalid} for an `every` that is not an interval of an hour or more
290
+ * @throws {BackupCronInvalid} for a `cron` that is not five fields, or runs more than hourly
291
+ * @throws {BackupRetentionInvalid} for a `keep` that is not days
292
+ */
293
+ function checkStageBackups(stage, value) {
294
+ if (value === false) return false;
295
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new BackupsEntryInvalid(stage, value, "is not an entry");
296
+ const entry = value;
297
+ const unknown = Object.keys(entry).filter((key) => ![
298
+ "every",
299
+ "cron",
300
+ "keep"
301
+ ].includes(key));
302
+ if (unknown.length > 0) throw new BackupsEntryInvalid(stage, value, `has ${unknown.map((k) => `'${k}'`).join(", ")}, which it does not take`);
303
+ for (const key of [
304
+ "every",
305
+ "cron",
306
+ "keep"
307
+ ]) if (entry[key] !== void 0 && typeof entry[key] !== "string") throw new BackupsEntryInvalid(stage, value, `has a ${key} that is not text`);
308
+ if (entry.every !== void 0 && entry.cron !== void 0) throw new BackupsEntryInvalid(stage, value, "gives both every and cron; give one");
309
+ const keepDays = parseRetention(stage, entry.keep ?? "30d");
310
+ if (typeof entry.cron === "string") {
311
+ const schedule = parseCron(stage, entry.cron);
312
+ const gaps = scheduleGaps(schedule);
313
+ if (!gaps) throw new BackupCronInvalid(stage, entry.cron, "does not run twice in four years");
314
+ if (gaps.shortest < 3600) throw new BackupCronInvalid(stage, entry.cron, `runs ${duration(gaps.shortest)} apart at its closest, more often than once an hour`);
315
+ return {
316
+ schedule,
317
+ keepDays,
318
+ maxGapSeconds: gaps.longest,
319
+ describe: `cron '${schedule.expression}' (UTC), kept ${keepDays} days`
320
+ };
321
+ }
322
+ const seconds = parseInterval(stage, entry.every ?? "1d");
323
+ return {
324
+ schedule: {
325
+ kind: "every",
326
+ seconds,
327
+ offset: EVERY_ANCHOR_SECONDS
328
+ },
329
+ keepDays,
330
+ maxGapSeconds: seconds,
331
+ describe: `every ${duration(seconds)} from 02:00 UTC, kept ${keepDays} days`
332
+ };
333
+ }
334
+ //#endregion
335
+ //#region src/secrets/providers.ts
336
+ /**
337
+ * The secrets stores gkm ships, by name — with no imports, so the config
338
+ * loader can check `secrets.store` without loading any store.
339
+ */
340
+ /** The stores this package ships, by the name `secrets.store` gives them. */
341
+ const SECRETS_STORE_PROVIDERS = [
342
+ "file",
343
+ "ssm",
344
+ "secrets-manager",
345
+ "s3"
346
+ ];
347
+ /**
348
+ * `secrets.store` names a provider this package does not ship — a typo such
349
+ * as `'secretsmanager'` or `'ssm-parameter'`. Refused rather than read as the
350
+ * file, which would leave a deployed stage's secrets on one machine.
351
+ */
352
+ var UnknownSecretsStoreProvider = class extends require_errors.GkmError {
353
+ provider;
354
+ constructor(provider) {
355
+ super(`secrets.store names the provider ${JSON.stringify(provider)}, which is not one gkm ships. Use 'file', { provider: 's3' }, { provider: 'ssm', region }, { provider: 'secrets-manager', region }, or { provider: <an object with name, read() and write()> } in gkm.config.ts.`);
356
+ this.provider = provider;
357
+ this.name = "UnknownSecretsStoreProvider";
358
+ }
359
+ };
360
+ /**
361
+ * Refuse a `secrets.store` naming a provider that is not one, before the
362
+ * schema reduces it to a generic validation failure.
363
+ */
364
+ function assertKnownSecretsStore(store) {
365
+ if (store === void 0) return;
366
+ const provider = typeof store === "object" && store !== null && "provider" in store ? store.provider : store;
367
+ if (typeof provider === "string" && !SECRETS_STORE_PROVIDERS.includes(provider)) throw new UnknownSecretsStoreProvider(provider);
368
+ }
369
+ /**
370
+ * An `s3` secrets store names no region, and the deploy state is not in S3 to
371
+ * take one from.
372
+ */
373
+ var S3SecretsStoreNeedsRegion = class extends require_errors.GkmError {
374
+ constructor() {
375
+ super("secrets.store is { provider: 's3' } with no region, and the deploy state is not in S3 to take one from. Name it — secrets: { store: { provider: 's3', region: '<region>' } } — or keep the state beside it: state: { provider: 's3', region: '<region>' }.");
376
+ this.name = "S3SecretsStoreNeedsRegion";
377
+ }
378
+ };
379
+ /**
380
+ * Where an `s3` store keeps a stage's secrets. With no bucket named it is the
381
+ * project bucket, beside the deploy state; region and prefix default to the
382
+ * state's when that is in S3 too, so the two are written once.
383
+ *
384
+ * @throws {S3SecretsStoreNeedsRegion} when no region is named or inherited
385
+ */
386
+ function s3SecretsLocation(store, state) {
387
+ const s3State = typeof state === "object" && state !== null && state.provider === "s3" ? state : void 0;
388
+ const region = store.region ?? s3State?.region;
389
+ if (!region) throw new S3SecretsStoreNeedsRegion();
390
+ return {
391
+ bucket: store.bucket,
392
+ region,
393
+ prefix: (store.prefix ?? s3State?.prefix ?? "gkm").replace(/\/+$/, "")
394
+ };
395
+ }
396
+ /** The key a stage's secrets are kept at: `<prefix>/<project>/<stage>/secrets.json`. */
397
+ function s3SecretsKey(prefix, project, stage) {
398
+ const path = `${project}/${stage}/secrets.json`;
399
+ return prefix ? `${prefix}/${path}` : path;
400
+ }
401
+ //#endregion
402
+ //#region src/compose/proxy.ts
403
+ /**
404
+ * Which proxy a stage's stack is served by, and with whose certificate —
405
+ * `deploy.compose.proxy` and `deploy.compose.tls`, resolved for one stage.
406
+ *
407
+ * Pure, and kept apart from the stack so the workspace schema can check a
408
+ * config with the same rules — and the same named errors — the stack applies.
409
+ */
410
+ /** A per-stage setting keyed by a stage the workspace does not have. */
411
+ var ComposeStageUnknown = class extends require_errors.GkmError {
412
+ setting;
413
+ stage;
414
+ stages;
415
+ constructor(setting, stage, stages) {
416
+ super(`deploy.compose.${setting} names the stage '${stage}', which is not one of this workspace's (${stages.join(", ")}). Use a stage from stages.local or stages.deployed.`);
417
+ this.setting = setting;
418
+ this.stage = stage;
419
+ this.stages = stages;
420
+ this.name = "ComposeStageUnknown";
421
+ }
422
+ };
423
+ /**
424
+ * A server for the local stage, which always runs on this machine's Docker.
425
+ */
426
+ var ComposeServerOnLocalStage = class extends require_errors.GkmError {
427
+ stage;
428
+ constructor(stage) {
429
+ super(`deploy.compose.server names '${stage}', the local stage, which always runs on this machine's Docker. Remove it, or set it for a deployed stage.`);
430
+ this.stage = stage;
431
+ this.name = "ComposeServerOnLocalStage";
432
+ }
433
+ };
434
+ /** The stage's certificate or key file is not there to read. */
435
+ var ComposeTlsFileMissing = class extends require_errors.GkmError {
436
+ stage;
437
+ file;
438
+ constructor(stage, file) {
439
+ super(`deploy.compose.tls for '${stage}' names ${file}, and there is no file there. Point certFile and keyFile at the PEM certificate (with its chain) and key, and caFile at the root it chains to where you set one — relative to the workspace root, or absolute.`);
440
+ this.stage = stage;
441
+ this.file = file;
442
+ this.name = "ComposeTlsFileMissing";
443
+ }
444
+ };
445
+ /**
446
+ * The proxy a stage's stack is served by: Caddy unless `deploy.compose.proxy`
447
+ * says otherwise. The plain string form is for the deployed stages — a
448
+ * server's shared edge — so the local stage stays on its own Caddy then; it
449
+ * runs behind a Traefik edge on this machine only when the per-stage map
450
+ * names it (`proxy: { development: 'traefik', production: 'traefik' }`).
451
+ */
452
+ function proxyFor(config, stage, local) {
453
+ const proxy = config?.proxy;
454
+ if (!proxy) return "caddy";
455
+ if (typeof proxy === "string") return local ? "caddy" : proxy;
456
+ return proxy[stage] ?? "caddy";
457
+ }
458
+ /**
459
+ * A stage's own certificate, its paths absolute, when it sets one — any
460
+ * stage's, the local one's included, served by either proxy.
461
+ */
462
+ function certificateFor(config, stage, root) {
463
+ const tls = config?.tls?.[stage];
464
+ if (!tls) return void 0;
465
+ const absolute = (file) => (0, node_path.isAbsolute)(file) ? file : (0, node_path.resolve)(root, file);
466
+ return {
467
+ certFile: absolute(tls.certFile),
468
+ keyFile: absolute(tls.keyFile),
469
+ ...tls.caFile ? { caFile: absolute(tls.caFile) } : {}
470
+ };
471
+ }
472
+ /**
473
+ * Throws the named error for the first thing wrong with the per-stage
474
+ * settings: a stage the workspace does not have, or a server for the local
475
+ * stage.
476
+ */
477
+ function checkComposeStages(config, stages) {
478
+ const known = [stages.local, ...stages.deployed];
479
+ if (config?.proxy && typeof config.proxy === "object") {
480
+ for (const stage of Object.keys(config.proxy)) if (!known.includes(stage)) throw new ComposeStageUnknown("proxy", stage, known);
481
+ }
482
+ for (const stage of Object.keys(config?.tls ?? {})) if (!known.includes(stage)) throw new ComposeStageUnknown("tls", stage, known);
483
+ for (const stage of Object.keys(config?.server ?? {})) {
484
+ if (stage === stages.local) throw new ComposeServerOnLocalStage(stage);
485
+ if (!known.includes(stage)) throw new ComposeStageUnknown("server", stage, known);
486
+ }
487
+ }
488
+ //#endregion
489
+ //#region src/providers/s3/errors.ts
490
+ /** What the `s3` provider refuses, and how each is put right. */
491
+ /** An `objects` entry for `s3` with a field it does not take or cannot use. */
492
+ var S3ProviderConfigInvalid = class extends require_errors.GkmError {
493
+ stage;
494
+ field;
495
+ value;
496
+ expected;
497
+ constructor(stage, field, value, expected) {
498
+ super(`deploy.objects.${stage}.${field} is ${JSON.stringify(value)}; ${expected}.`);
499
+ this.stage = stage;
500
+ this.field = field;
501
+ this.value = value;
502
+ this.expected = expected;
503
+ this.name = "S3ProviderConfigInvalid";
504
+ }
505
+ };
506
+ /** No region anywhere to create the stage's buckets in. */
507
+ var S3RegionRequired = class extends require_errors.GkmError {
508
+ stage;
509
+ constructor(stage) {
510
+ super(`The s3 provider has no region for the stage '${stage}'. Name one in gkm.config.ts: deploy: { objects: { ${stage}: { provider: 's3', region: 'eu-west-1' } } } — or set AWS_REGION.`);
511
+ this.stage = stage;
512
+ this.name = "S3RegionRequired";
513
+ }
514
+ };
515
+ /** The good name and every suffixed one are taken by other accounts. */
516
+ var BucketNameUnavailable = class extends require_errors.GkmError {
517
+ id;
518
+ tried;
519
+ constructor(id, tried) {
520
+ super(`Every name tried for the bucket '${id}' is taken by another AWS account: ${tried.join(", ")}. Set deploy.namespace in gkm.config.ts to something more particular to you, and run the provision again.`);
521
+ this.id = id;
522
+ this.tried = tried;
523
+ this.name = "BucketNameUnavailable";
524
+ }
525
+ };
526
+ /** A bucket in this account carries another project's tag. */
527
+ var BucketOwnedByAnotherProject = class extends require_errors.GkmError {
528
+ bucket;
529
+ owner;
530
+ project;
531
+ constructor(bucket, owner, project) {
532
+ super(`The bucket '${bucket}' is in this account and tagged gkm:project=${owner}, not ${project}: another project's. gkm never adopts it. Set deploy.namespace in gkm.config.ts so this project names its buckets differently.`);
533
+ this.bucket = bucket;
534
+ this.owner = owner;
535
+ this.project = project;
536
+ this.name = "BucketOwnedByAnotherProject";
537
+ }
538
+ };
539
+ /** The bucket the stage's state names exists, and this account cannot reach it. */
540
+ var RecordedBucketUnreachable = class extends require_errors.GkmError {
541
+ id;
542
+ bucket;
543
+ constructor(id, bucket) {
544
+ super(`The stage's state records '${bucket}' as the bucket for '${id}', and this account cannot reach it — it is in another account, or the credentials are not the stage account's. Run with the account that created it (--profile).`);
545
+ this.id = id;
546
+ this.bucket = bucket;
547
+ this.name = "RecordedBucketUnreachable";
548
+ }
549
+ };
550
+ /** An IAM user by gkm's name exists, and gkm did not create it for this stage. */
551
+ var IamUserNotOwned = class extends require_errors.GkmError {
552
+ user;
553
+ project;
554
+ stage;
555
+ constructor(user, project, stage) {
556
+ super(`The IAM user '${user}' exists and is not tagged gkm:project=${project}, gkm:stage=${stage}, so gkm leaves it alone. Rename or delete it, or set deploy.namespace in gkm.config.ts so gkm names its users differently.`);
557
+ this.user = user;
558
+ this.project = project;
559
+ this.stage = stage;
560
+ this.name = "IamUserNotOwned";
561
+ }
562
+ };
563
+ /** The user already has the two access keys IAM allows. */
564
+ var AccessKeyLimit = class extends require_errors.GkmError {
565
+ user;
566
+ keys;
567
+ constructor(user, keys) {
568
+ super(`The IAM user '${user}' already has two access keys (${keys.join(", ")}), the most IAM allows, and gkm needs to issue one. Delete the one the stage does not use (aws iam delete-access-key --user-name ${user} --access-key-id …), then run the provision again.`);
569
+ this.user = user;
570
+ this.keys = keys;
571
+ this.name = "AccessKeyLimit";
572
+ }
573
+ };
574
+ /** `--rotate-keys` while the last rotation's old key is still active. */
575
+ var RotationInProgress = class extends require_errors.GkmError {
576
+ id;
577
+ previous;
578
+ stage;
579
+ constructor(id, previous, stage) {
580
+ super(`The bucket '${id}' is mid-rotation: its old key ${previous} is still active until '${stage}' is deployed with the new one: deploy it (gkm deploy --stage ${stage}) — the next deploy after that deletes the old key — or pass --retire-old-keys to delete it now, before rotating again.`);
581
+ this.id = id;
582
+ this.previous = previous;
583
+ this.stage = stage;
584
+ this.name = "RotationInProgress";
585
+ }
586
+ };
587
+ /** The stage's secrets point the bucket's key at a bucket gkm did not provision. */
588
+ var BucketKeySetElsewhere = class extends require_errors.GkmError {
589
+ key;
590
+ bucket;
591
+ found;
592
+ stage;
593
+ constructor(key, bucket, found, stage) {
594
+ super(`${key} in the stage '${stage}' points at the bucket '${found}', and the s3 provider manages '${bucket}' for it. Remove the key (gkm secrets:unset ${key} --stage ${stage}) to have the provider write its own, or set deploy.objects.${stage} to 'external' to keep yours.`);
595
+ this.key = key;
596
+ this.bucket = bucket;
597
+ this.found = found;
598
+ this.stage = stage;
599
+ this.name = "BucketKeySetElsewhere";
600
+ }
601
+ };
602
+ /** `verify()`: a provisioned bucket the stage's key cannot reach. */
603
+ var ProvisionedBucketUnreachable = class extends require_errors.GkmError {
604
+ id;
605
+ bucket;
606
+ stage;
607
+ reason;
608
+ constructor(id, bucket, stage, reason) {
609
+ super(`The bucket '${bucket}' (${id}) cannot be reached with the key in the stage '${stage}''s secrets: ${reason}. Deploy '${stage}' with the stage account's credentials (gkm deploy --stage ${stage}), which creates or repairs it.`);
610
+ this.id = id;
611
+ this.bucket = bucket;
612
+ this.stage = stage;
613
+ this.reason = reason;
614
+ this.name = "ProvisionedBucketUnreachable";
615
+ }
616
+ };
617
+ /**
618
+ * `verify()`: the bucket answers from another region than the one its URL
619
+ * names — S3 redirects (301) or refuses the signature (400) and says where
620
+ * the bucket is.
621
+ */
622
+ var BucketRegionMismatch = class extends require_errors.GkmError {
623
+ id;
624
+ bucket;
625
+ stage;
626
+ key;
627
+ bucketRegion;
628
+ urlRegion;
629
+ askedRegion;
630
+ answer;
631
+ constructor(id, bucket, stage, key, bucketRegion, urlRegion, askedRegion, answer) {
632
+ const says = urlRegion ? `says ${urlRegion}` : `names no region, so ${askedRegion} was asked`;
633
+ super(`The bucket '${bucket}' (${id}) is in ${bucketRegion}, but ${key} in the stage '${stage}''s secrets ${says} (${answer}). Deploy '${stage}' with the stage account's credentials (gkm deploy --stage ${stage}): the s3 provider reads the bucket's region and rewrites ${key} with it. Set deploy.objects.${stage}.region to '${bucketRegion}' in gkm.config.ts so the stage's config says where its buckets are.`);
634
+ this.id = id;
635
+ this.bucket = bucket;
636
+ this.stage = stage;
637
+ this.key = key;
638
+ this.bucketRegion = bucketRegion;
639
+ this.urlRegion = urlRegion;
640
+ this.askedRegion = askedRegion;
641
+ this.answer = answer;
642
+ this.name = "BucketRegionMismatch";
643
+ }
644
+ };
645
+ /** Neither `HeadBucket` nor `GetBucketLocation` says where a bucket is. */
646
+ var BucketRegionUnknown = class extends require_errors.GkmError {
647
+ bucket;
648
+ head;
649
+ location;
650
+ constructor(bucket, head, location) {
651
+ super(`gkm cannot tell which region the bucket '${bucket}' is in: HeadBucket answered ${head}, and GetBucketLocation ${location}. Check that the provisioning credentials are the stage account's and may call s3:GetBucketLocation on it, then run the deploy again.`);
652
+ this.bucket = bucket;
653
+ this.head = head;
654
+ this.location = location;
655
+ this.name = "BucketRegionUnknown";
656
+ }
657
+ };
658
+ /** `HeadBucket` answered neither yes, no, nor "another account's". */
659
+ var BucketProbeFailed = class extends require_errors.GkmError {
660
+ bucket;
661
+ answer;
662
+ constructor(bucket, answer) {
663
+ super(`gkm asked S3 whether the bucket '${bucket}' exists and got ${answer}. Check the provisioning credentials and the stage's region, then run the deploy again.`);
664
+ this.bucket = bucket;
665
+ this.answer = answer;
666
+ this.name = "BucketProbeFailed";
667
+ }
668
+ };
669
+ //#endregion
670
+ //#region src/providers/s3/config.ts
671
+ const FIELDS$1 = [
672
+ "provider",
673
+ "region",
674
+ "versioning",
675
+ "cdn"
676
+ ];
677
+ /** An AWS region code: `eu-west-1`, `us-gov-west-1`, `ap-southeast-4`. */
678
+ const REGION$1 = /^[a-z]{2}(-[a-z]+)+-\d+$/;
679
+ function checkS3Config(stage, config) {
680
+ const entry = config;
681
+ for (const field of Object.keys(entry)) if (!FIELDS$1.includes(field)) throw new S3ProviderConfigInvalid(stage, field, entry[field], `the s3 provider takes ${FIELDS$1.slice(1).join(", ")} only`);
682
+ if (entry.region !== void 0) {
683
+ if (typeof entry.region !== "string" || !REGION$1.test(entry.region)) throw new S3ProviderConfigInvalid(stage, "region", entry.region, "set it to an AWS region code, like 'eu-west-1'");
684
+ }
685
+ if (entry.versioning !== void 0 && typeof entry.versioning !== "boolean") throw new S3ProviderConfigInvalid(stage, "versioning", entry.versioning, "set it to true to keep previous versions of every object, or leave it out");
686
+ if (entry.cdn !== void 0 && typeof entry.cdn !== "boolean") throw new S3ProviderConfigInvalid(stage, "cdn", entry.cdn, "set it to false to serve file servers from the bucket's own endpoint, or leave it out");
687
+ return entry;
688
+ }
689
+ /** How the s3 provider's provisioning credentials are supplied. */
690
+ const S3_PROVISIONING = {
691
+ env: [
692
+ "AWS_PROFILE",
693
+ "AWS_ACCESS_KEY_ID",
694
+ "AWS_SECRET_ACCESS_KEY",
695
+ "AWS_SESSION_TOKEN"
696
+ ],
697
+ describe: "the stage's AWS account — AWS_PROFILE, or AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY (in CI, what aws-actions/configure-aws-credentials exports)"
698
+ };
699
+ //#endregion
700
+ //#region src/providers/ses/errors.ts
701
+ /** `deploy.inbox.<stage>` holds a field the `ses` provider does not take. */
702
+ var SesProviderConfigInvalid = class extends require_errors.GkmError {
703
+ stage;
704
+ field;
705
+ value;
706
+ expected;
707
+ constructor(stage, field, value, expected) {
708
+ super(`deploy.inbox.${stage}.${field} is ${JSON.stringify(value)}; ${expected}.`);
709
+ this.stage = stage;
710
+ this.field = field;
711
+ this.value = value;
712
+ this.expected = expected;
713
+ this.name = "SesProviderConfigInvalid";
714
+ }
715
+ };
716
+ /** The stage's region is one SES does not receive mail in. */
717
+ var SesReceivingUnsupported = class extends require_errors.GkmError {
718
+ stage;
719
+ region;
720
+ regions;
721
+ constructor(stage, region, regions) {
722
+ super(`'${stage}' is in ${region}, where SES does not receive mail. Set deploy.inbox.${stage}.region to one that does: ${regions.join(", ")}.`);
723
+ this.stage = stage;
724
+ this.region = region;
725
+ this.regions = regions;
726
+ this.name = "SesReceivingUnsupported";
727
+ }
728
+ };
729
+ /** An inbox whose keys the stage's secrets do not hold: not provisioned yet. */
730
+ var InboxNotProvisioned = class extends require_errors.GkmError {
731
+ stage;
732
+ inbox;
733
+ missing;
734
+ constructor(stage, inbox, missing) {
735
+ super(`'${inbox}' has no ${missing.join(" or ")} in '${stage}''s secrets, so it receives nothing. Deploy the stage with credentials for its AWS account: the ses provider creates the inbox and writes them.`);
736
+ this.stage = stage;
737
+ this.inbox = inbox;
738
+ this.missing = missing;
739
+ this.name = "InboxNotProvisioned";
740
+ }
741
+ };
742
+ //#endregion
743
+ //#region src/providers/ses/config.ts
744
+ const FIELDS = ["provider", "region"];
745
+ const REGION = /^[a-z]{2}(-[a-z]+)+-\d+$/;
746
+ function checkSesConfig(stage, config) {
747
+ const entry = config;
748
+ for (const field of Object.keys(entry)) if (!FIELDS.includes(field)) throw new SesProviderConfigInvalid(stage, field, entry[field], `the ses provider takes ${FIELDS.slice(1).join(", ")} only`);
749
+ if (entry.region !== void 0 && (typeof entry.region !== "string" || !REGION.test(entry.region))) throw new SesProviderConfigInvalid(stage, "region", entry.region, "set it to an AWS region code SES receives mail in, like 'eu-west-1'");
750
+ return entry;
751
+ }
752
+ /** The stage's AWS account, as every AWS provider asks for it. */
753
+ const SES_PROVISIONING = S3_PROVISIONING;
754
+ //#endregion
755
+ //#region src/providers/config.ts
756
+ /**
757
+ * `deploy.<kind>.<stage>`, read: what backs one kind of construct on a stage.
758
+ *
759
+ * Kept free of the providers themselves — of the AWS SDK and the graph — so
760
+ * the workspace schema can check an entry with the words a deploy would use,
761
+ * the way `checkStageTelemetry` does for `deploy.telemetry`.
762
+ */
763
+ /** Each provider's config check, by kind and name. */
764
+ const CHECKS = {
765
+ objects: { s3: checkS3Config },
766
+ inbox: { ses: checkSesConfig }
767
+ };
768
+ /** How each provider's provisioning credentials are supplied, by kind and name. */
769
+ const PROVISIONING = {
770
+ objects: { s3: S3_PROVISIONING },
771
+ inbox: { ses: SES_PROVISIONING }
772
+ };
773
+ /** How `name`'s provisioning credentials are supplied, for messages. */
774
+ function provisioningOf(kind, name) {
775
+ return Object.hasOwn(PROVISIONING[kind], name) ? PROVISIONING[kind][name] : void 0;
776
+ }
777
+ /** The `provider:` names a kind accepts. */
778
+ function providerNamesOf(kind) {
779
+ return Object.keys(CHECKS[kind]).sort();
780
+ }
781
+ /** What `deploy.<kind>.<stage>` may be, for messages. */
782
+ function accepted(kind) {
783
+ return [
784
+ "'external'",
785
+ ...providerNamesOf(kind).map((name) => `{ provider: '${name}' }`),
786
+ "false"
787
+ ].join(", ");
788
+ }
789
+ /** An entry that names no provider gkm has, or is not an entry at all. */
790
+ var UnknownStageProvider = class extends require_errors.GkmError {
791
+ kind;
792
+ stage;
793
+ value;
794
+ constructor(kind, stage, value) {
795
+ super(`deploy.${kind}.${stage} is ${JSON.stringify(value)}, which is not a provider gkm has for ${kind}. It takes ${accepted(kind)}.`);
796
+ this.kind = kind;
797
+ this.stage = stage;
798
+ this.value = value;
799
+ this.name = "UnknownStageProvider";
800
+ }
801
+ };
802
+ /**
803
+ * One stage's entry checked: `'external'`, `false`, or a provider's object
804
+ * that its own check accepts.
805
+ *
806
+ * @throws {UnknownStageProvider} for anything else — `'minio'` included
807
+ */
808
+ function checkStageProvider(kind, stage, value) {
809
+ if (value === "external" || value === false) return value;
810
+ if (value && typeof value === "object" && !Array.isArray(value)) {
811
+ const name = value.provider;
812
+ const check = typeof name === "string" && Object.hasOwn(CHECKS[kind], name) ? CHECKS[kind][name] : void 0;
813
+ if (check) return check(stage, value);
814
+ }
815
+ throw new UnknownStageProvider(kind, stage, value);
816
+ }
817
+ /**
818
+ * What backs `kind` on `stage`: the local stage is always `external` here —
819
+ * `gkm dev` runs its own — and a deployed stage that names nothing is too.
820
+ */
821
+ function stageProvider(workspace, kind, stage) {
822
+ if (stage === workspace.stages?.local) return { mode: "external" };
823
+ const value = workspace.deploy?.[kind]?.[stage];
824
+ if (value === void 0) return { mode: "external" };
825
+ const entry = checkStageProvider(kind, stage, value);
826
+ if (entry === "external") return { mode: "external" };
827
+ if (entry === false) return { mode: "none" };
828
+ return {
829
+ mode: "provider",
830
+ name: entry.provider,
831
+ config: entry
832
+ };
833
+ }
834
+ //#endregion
835
+ //#region src/compose/logsConfig.ts
836
+ /**
837
+ * The self-hosted telemetry provider's options, read: how the stack's
838
+ * OpenObserve is run and reached — `deploy.telemetry.<stage>` with
839
+ * `provider: 'self-hosted'`.
840
+ *
841
+ * Kept apart from the stack so the workspace schema can check a config with
842
+ * the same rules — and the same named errors — the stack applies.
843
+ */
844
+ /** The port OpenObserve listens on, and the one it is published on by default. */
845
+ const LOGS_PORT = 5080;
846
+ /** `public` with no address to allow: nobody could reach it. */
847
+ var LogsAllowEmpty = class extends require_errors.GkmError {
848
+ stage;
849
+ constructor(stage) {
850
+ super(`deploy.telemetry.${stage}.public.allow is empty, so the logs site would answer every request with 403. List the addresses that may reach it (public: { allow: ['203.0.113.7', '10.0.0.0/8'] }), or remove public and reach it through an SSH tunnel.`);
851
+ this.stage = stage;
852
+ this.name = "LogsAllowEmpty";
853
+ }
854
+ };
855
+ /** An `allow` entry that is not an IP address or a CIDR range. */
856
+ var LogsAllowEntryInvalid = class extends require_errors.GkmError {
857
+ stage;
858
+ entry;
859
+ constructor(stage, entry) {
860
+ super(`deploy.telemetry.${stage}.public.allow has '${entry}', which is not an IP address or a CIDR range. Write one like '203.0.113.7', '10.0.0.0/8' or '2001:db8::/32'.`);
861
+ this.stage = stage;
862
+ this.entry = entry;
863
+ this.name = "LogsAllowEntryInvalid";
864
+ }
865
+ };
866
+ /** A retention OpenObserve would refuse to start with. */
867
+ var LogsRetentionInvalid = class extends require_errors.GkmError {
868
+ stage;
869
+ retentionDays;
870
+ constructor(stage, retentionDays) {
871
+ super(`deploy.telemetry.${stage}.retentionDays is ${String(retentionDays)}; it must be a whole number of days, at least 3 — OpenObserve refuses to start with fewer. Leave it out for 30.`);
872
+ this.stage = stage;
873
+ this.retentionDays = retentionDays;
874
+ this.name = "LogsRetentionInvalid";
875
+ }
876
+ };
877
+ /** A port that is not one. */
878
+ var LogsPortInvalid = class extends require_errors.GkmError {
879
+ stage;
880
+ port;
881
+ constructor(stage, port) {
882
+ super(`deploy.telemetry.${stage}.port is ${String(port)}; set it to a number between 1 and 65535, or leave it out for ${LOGS_PORT}.`);
883
+ this.stage = stage;
884
+ this.port = port;
885
+ this.name = "LogsPortInvalid";
886
+ }
887
+ };
888
+ /** Whether `entry` is an IP address, or an address and a prefix length. */
889
+ function isAddressOrRange(entry) {
890
+ const [address = "", prefix, ...rest] = entry.split("/");
891
+ if (rest.length > 0) return false;
892
+ const family = (0, node_net.isIP)(address);
893
+ if (family === 0) return false;
894
+ if (prefix === void 0) return true;
895
+ if (!/^\d{1,3}$/.test(prefix)) return false;
896
+ return Number(prefix) <= (family === 4 ? 32 : 128);
897
+ }
898
+ /**
899
+ * The self-hosted provider's options with their defaults — `{}` for all of
900
+ * them. Throws the named error for the first thing wrong with them.
901
+ */
902
+ function resolveSelfHosted(config, stage) {
903
+ const port = config.port ?? 5080;
904
+ if (!Number.isInteger(port) || port < 1 || port > 65535) throw new LogsPortInvalid(stage, config.port);
905
+ const retentionDays = config.retentionDays ?? 30;
906
+ if (!Number.isInteger(retentionDays) || retentionDays < 3) throw new LogsRetentionInvalid(stage, config.retentionDays);
907
+ if (config.public) {
908
+ const allow = config.public.allow ?? [];
909
+ if (allow.length === 0) throw new LogsAllowEmpty(stage);
910
+ for (const entry of allow) if (!isAddressOrRange(entry)) throw new LogsAllowEntryInvalid(stage, entry);
911
+ return {
912
+ port,
913
+ retentionDays,
914
+ public: { allow: [...allow] }
915
+ };
916
+ }
917
+ return {
918
+ port,
919
+ retentionDays
920
+ };
921
+ }
922
+ //#endregion
923
+ //#region src/telemetry/config.ts
924
+ /**
925
+ * `deploy.telemetry`, read: where one stage's telemetry goes, and how much.
926
+ *
927
+ * The application says what it emits (the `Telemetry` construct). This says
928
+ * where it is sent, per stage, and is the only place that does:
929
+ *
930
+ * - **self-hosted** — the target runs OpenObserve beside the apps (#189's
931
+ * stack service). A server target that can run it uses it when a stage
932
+ * names nothing.
933
+ * - **otlp** — any OTLP/HTTP endpoint, with its headers.
934
+ * - **false** — nothing is sent.
935
+ *
936
+ * Vendor presets (a known endpoint and header shape, with the stage secret
937
+ * `TELEMETRY_CREDENTIALS`) are one more entry in {@link PROVIDERS}: a
938
+ * resolver from the stage's config to a {@link ResolvedTelemetry}, which
939
+ * every target already consumes through {@link telemetryEnv}.
940
+ *
941
+ * The local stage ignores all of it: `gkm dev` and `gkm compose` on it run
942
+ * OpenObserve and keep every trace.
943
+ */
944
+ /** A deployed stage uses telemetry and its target cannot choose for it. */
945
+ var TelemetryProviderRequired = class extends require_errors.GkmError {
946
+ stage;
947
+ target;
948
+ constructor(stage, target) {
949
+ super(`The stage '${stage}' deploys through ${target}, which cannot run telemetry itself, and a process uses a Telemetry construct. Say where it goes in gkm.config.ts: deploy: { telemetry: { ${stage}: { provider: 'otlp', endpoint: 'https://…' } } } — or deploy: { telemetry: { ${stage}: false } } to send nothing.`);
950
+ this.stage = stage;
951
+ this.target = target;
952
+ this.name = "TelemetryProviderRequired";
953
+ }
954
+ };
955
+ /** A stage asks for the self-hosted provider on a target that cannot run it. */
956
+ var SelfHostedTelemetryUnavailable = class extends require_errors.GkmError {
957
+ stage;
958
+ target;
959
+ constructor(stage, target) {
960
+ super(`deploy.telemetry.${stage} is 'self-hosted', and ${target} does not run OpenObserve beside the apps — the compose target does. Deploy '${stage}' through compose, or send its telemetry elsewhere: deploy: { telemetry: { ${stage}: { provider: 'otlp', endpoint: 'https://…' } } }.`);
961
+ this.stage = stage;
962
+ this.target = target;
963
+ this.name = "SelfHostedTelemetryUnavailable";
964
+ }
965
+ };
966
+ /** A sample rate that is not a fraction. */
967
+ var TelemetrySampleRateInvalid = class extends require_errors.GkmError {
968
+ stage;
969
+ sampleRate;
970
+ constructor(stage, sampleRate) {
971
+ super(`deploy.telemetry.${stage}.sampleRate is ${String(sampleRate)}; set it to a number from 0 to 1 — the fraction of traces kept — or leave it out to keep every one.`);
972
+ this.stage = stage;
973
+ this.sampleRate = sampleRate;
974
+ this.name = "TelemetrySampleRateInvalid";
975
+ }
976
+ };
977
+ /** An OTLP endpoint that is not an http(s) URL. */
978
+ var TelemetryEndpointInvalid = class extends require_errors.GkmError {
979
+ stage;
980
+ endpoint;
981
+ constructor(stage, endpoint) {
982
+ super(`deploy.telemetry.${stage}.endpoint is ${JSON.stringify(endpoint)}; set it to the collector's OTLP/HTTP base URL, like 'https://otlp.example.com' — /v1/traces and /v1/logs are added to it.`);
983
+ this.stage = stage;
984
+ this.endpoint = endpoint;
985
+ this.name = "TelemetryEndpointInvalid";
986
+ }
987
+ };
988
+ /** The sample rate a stage keeps, checked. */
989
+ function sampleRateOf(stage, sampleRate) {
990
+ const rate = sampleRate ?? 1;
991
+ if (!Number.isFinite(rate) || rate < 0 || rate > 1) throw new TelemetrySampleRateInvalid(stage, sampleRate);
992
+ return rate;
993
+ }
994
+ /**
995
+ * Each provider's resolver: a stage's config to what the targets consume.
996
+ * A vendor preset is one more entry here.
997
+ */
998
+ const PROVIDERS = {
999
+ "self-hosted": (config, stage) => {
1000
+ const { provider: _, sampleRate, ...options } = config;
1001
+ return {
1002
+ provider: "self-hosted",
1003
+ selfHosted: resolveSelfHosted(options, stage),
1004
+ sampleRate: sampleRateOf(stage, sampleRate)
1005
+ };
1006
+ },
1007
+ otlp: (config, stage) => {
1008
+ if (typeof config.endpoint !== "string" || !isHttpUrl(config.endpoint)) throw new TelemetryEndpointInvalid(stage, config.endpoint);
1009
+ return {
1010
+ provider: "otlp",
1011
+ endpoint: config.endpoint.replace(/\/+$/, ""),
1012
+ headers: { ...config.headers },
1013
+ sampleRate: sampleRateOf(stage, config.sampleRate)
1014
+ };
1015
+ }
1016
+ };
1017
+ function isHttpUrl(value) {
1018
+ try {
1019
+ const url = new URL(value);
1020
+ return url.protocol === "http:" || url.protocol === "https:";
1021
+ } catch {
1022
+ return false;
1023
+ }
1024
+ }
1025
+ /**
1026
+ * One stage's entry, checked on its own — what the workspace schema runs, so
1027
+ * a bad config fails to load with the words a deploy would fail with.
1028
+ */
1029
+ function checkStageTelemetry(stage, config) {
1030
+ if (config === false) return void 0;
1031
+ const entry = config === "self-hosted" ? { provider: "self-hosted" } : config;
1032
+ const resolve = PROVIDERS[entry.provider];
1033
+ return resolve(entry, stage);
1034
+ }
1035
+ /**
1036
+ * Where a stage's telemetry goes, or undefined when nothing is sent — no
1037
+ * process uses a `Telemetry` node, or the stage opted out with `false`.
1038
+ *
1039
+ * The local stage always runs the self-hosted provider with its defaults and
1040
+ * keeps every trace, whatever `deploy.telemetry` says. A deployed stage that
1041
+ * names nothing gets the self-hosted provider where its target runs one, and
1042
+ * {@link TelemetryProviderRequired} where it cannot — AWS has none.
1043
+ */
1044
+ function resolveStageTelemetry(input) {
1045
+ const { stage } = input;
1046
+ if (!input.used) return void 0;
1047
+ if (input.local) return {
1048
+ provider: "self-hosted",
1049
+ selfHosted: resolveSelfHosted({}, stage),
1050
+ sampleRate: 1
1051
+ };
1052
+ const config = input.telemetry?.[stage];
1053
+ if (config === void 0) {
1054
+ if (input.runtime === "server" && input.selfHosted) return checkStageTelemetry(stage, "self-hosted");
1055
+ throw new TelemetryProviderRequired(stage, input.target);
1056
+ }
1057
+ const resolved = checkStageTelemetry(stage, config);
1058
+ if (resolved?.provider === "self-hosted" && !input.selfHosted) throw new SelfHostedTelemetryUnavailable(stage, input.target);
1059
+ return resolved;
1060
+ }
1061
+ /** The sampler every process with the edge runs, per the stage's rate. */
1062
+ const TRACES_SAMPLER = "parentbased_traceidratio";
1063
+ /**
1064
+ * `OTEL_EXPORTER_OTLP_HEADERS` for a set of headers: `key=value` pairs,
1065
+ * comma-separated, each value percent-encoded — the W3C baggage format the
1066
+ * SDK parses.
1067
+ */
1068
+ function otlpHeaderString(headers) {
1069
+ return Object.entries(headers).map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join(",");
1070
+ }
1071
+ /**
1072
+ * The `OTEL_*` values a stage resolves for its `Telemetry` node, before any
1073
+ * one process is named: where to export, how to sign, and how much to keep.
1074
+ * `OTEL_SERVICE_NAME` is each process's own — see `scopeTelemetryEnv`.
1075
+ */
1076
+ function telemetryEnv(destination, sampleRate) {
1077
+ return {
1078
+ OTEL_EXPORTER_OTLP_ENDPOINT: destination.endpoint,
1079
+ ...destination.headers ? { OTEL_EXPORTER_OTLP_HEADERS: destination.headers } : {},
1080
+ OTEL_TRACES_SAMPLER: TRACES_SAMPLER,
1081
+ OTEL_TRACES_SAMPLER_ARG: String(sampleRate)
1082
+ };
1083
+ }
1084
+ /** What an `otlp` stage resolves, for every process with the edge. */
1085
+ function otlpTelemetryEnv(resolved) {
1086
+ const headers = otlpHeaderString(resolved.headers);
1087
+ return telemetryEnv({
1088
+ endpoint: resolved.endpoint,
1089
+ ...headers ? { headers } : {}
1090
+ }, resolved.sampleRate);
1091
+ }
1092
+ /**
1093
+ * The sample rate a stage's browsers trace page views at — a public value,
1094
+ * the same rate its servers sample at — or undefined when the stage sends no
1095
+ * telemetry. The local stage keeps every trace.
1096
+ *
1097
+ * Lenient where `resolveStageTelemetry` is strict: a site's client is built
1098
+ * before, and apart from, the deploy that refuses a stage with no provider.
1099
+ */
1100
+ function stageSampleRate(telemetry, stage, local) {
1101
+ if (local) return 1;
1102
+ const config = telemetry?.[stage];
1103
+ if (config === false) return void 0;
1104
+ if (config === void 0 || config === "self-hosted") return 1;
1105
+ return sampleRateOf(stage, config.sampleRate);
1106
+ }
1107
+ //#endregion
1108
+ //#region src/workspace/stages.ts
1109
+ /**
1110
+ * What `gkm test` runs as. The CLI's own, so no project stage may take it:
1111
+ * its containers are torn down and rebuilt between runs.
1112
+ */
1113
+ const TEST_STAGE = "test";
1114
+ /** A stage becomes part of every physical name, so it has to fit in one. */
1115
+ const STAGE_NAME = /^[a-z][a-z0-9-]*$/;
1116
+ /** Everything wrong with one stage name, or nothing. */
1117
+ function nameProblems(name) {
1118
+ const problems = [];
1119
+ if (!STAGE_NAME.test(name)) problems.push(`stage "${name}" must be lowercase letters, digits and hyphens, starting with a letter`);
1120
+ if (name === "test") problems.push(`stage "${TEST_STAGE}" is reserved for gkm test`);
1121
+ return problems;
1122
+ }
1123
+ /** Everything wrong with a list of deployed stages on its own. */
1124
+ function deployedProblems(deployed) {
1125
+ const problems = deployed.flatMap(nameProblems);
1126
+ const seen = /* @__PURE__ */ new Set();
1127
+ for (const name of deployed) {
1128
+ if (seen.has(name)) problems.push(`stage "${name}" is listed twice`);
1129
+ seen.add(name);
1130
+ }
1131
+ return problems;
1132
+ }
1133
+ /** Everything wrong with a stages block, or nothing. */
1134
+ function stageProblems(stages) {
1135
+ if (!stages) return ["`stages` is required, e.g. stages: { local: 'dev', deployed: ['prod'] }"];
1136
+ const { local, deployed, protected: kept = [] } = stages;
1137
+ const problems = [...nameProblems(local), ...deployedProblems(deployed)];
1138
+ if (deployed.includes(local)) problems.push(`"${local}" is both the local stage and a deployed one; they would share secrets`);
1139
+ for (const name of kept) if (!deployed.includes(name)) problems.push(`protected stage "${name}" is not a deployed stage`);
1140
+ return problems;
1141
+ }
1142
+ /** The stages block, or an error naming everything wrong with it. */
1143
+ function validateStages(stages) {
1144
+ const problems = stageProblems(stages);
1145
+ if (problems.length) throw new InvalidStages(problems);
1146
+ return stages;
1147
+ }
1148
+ /** Refuses a stage the project does not deploy to. */
1149
+ function assertDeployedStage(stages, stage) {
1150
+ if (!stages.deployed.includes(stage)) throw new UndeclaredStage(stage, stages.deployed);
1151
+ }
1152
+ /** A stages block — in gkm.config.ts or from `gkm init`'s flags — that breaks a rule. */
1153
+ var InvalidStages = class extends require_errors.GkmError {
1154
+ problems;
1155
+ constructor(problems) {
1156
+ super(`Invalid stages:\n ${problems.join("\n ")}`);
1157
+ this.problems = problems;
1158
+ this.name = "InvalidStages";
1159
+ }
1160
+ };
1161
+ /**
1162
+ * A stage the project does not deploy to. Refused before anything is
1163
+ * provisioned, so a typo does not become a second environment.
1164
+ */
1165
+ var UndeclaredStage = class extends require_errors.GkmError {
1166
+ stage;
1167
+ deployed;
1168
+ constructor(stage, deployed) {
1169
+ super(`"${stage}" is not a deployed stage. gkm.config.ts deploys to: ${deployed.join(", ") || "nothing yet"}.`);
1170
+ this.stage = stage;
1171
+ this.deployed = deployed;
1172
+ this.name = "UndeclaredStage";
1173
+ }
1174
+ };
1175
+ /**
1176
+ * A per-stage setting keyed by a stage the workspace does not deploy: a typo,
1177
+ * a stage since removed, or the local stage, which none of them apply to.
1178
+ */
1179
+ var UnknownStageKey = class extends require_errors.GkmError {
1180
+ setting;
1181
+ stage;
1182
+ deployed;
1183
+ local;
1184
+ constructor(setting, stage, deployed, local) {
1185
+ super(`${setting} names the stage '${stage}', ` + (stage === local ? `the local stage — ${setting} is read for deployed stages only. ` : "which is not one of this workspace's deployed stages. ") + `It takes ${deployed.length > 0 ? deployed.map((s) => `'${s}'`).join(", ") : "no stage: stages.deployed is empty"} — the stages in stages.deployed.`);
1186
+ this.setting = setting;
1187
+ this.stage = stage;
1188
+ this.deployed = deployed;
1189
+ this.local = local;
1190
+ this.name = "UnknownStageKey";
1191
+ }
1192
+ };
1193
+ /**
1194
+ * The first key of a per-stage map that is not a deployed stage.
1195
+ *
1196
+ * @throws {UnknownStageKey}
1197
+ */
1198
+ function assertDeployedStageKeys(setting, map, stages) {
1199
+ if (!map || !stages?.deployed) return;
1200
+ for (const key of Object.keys(map)) if (!stages.deployed.includes(key)) throw new UnknownStageKey(setting, key, stages.deployed, stages.local);
1201
+ }
1202
+ //#endregion
1203
+ //#region src/workspace/schema.ts
1204
+ /** Routes are a glob, or a list of them. */
1205
+ const RoutesSchema = require_schemas.union([require_schemas.string(), require_schemas.array(require_schemas.string())]);
1206
+ /**
1207
+ * Telescope configuration schema.
1208
+ */
1209
+ const TelescopeConfigSchema = require_schemas.object({
1210
+ enabled: require_schemas.boolean().optional(),
1211
+ port: require_schemas.number().optional(),
1212
+ path: require_schemas.string().optional(),
1213
+ ignore: require_schemas.array(require_schemas.string()).optional(),
1214
+ recordBody: require_schemas.boolean().optional(),
1215
+ maxEntries: require_schemas.number().optional(),
1216
+ websocket: require_schemas.boolean().optional()
1217
+ });
1218
+ /**
1219
+ * OpenAPI configuration schema.
1220
+ */
1221
+ const OpenApiConfigSchema = require_schemas.object({
1222
+ enabled: require_schemas.boolean().optional(),
1223
+ title: require_schemas.string().optional(),
1224
+ version: require_schemas.string().optional(),
1225
+ description: require_schemas.string().optional()
1226
+ });
1227
+ /**
1228
+ * Hooks configuration schema.
1229
+ */
1230
+ const HooksConfigSchema = require_schemas.object({ server: require_schemas.string().optional() });
1231
+ /**
1232
+ * Backend framework schema for non-gkm apps.
1233
+ */
1234
+ const BackendFrameworkSchema = require_schemas._enum([
1235
+ "hono",
1236
+ "better-auth",
1237
+ "express",
1238
+ "fastify"
1239
+ ]);
1240
+ /**
1241
+ * Frontend framework schema.
1242
+ */
1243
+ const FrontendFrameworkSchema = require_schemas._enum([
1244
+ "nextjs",
1245
+ "remix",
1246
+ "vite",
1247
+ "tanstack-start"
1248
+ ]);
1249
+ /**
1250
+ * Mobile framework schema.
1251
+ */
1252
+ const MobileFrameworkSchema = require_schemas._enum(["expo"]);
1253
+ /**
1254
+ * Combined framework schema (backend, frontend, or mobile).
1255
+ */
1256
+ const FrameworkSchema = require_schemas.union([
1257
+ BackendFrameworkSchema,
1258
+ FrontendFrameworkSchema,
1259
+ MobileFrameworkSchema
1260
+ ]);
1261
+ /** Frontend framework values, kept in sync with FrontendFrameworkSchema. */
1262
+ const FRONTEND_FRAMEWORKS = [
1263
+ "nextjs",
1264
+ "remix",
1265
+ "vite",
1266
+ "tanstack-start"
1267
+ ];
1268
+ /** Mobile framework values, kept in sync with MobileFrameworkSchema. */
1269
+ const MOBILE_FRAMEWORKS = ["expo"];
1270
+ /**
1271
+ * A deploy target's name. Which names exist is the workspace's to say — the
1272
+ * built-ins and its own `deploy.targets` — so it is checked against both
1273
+ * once the whole config is read.
1274
+ */
1275
+ const DeployTargetSchema = require_schemas.string().min(1);
1276
+ /**
1277
+ * The built-in targets a config may name, both deployed by `gkm deploy`:
1278
+ * `dokploy`, and `sst`, which runs `sst deploy` on the manifest `gkm build`
1279
+ * writes.
1280
+ */
1281
+ const SUPPORTED_DEPLOY_TARGETS = require_define.configurableBuiltins();
1282
+ /** Built-in names reserved for targets that do not exist yet. */
1283
+ const PHASE_2_DEPLOY_TARGETS = Object.entries(require_define.BUILTIN_TARGETS).filter(([, target]) => target.status === "planned").map(([name]) => name);
1284
+ /**
1285
+ * Whether a config may name `target`: a usable built-in, or one of its own
1286
+ * `deploy.targets`.
1287
+ */
1288
+ function isDeployTargetSupported(target, targets = {}) {
1289
+ return SUPPORTED_DEPLOY_TARGETS.includes(target) || Object.hasOwn(targets, target);
1290
+ }
1291
+ /**
1292
+ * Check if a deploy target is planned for Phase 2.
1293
+ */
1294
+ function isPhase2DeployTarget(target) {
1295
+ return PHASE_2_DEPLOY_TARGETS.includes(target);
1296
+ }
1297
+ /**
1298
+ * Get error message for unsupported deploy targets.
1299
+ */
1300
+ function getDeployTargetError(target, appName) {
1301
+ if (isPhase2DeployTarget(target)) return `Deploy target "${target}"${appName ? ` for app "${appName}"` : ""} is coming in Phase 2. Currently "dokploy" and "sst" are supported.`;
1302
+ return `Unknown deploy target: ${target}. Built in: ${SUPPORTED_DEPLOY_TARGETS.join(", ")}; any other is named in deploy.targets with the package that provides it. Coming in Phase 2: ${PHASE_2_DEPLOY_TARGETS.join(", ")}.`;
1303
+ }
1304
+ /**
1305
+ * One `deploy.targets` entry: a package name, a target object, or either
1306
+ * with options.
1307
+ */
1308
+ const DeployTargetEntrySchema = require_schemas.union([
1309
+ require_schemas.string().min(1, "A target package name cannot be empty"),
1310
+ require_schemas.custom((value) => require_define.isDeployTarget(value), { message: "Expected a package name, a target (defineTarget), or [package or target, options]" }),
1311
+ require_schemas.tuple([require_schemas.union([require_schemas.string().min(1), require_schemas.custom((value) => require_define.isDeployTarget(value), { message: "Expected a package name or a target (defineTarget)" })]), require_schemas.unknown()])
1312
+ ]);
1313
+ /**
1314
+ * Dokploy workspace configuration schema.
1315
+ * Supports either a single endpoint or per-stage endpoints.
1316
+ */
1317
+ const DokployWorkspaceConfigSchema = require_schemas.object({
1318
+ /** Single endpoint for all stages */
1319
+ endpoint: require_schemas.url("Dokploy endpoint must be a valid URL").optional(),
1320
+ /** Per-stage endpoints (stage name -> endpoint URL) */
1321
+ endpoints: require_schemas.record(require_schemas.string(), require_schemas.url("Endpoint must be a valid URL")).optional(),
1322
+ registryId: require_schemas.string().optional(),
1323
+ /** Dokploy's own backup destination for the stage's Postgres. */
1324
+ backups: require_schemas.lazy(() => DokployBackupsConfigSchema).optional(),
1325
+ verify: require_schemas.object({
1326
+ deploymentTimeoutMs: require_schemas.number().int().positive().optional(),
1327
+ healthCheckPath: require_schemas.string().startsWith("/", "healthCheckPath must start with /").optional(),
1328
+ healthyAfter: require_schemas.number().int().positive().optional(),
1329
+ intervalMs: require_schemas.number().int().positive().optional(),
1330
+ healthTimeoutMs: require_schemas.number().int().positive().optional()
1331
+ }).optional()
1332
+ }).refine((data) => data.endpoint || data.endpoints, { message: "Either endpoint or endpoints must be provided" });
1333
+ /**
1334
+ * Valid AWS regions.
1335
+ */
1336
+ const AwsRegionSchema = require_schemas._enum([
1337
+ "us-east-1",
1338
+ "us-east-2",
1339
+ "us-west-1",
1340
+ "us-west-2",
1341
+ "af-south-1",
1342
+ "ap-east-1",
1343
+ "ap-south-1",
1344
+ "ap-south-2",
1345
+ "ap-southeast-1",
1346
+ "ap-southeast-2",
1347
+ "ap-southeast-3",
1348
+ "ap-southeast-4",
1349
+ "ap-northeast-1",
1350
+ "ap-northeast-2",
1351
+ "ap-northeast-3",
1352
+ "ca-central-1",
1353
+ "eu-central-1",
1354
+ "eu-central-2",
1355
+ "eu-west-1",
1356
+ "eu-west-2",
1357
+ "eu-west-3",
1358
+ "eu-south-1",
1359
+ "eu-south-2",
1360
+ "eu-north-1",
1361
+ "me-south-1",
1362
+ "me-central-1",
1363
+ "sa-east-1"
1364
+ ]);
1365
+ /**
1366
+ * DNS record types supported across providers.
1367
+ */
1368
+ const DnsRecordTypeSchema = require_schemas._enum([
1369
+ "A",
1370
+ "AAAA",
1371
+ "CNAME",
1372
+ "MX",
1373
+ "TXT",
1374
+ "NS",
1375
+ "SRV",
1376
+ "CAA"
1377
+ ]);
1378
+ require_schemas.object({
1379
+ /** Subdomain name (e.g., 'api' for api.example.com, '@' for root) */
1380
+ name: require_schemas.string(),
1381
+ /** Record type */
1382
+ type: DnsRecordTypeSchema,
1383
+ /** TTL in seconds */
1384
+ ttl: require_schemas.number().int().positive(),
1385
+ /**
1386
+ * Record values, as a zone file writes them: an MX record's is
1387
+ * `<priority> <host>` (`10 inbound-smtp.eu-west-1.amazonaws.com`).
1388
+ */
1389
+ values: require_schemas.array(require_schemas.string())
1390
+ });
1391
+ /**
1392
+ * A DNS record to create or update.
1393
+ */
1394
+ const UpsertDnsRecordSchema = require_schemas.object({
1395
+ /** Subdomain name (e.g., 'api' for api.example.com, '@' for root) */
1396
+ name: require_schemas.string(),
1397
+ /** Record type */
1398
+ type: DnsRecordTypeSchema,
1399
+ /** TTL in seconds */
1400
+ ttl: require_schemas.number().int().positive(),
1401
+ /**
1402
+ * Record value (IP address, hostname, etc.), as a zone file writes it: an
1403
+ * MX record's is `<priority> <host>` — see `mxValue`.
1404
+ */
1405
+ value: require_schemas.string()
1406
+ });
1407
+ require_schemas.object({
1408
+ /** The record that was upserted */
1409
+ record: UpsertDnsRecordSchema,
1410
+ /** Whether the record was created (true) or updated (false) */
1411
+ created: require_schemas.boolean(),
1412
+ /** Whether the record already existed with the same value */
1413
+ unchanged: require_schemas.boolean()
1414
+ });
1415
+ /**
1416
+ * How a domain's hosts point at a compose stage's server: an A (and AAAA)
1417
+ * record each (`'a'`, the default), or one A record for `target` and a CNAME
1418
+ * to it for every other host but the apex. `target` is one name, or one per
1419
+ * stage; it must be under the domain.
1420
+ */
1421
+ const DnsRecordsModeSchema = require_schemas.union([require_schemas.literal("a"), require_schemas.object({
1422
+ mode: require_schemas.literal("cname"),
1423
+ target: require_schemas.union([require_schemas.string(), require_schemas.record(require_schemas.string(), require_schemas.string())])
1424
+ }).strict()]);
1425
+ /**
1426
+ * Hostinger DNS provider config (without domain - domain is the record key).
1427
+ */
1428
+ const HostingerDnsProviderSchema = require_schemas.object({
1429
+ provider: require_schemas.literal("hostinger"),
1430
+ /** How the hosts point at a compose stage's server — see {@link DnsRecordsModeSchema}. */
1431
+ records: DnsRecordsModeSchema.optional(),
1432
+ /** TTL in seconds (default: 300) */
1433
+ ttl: require_schemas.number().int().positive().optional()
1434
+ });
1435
+ /**
1436
+ * Route53 DNS provider config (without domain - domain is the record key).
1437
+ */
1438
+ const Route53DnsProviderSchema = require_schemas.object({
1439
+ provider: require_schemas.literal("route53"),
1440
+ /** How the hosts point at a compose stage's server — see {@link DnsRecordsModeSchema}. */
1441
+ records: DnsRecordsModeSchema.optional(),
1442
+ /** AWS region (optional - uses AWS_REGION env var if not provided) */
1443
+ region: AwsRegionSchema.optional(),
1444
+ /** AWS profile name (optional - uses default credential chain if not provided) */
1445
+ profile: require_schemas.string().optional(),
1446
+ /** Hosted zone ID (optional - auto-detected from domain if not provided) */
1447
+ hostedZoneId: require_schemas.string().optional(),
1448
+ /** TTL in seconds (default: 300) */
1449
+ ttl: require_schemas.number().int().positive().optional()
1450
+ });
1451
+ /**
1452
+ * GoDaddy DNS provider config (without domain - domain is the record key).
1453
+ *
1454
+ * Credentials: `GODADDY_API_TOKEN` (a Personal Access Token scoped to
1455
+ * `domains.dns:update`), else `gkm login --provider godaddy`. GoDaddy refuses
1456
+ * a TTL under 600 seconds.
1457
+ */
1458
+ const GoDaddyDnsProviderSchema = require_schemas.object({
1459
+ provider: require_schemas.literal("godaddy"),
1460
+ /** How the hosts point at a compose stage's server — see {@link DnsRecordsModeSchema}. */
1461
+ records: DnsRecordsModeSchema.optional(),
1462
+ /** TTL in seconds (default and minimum: 600) */
1463
+ ttl: require_schemas.number().int().min(600, "GoDaddy's minimum TTL is 600 seconds").optional()
1464
+ });
1465
+ /**
1466
+ * Cloudflare DNS provider config (placeholder for future).
1467
+ */
1468
+ const CloudflareDnsProviderSchema = require_schemas.object({
1469
+ provider: require_schemas.literal("cloudflare"),
1470
+ /** How the hosts point at a compose stage's server — see {@link DnsRecordsModeSchema}. */
1471
+ records: DnsRecordsModeSchema.optional(),
1472
+ /** TTL in seconds (default: 300) */
1473
+ ttl: require_schemas.number().int().positive().optional()
1474
+ });
1475
+ /**
1476
+ * Manual DNS configuration (user handles DNS themselves).
1477
+ */
1478
+ const ManualDnsProviderSchema = require_schemas.object({
1479
+ provider: require_schemas.literal("manual"),
1480
+ /** How the hosts point at a compose stage's server — see {@link DnsRecordsModeSchema}. */
1481
+ records: DnsRecordsModeSchema.optional()
1482
+ });
1483
+ /**
1484
+ * Custom DNS provider config (user-provided implementation).
1485
+ */
1486
+ const CustomDnsProviderSchema = require_schemas.object({
1487
+ /** Custom DnsProvider implementation */
1488
+ provider: require_schemas.custom((val) => typeof val === "object" && val !== null && typeof val.name === "string" && typeof val.getRecords === "function" && typeof val.upsertRecords === "function", { message: "Custom DNS provider must implement name, getRecords(), and upsertRecords() methods" }),
1489
+ /** How the hosts point at a compose stage's server — see {@link DnsRecordsModeSchema}. */
1490
+ records: DnsRecordsModeSchema.optional(),
1491
+ /** TTL in seconds (default: 300) */
1492
+ ttl: require_schemas.number().int().positive().optional()
1493
+ });
1494
+ /**
1495
+ * Built-in DNS provider config (discriminated union).
1496
+ */
1497
+ const BuiltInDnsProviderSchema = require_schemas.discriminatedUnion("provider", [
1498
+ HostingerDnsProviderSchema,
1499
+ Route53DnsProviderSchema,
1500
+ GoDaddyDnsProviderSchema,
1501
+ CloudflareDnsProviderSchema,
1502
+ ManualDnsProviderSchema
1503
+ ]);
1504
+ /**
1505
+ * Single DNS provider config (for one domain).
1506
+ */
1507
+ const DnsProviderSchema = require_schemas.union([BuiltInDnsProviderSchema, CustomDnsProviderSchema]);
1508
+ /**
1509
+ * DNS configuration schema.
1510
+ *
1511
+ * Maps root domains to their DNS provider configuration.
1512
+ * Example:
1513
+ * ```
1514
+ * dns: {
1515
+ * 'geekmidas.dev': { provider: 'hostinger' },
1516
+ * 'geekmidas.com': { provider: 'route53' },
1517
+ * }
1518
+ * ```
1519
+ *
1520
+ * Supported providers:
1521
+ * - 'hostinger': Use Hostinger DNS API
1522
+ * - 'route53': Use AWS Route53
1523
+ * - 'godaddy': Use GoDaddy's v1 DNS API
1524
+ * - 'cloudflare': Use Cloudflare DNS API (future)
1525
+ * - 'manual': Don't create records, just print required records
1526
+ * - Custom: Provide a DnsProvider implementation
1527
+ */
1528
+ const DnsConfigSchema = require_schemas.record(require_schemas.string(), DnsProviderSchema);
1529
+ const HostingerDnsConfigSchema = HostingerDnsProviderSchema.extend({ domain: require_schemas.string().min(1, "Domain is required") });
1530
+ const Route53DnsConfigSchema = Route53DnsProviderSchema.extend({ domain: require_schemas.string().min(1, "Domain is required") });
1531
+ const GoDaddyDnsConfigSchema = GoDaddyDnsProviderSchema.extend({ domain: require_schemas.string().min(1, "Domain is required") });
1532
+ const CloudflareDnsConfigSchema = CloudflareDnsProviderSchema.extend({ domain: require_schemas.string().min(1, "Domain is required") });
1533
+ const ManualDnsConfigSchema = ManualDnsProviderSchema.extend({ domain: require_schemas.string().min(1, "Domain is required") });
1534
+ const CustomDnsConfigSchema = CustomDnsProviderSchema.extend({ domain: require_schemas.string().min(1, "Domain is required") });
1535
+ const BuiltInDnsConfigSchema = require_schemas.discriminatedUnion("provider", [
1536
+ HostingerDnsConfigSchema,
1537
+ Route53DnsConfigSchema,
1538
+ GoDaddyDnsConfigSchema,
1539
+ CloudflareDnsConfigSchema,
1540
+ ManualDnsConfigSchema
1541
+ ]);
1542
+ const LegacyDnsConfigSchema = require_schemas.union([BuiltInDnsConfigSchema, CustomDnsConfigSchema]);
1543
+ require_schemas.union([DnsConfigSchema, LegacyDnsConfigSchema]);
1544
+ /**
1545
+ * Backups configuration schema.
1546
+ *
1547
+ * Configures automatic backup destinations for database services.
1548
+ * On first deploy, creates S3 bucket with unique name and IAM credentials.
1549
+ */
1550
+ const DokployBackupsConfigSchema = require_schemas.object({
1551
+ /** Backup storage type (currently only 's3' supported) */
1552
+ type: require_schemas.literal("s3"),
1553
+ /** AWS profile name for creating bucket/IAM resources */
1554
+ profile: require_schemas.string().optional(),
1555
+ /** AWS region for the backup bucket */
1556
+ region: AwsRegionSchema,
1557
+ /** Cron schedule for backups (default: '0 2 * * *' = 2 AM daily) */
1558
+ schedule: require_schemas.string().optional(),
1559
+ /** Number of backups to retain (default: 30) */
1560
+ retention: require_schemas.number().optional()
1561
+ });
1562
+ /**
1563
+ * `deploy.backups` — when each deployed compose stage's databases are backed
1564
+ * up, and how long a backup is kept. The rules are `checkStageBackups`', so
1565
+ * the schema and a deploy refuse the same entries with the same words.
1566
+ */
1567
+ const BackupsConfigSchema = require_schemas.record(require_schemas.string(), require_schemas.unknown()).superRefine((entries, ctx) => {
1568
+ for (const [stage, value] of Object.entries(entries)) try {
1569
+ checkStageBackups(stage, value);
1570
+ } catch (error) {
1571
+ ctx.addIssue({
1572
+ code: "custom",
1573
+ message: error instanceof Error ? error.message : String(error),
1574
+ path: [stage]
1575
+ });
1576
+ }
1577
+ });
1578
+ /** `deploy.compose` — what the compose target runs beside the apps. */
1579
+ const ComposeWorkspaceConfigSchema = require_schemas.object({
1580
+ proxy: require_schemas.union([require_schemas._enum(["caddy", "traefik"]), require_schemas.record(require_schemas.string(), require_schemas._enum(["caddy", "traefik"]))]).optional(),
1581
+ tls: require_schemas.record(require_schemas.string(), require_schemas.object({
1582
+ certFile: require_schemas.string().min(1),
1583
+ keyFile: require_schemas.string().min(1),
1584
+ caFile: require_schemas.string().min(1).optional()
1585
+ }).strict()).optional(),
1586
+ server: require_schemas.record(require_schemas.string(), require_schemas.object({
1587
+ user: require_schemas.string().min(1),
1588
+ host: require_schemas.string().min(1).optional(),
1589
+ port: require_schemas.number().int().min(1).max(65535).optional()
1590
+ }).strict()).optional()
1591
+ }).strict();
1592
+ const TelemetrySampleRate = require_schemas.number().optional();
1593
+ /**
1594
+ * `deploy.telemetry` — where each stage's telemetry goes. The rules past the
1595
+ * shape are `checkStageTelemetry`'s, so the schema and a deploy refuse the
1596
+ * same configs with the same words.
1597
+ */
1598
+ const TelemetryConfigSchema = require_schemas.record(require_schemas.string(), require_schemas.union([
1599
+ require_schemas.literal(false),
1600
+ require_schemas.literal("self-hosted"),
1601
+ require_schemas.object({
1602
+ provider: require_schemas.literal("self-hosted"),
1603
+ port: require_schemas.number().optional(),
1604
+ retentionDays: require_schemas.number().optional(),
1605
+ public: require_schemas.object({ allow: require_schemas.array(require_schemas.string()) }).optional(),
1606
+ sampleRate: TelemetrySampleRate
1607
+ }).strict(),
1608
+ require_schemas.object({
1609
+ provider: require_schemas.literal("otlp"),
1610
+ endpoint: require_schemas.string(),
1611
+ headers: require_schemas.record(require_schemas.string(), require_schemas.string()).optional(),
1612
+ sampleRate: TelemetrySampleRate
1613
+ }).strict()
1614
+ ])).superRefine((telemetry, ctx) => {
1615
+ for (const [stage, config] of Object.entries(telemetry)) try {
1616
+ checkStageTelemetry(stage, config);
1617
+ } catch (error) {
1618
+ ctx.addIssue({
1619
+ code: "custom",
1620
+ message: error instanceof Error ? error.message : String(error),
1621
+ path: [stage]
1622
+ });
1623
+ }
1624
+ });
1625
+ /**
1626
+ * `deploy.objects` — what backs each deployed stage's buckets. The rules are
1627
+ * `checkStageProvider`'s, so the schema and a provision run refuse the same
1628
+ * entries with the same words.
1629
+ */
1630
+ const ObjectsConfigSchema = require_schemas.record(require_schemas.string(), require_schemas.unknown()).superRefine((entries, ctx) => {
1631
+ for (const [stage, value] of Object.entries(entries)) try {
1632
+ checkStageProvider("objects", stage, value);
1633
+ } catch (error) {
1634
+ ctx.addIssue({
1635
+ code: "custom",
1636
+ message: error instanceof Error ? error.message : String(error),
1637
+ path: [stage]
1638
+ });
1639
+ }
1640
+ });
1641
+ /** `deploy.inbox` — what receives each deployed stage's inboxes; `checkStageProvider`'s rules. */
1642
+ const InboxConfigSchema = require_schemas.record(require_schemas.string(), require_schemas.unknown()).superRefine((entries, ctx) => {
1643
+ for (const [stage, value] of Object.entries(entries)) try {
1644
+ checkStageProvider("inbox", stage, value);
1645
+ } catch (error) {
1646
+ ctx.addIssue({
1647
+ code: "custom",
1648
+ message: error instanceof Error ? error.message : String(error),
1649
+ path: [stage]
1650
+ });
1651
+ }
1652
+ });
1653
+ /**
1654
+ * Deploy configuration schema.
1655
+ */
1656
+ const DeployConfigSchema = require_schemas.object({
1657
+ default: DeployTargetSchema.optional(),
1658
+ targets: require_schemas.record(require_schemas.string(), DeployTargetEntrySchema).superRefine((targets, ctx) => {
1659
+ for (const name of Object.keys(targets)) if (require_define.builtinTarget(name)) ctx.addIssue({
1660
+ code: "custom",
1661
+ message: `"${name}" is a built-in target; give this one a name of its own`,
1662
+ path: [name]
1663
+ });
1664
+ }).optional(),
1665
+ /** Whose deploy this is, on a target shared with other workspaces. */
1666
+ namespace: require_schemas.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "deploy.namespace must be lowercase letters and digits with single '-' between them").optional(),
1667
+ /** Where every target pushes and pulls the apps' images. */
1668
+ registry: require_schemas.string().min(1).optional(),
1669
+ dokploy: DokployWorkspaceConfigSchema.optional(),
1670
+ compose: ComposeWorkspaceConfigSchema.optional(),
1671
+ telemetry: TelemetryConfigSchema.optional(),
1672
+ objects: ObjectsConfigSchema.optional(),
1673
+ inbox: InboxConfigSchema.optional(),
1674
+ backups: BackupsConfigSchema.optional()
1675
+ });
1676
+ /**
1677
+ * Models configuration schema.
1678
+ */
1679
+ const ModelsConfigSchema = require_schemas.object({
1680
+ path: require_schemas.string().optional(),
1681
+ schema: require_schemas._enum(["zod"]).optional()
1682
+ });
1683
+ /**
1684
+ * Shared configuration schema.
1685
+ */
1686
+ const SharedConfigSchema = require_schemas.object({
1687
+ packages: require_schemas.array(require_schemas.string()).optional(),
1688
+ models: ModelsConfigSchema.optional()
1689
+ });
1690
+ /**
1691
+ * Secrets configuration schema.
1692
+ */
1693
+ const StagesConfigSchema = require_schemas.object({
1694
+ local: require_schemas.string(),
1695
+ deployed: require_schemas.array(require_schemas.string()),
1696
+ protected: require_schemas.array(require_schemas.string()).optional()
1697
+ }).superRefine((stages, ctx) => {
1698
+ for (const message of stageProblems(stages)) ctx.addIssue({
1699
+ code: "custom",
1700
+ message
1701
+ });
1702
+ });
1703
+ const SecretsStoreSchema = require_schemas.union([
1704
+ require_schemas.literal("file"),
1705
+ require_schemas.object({
1706
+ provider: require_schemas.literal("s3"),
1707
+ /** A bucket that exists; omitted, the project bucket. */
1708
+ bucket: require_schemas.string().min(1).optional(),
1709
+ /** Omitted, the S3 deploy state's region. */
1710
+ region: AwsRegionSchema.optional(),
1711
+ /** Omitted, the S3 deploy state's prefix, else 'gkm'. */
1712
+ prefix: require_schemas.string().optional()
1713
+ }).strict(),
1714
+ require_schemas.object({
1715
+ provider: require_schemas.literal("ssm"),
1716
+ region: AwsRegionSchema
1717
+ }).strict(),
1718
+ require_schemas.object({
1719
+ provider: require_schemas.literal("secrets-manager"),
1720
+ region: AwsRegionSchema,
1721
+ kmsKeyId: require_schemas.string().min(1).optional()
1722
+ }).strict(),
1723
+ require_schemas.object({
1724
+ /** Any backend: an object implementing SecretsStore */
1725
+ provider: require_schemas.custom((val) => typeof val === "object" && val !== null && typeof val.name === "string" && typeof val.read === "function" && typeof val.write === "function", { message: "a secrets store has a name, read() and write()" }) })
1726
+ ]);
1727
+ const SecretsConfigSchema = require_schemas.object({
1728
+ enabled: require_schemas.boolean().optional(),
1729
+ store: SecretsStoreSchema.optional(),
1730
+ algorithm: require_schemas.string().optional(),
1731
+ kdf: require_schemas._enum(["scrypt", "pbkdf2"]).optional()
1732
+ });
1733
+ /**
1734
+ * Local state provider config.
1735
+ */
1736
+ const LocalStateConfigSchema = require_schemas.object({ provider: require_schemas.literal("local") });
1737
+ /**
1738
+ * SSM state provider config (requires region).
1739
+ */
1740
+ const SSMStateConfigSchema = require_schemas.object({
1741
+ provider: require_schemas.literal("ssm"),
1742
+ /** AWS region (required for SSM provider) */
1743
+ region: AwsRegionSchema,
1744
+ /** AWS profile name (optional - uses default credential chain if not provided) */
1745
+ profile: require_schemas.string().optional()
1746
+ });
1747
+ /**
1748
+ * S3 state provider config: conditional writes and a lock object in a bucket.
1749
+ */
1750
+ const S3StateConfigSchema = require_schemas.object({
1751
+ provider: require_schemas.literal("s3"),
1752
+ /**
1753
+ * Bucket the state lives in (must already exist). Omitted, the project
1754
+ * bucket, created by the first deploy.
1755
+ */
1756
+ bucket: require_schemas.string().min(1).optional(),
1757
+ /** AWS region of the bucket */
1758
+ region: AwsRegionSchema,
1759
+ /** Key prefix inside the bucket (default: 'gkm') */
1760
+ prefix: require_schemas.string().optional(),
1761
+ /** AWS profile name (optional - uses default credential chain if not provided) */
1762
+ profile: require_schemas.string().optional()
1763
+ });
1764
+ /**
1765
+ * Custom state provider config (user-provided implementation).
1766
+ */
1767
+ const CustomStateConfigSchema = require_schemas.object({
1768
+ /** Custom StateProvider implementation */
1769
+ provider: require_schemas.custom((val) => typeof val === "object" && val !== null && typeof val.read === "function" && typeof val.write === "function", { message: "Custom provider must implement read() and write() methods" }) });
1770
+ /**
1771
+ * Built-in state provider config (discriminated union).
1772
+ */
1773
+ const BuiltInStateConfigSchema = require_schemas.discriminatedUnion("provider", [
1774
+ LocalStateConfigSchema,
1775
+ SSMStateConfigSchema,
1776
+ S3StateConfigSchema
1777
+ ]);
1778
+ /**
1779
+ * State configuration schema.
1780
+ *
1781
+ * Configures how deployment state is stored.
1782
+ * - 'local': Store in .gkm/deploy-{stage}.json (default)
1783
+ * - 'ssm': Store in AWS SSM Parameter Store (requires region)
1784
+ * - 's3': Store in an S3 bucket with conditional writes (requires region; the
1785
+ * project bucket is created when no bucket is named)
1786
+ * - Custom: Provide a StateStore, or a StateProvider with read/write methods
1787
+ */
1788
+ const StateConfigSchema = require_schemas.union([BuiltInStateConfigSchema, CustomStateConfigSchema]);
1789
+ /**
1790
+ * App configuration schema.
1791
+ */
1792
+ const AppConfigSchema = require_schemas.object({
1793
+ type: require_schemas._enum([
1794
+ "backend",
1795
+ "web",
1796
+ "mobile"
1797
+ ]).optional().default("backend"),
1798
+ path: require_schemas.string().min(1, "App path is required"),
1799
+ port: require_schemas.number().int().positive("Port must be a positive integer"),
1800
+ dependencies: require_schemas.array(require_schemas.string()).optional(),
1801
+ deploy: DeployTargetSchema.optional(),
1802
+ constructs: RoutesSchema.optional(),
1803
+ routes: RoutesSchema.optional(),
1804
+ functions: RoutesSchema.optional(),
1805
+ crons: RoutesSchema.optional(),
1806
+ queues: RoutesSchema.optional(),
1807
+ topics: RoutesSchema.optional(),
1808
+ subscribers: RoutesSchema.optional(),
1809
+ envParser: require_schemas.string().optional(),
1810
+ logger: require_schemas.string().optional(),
1811
+ hooks: HooksConfigSchema.optional(),
1812
+ telescope: require_schemas.union([
1813
+ require_schemas.string(),
1814
+ require_schemas.boolean(),
1815
+ TelescopeConfigSchema
1816
+ ]).optional(),
1817
+ openapi: require_schemas.union([require_schemas.boolean(), OpenApiConfigSchema]).optional(),
1818
+ runtime: require_schemas._enum(["node", "bun"]).optional(),
1819
+ env: require_schemas.union([require_schemas.string(), require_schemas.array(require_schemas.string())]).optional(),
1820
+ entry: require_schemas.string().optional(),
1821
+ framework: FrameworkSchema.optional(),
1822
+ config: require_schemas.object({
1823
+ client: require_schemas.string().optional(),
1824
+ server: require_schemas.string().optional()
1825
+ }).optional()
1826
+ }).refine((data) => {
1827
+ if (data.type === "web") {
1828
+ if (!data.framework || !FRONTEND_FRAMEWORKS.includes(data.framework)) return false;
1829
+ }
1830
+ return true;
1831
+ }, {
1832
+ message: `Web apps must have a valid web framework (${FRONTEND_FRAMEWORKS.join(", ")})`,
1833
+ path: ["framework"]
1834
+ }).refine((data) => {
1835
+ if (data.type === "mobile") {
1836
+ if (!data.framework || !MOBILE_FRAMEWORKS.includes(data.framework)) return false;
1837
+ }
1838
+ return true;
1839
+ }, {
1840
+ message: `Mobile apps must have a valid mobile framework (${MOBILE_FRAMEWORKS.join(", ")})`,
1841
+ path: ["framework"]
1842
+ });
1843
+ /** What `gkm test` hands a feature test. */
1844
+ const TestConfigSchema = require_schemas.object({
1845
+ /** The folder of per-database factories; `test/factories` by default. */
1846
+ factories: require_schemas.string().optional() }).strict();
1847
+ /** How `gkm dev` is reached from outside the apps it runs. */
1848
+ const DevConfigSchema = require_schemas.object({
1849
+ /** Browser origins that may read the discovery endpoint. */
1850
+ allowedOrigins: require_schemas.array(require_schemas.url().refine((value) => URL.canParse(value) && new URL(value).origin === value, { message: "An origin is a scheme, host and port only, e.g. https://console.example.com — no path or trailing slash" })).optional(),
1851
+ /** The discovery endpoint's loopback port; 4983 by default. */
1852
+ discoveryPort: require_schemas.number().int().min(0).max(65535).optional()
1853
+ }).strict();
1854
+ /**
1855
+ * Workspace configuration schema.
1856
+ */
1857
+ const WorkspaceConfigSchema = require_schemas.object({
1858
+ name: require_schemas.string().optional(),
1859
+ /**
1860
+ * Where the workspace's own constructs live, relative to its root.
1861
+ *
1862
+ * Infrastructure is a fact about the product, not about the process that
1863
+ * happens to import it — so a database two apps share is declared once,
1864
+ * at the top, and both find it. An app-level glob still works and is
1865
+ * additive, for something only one app uses.
1866
+ */
1867
+ constructs: RoutesSchema.optional(),
1868
+ /**
1869
+ * Apps that nothing declares.
1870
+ *
1871
+ * Optional, and normally absent: a `site` is an app and so is a
1872
+ * `rest-api` that named one, so the list is read off the graph. This is
1873
+ * the escape hatch for what no construct describes — a mobile app, a
1874
+ * process someone runs by hand — and for overriding one field of a
1875
+ * derived app without restating it.
1876
+ */
1877
+ apps: require_schemas.record(require_schemas.string(), AppConfigSchema).optional(),
1878
+ shared: SharedConfigSchema.optional(),
1879
+ /** Each deployed stage's base domain (stage name -> domain). */
1880
+ domains: require_schemas.record(require_schemas.string(), require_schemas.string()).optional(),
1881
+ /**
1882
+ * Subdomains no tenant of a wildcard site may take, beyond every app's
1883
+ * own: `www`, `mail`, `status`. One DNS label each.
1884
+ */
1885
+ protectedSubdomains: require_schemas.array(require_schemas.string().regex(/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/)).optional(),
1886
+ /** Each root domain's DNS provider, and how its hosts are pointed. */
1887
+ dns: DnsConfigSchema.optional(),
1888
+ deploy: DeployConfigSchema.optional(),
1889
+ stages: StagesConfigSchema,
1890
+ secrets: SecretsConfigSchema.optional(),
1891
+ state: StateConfigSchema.optional(),
1892
+ test: TestConfigSchema.optional(),
1893
+ dev: DevConfigSchema.optional()
1894
+ }).strict().refine((data) => {
1895
+ const appNames = Object.keys(data.apps ?? {});
1896
+ for (const [appName, app] of Object.entries(data.apps ?? {})) for (const dep of app.dependencies ?? []) {
1897
+ if (!appNames.includes(dep)) return false;
1898
+ if (dep === appName) return false;
1899
+ }
1900
+ return true;
1901
+ }, { message: "App dependencies must reference existing apps and cannot be self-referential" }).refine((data) => {
1902
+ const appNames = Object.keys(data.apps ?? {});
1903
+ const visited = /* @__PURE__ */ new Set();
1904
+ const recStack = /* @__PURE__ */ new Set();
1905
+ function hasCycle(app) {
1906
+ if (recStack.has(app)) return true;
1907
+ if (visited.has(app)) return false;
1908
+ visited.add(app);
1909
+ recStack.add(app);
1910
+ const deps = data.apps?.[app]?.dependencies ?? [];
1911
+ for (const dep of deps) if (hasCycle(dep)) return true;
1912
+ recStack.delete(app);
1913
+ return false;
1914
+ }
1915
+ for (const app of appNames) {
1916
+ visited.clear();
1917
+ recStack.clear();
1918
+ if (hasCycle(app)) return false;
1919
+ }
1920
+ return true;
1921
+ }, { message: "Circular dependencies detected between apps" }).superRefine((data, ctx) => {
1922
+ const defaultTarget = data.deploy?.default;
1923
+ const ownTargets = data.deploy?.targets ?? {};
1924
+ if (defaultTarget && !isDeployTargetSupported(defaultTarget, ownTargets)) {
1925
+ ctx.addIssue({
1926
+ code: "custom",
1927
+ message: getDeployTargetError(defaultTarget),
1928
+ path: ["deploy", "default"]
1929
+ });
1930
+ return;
1931
+ }
1932
+ for (const [appName, app] of Object.entries(data.apps ?? {})) if (app.deploy && !isDeployTargetSupported(app.deploy, ownTargets)) {
1933
+ ctx.addIssue({
1934
+ code: "custom",
1935
+ message: getDeployTargetError(app.deploy, appName),
1936
+ path: [
1937
+ "apps",
1938
+ appName,
1939
+ "deploy"
1940
+ ]
1941
+ });
1942
+ return;
1943
+ }
1944
+ const store = data.secrets?.store;
1945
+ if (typeof store === "object" && store.provider === "s3") try {
1946
+ s3SecretsLocation(store, data.state);
1947
+ } catch (error) {
1948
+ ctx.addIssue({
1949
+ code: "custom",
1950
+ message: error instanceof Error ? error.message : String(error),
1951
+ path: ["secrets", "store"]
1952
+ });
1953
+ }
1954
+ try {
1955
+ checkComposeStages(data.deploy?.compose, data.stages);
1956
+ } catch (error) {
1957
+ ctx.addIssue({
1958
+ code: "custom",
1959
+ message: error instanceof Error ? error.message : String(error),
1960
+ path: ["deploy", "compose"]
1961
+ });
1962
+ }
1963
+ const perStage = [
1964
+ [
1965
+ "domains",
1966
+ ["domains"],
1967
+ data.domains
1968
+ ],
1969
+ [
1970
+ "deploy.objects",
1971
+ ["deploy", "objects"],
1972
+ data.deploy?.objects
1973
+ ],
1974
+ [
1975
+ "deploy.inbox",
1976
+ ["deploy", "inbox"],
1977
+ data.deploy?.inbox
1978
+ ],
1979
+ [
1980
+ "deploy.backups",
1981
+ ["deploy", "backups"],
1982
+ data.deploy?.backups
1983
+ ],
1984
+ [
1985
+ "deploy.telemetry",
1986
+ ["deploy", "telemetry"],
1987
+ data.deploy?.telemetry
1988
+ ],
1989
+ ...Object.entries(data.dns ?? {}).map(([domain, entry]) => {
1990
+ const records = entry.records;
1991
+ const target = records && typeof records === "object" ? records.target : void 0;
1992
+ return [
1993
+ `dns['${domain}'].records.target`,
1994
+ [
1995
+ "dns",
1996
+ domain,
1997
+ "records",
1998
+ "target"
1999
+ ],
2000
+ target && typeof target === "object" ? target : void 0
2001
+ ];
2002
+ })
2003
+ ];
2004
+ for (const [setting, path, map] of perStage) try {
2005
+ assertDeployedStageKeys(setting, map, data.stages);
2006
+ } catch (error) {
2007
+ ctx.addIssue({
2008
+ code: "custom",
2009
+ message: error instanceof Error ? error.message : String(error),
2010
+ path
2011
+ });
2012
+ }
2013
+ for (const [domain, entry] of Object.entries(data.dns ?? {})) try {
2014
+ checkDnsRecordsMode(domain, entry.records);
2015
+ } catch (error) {
2016
+ ctx.addIssue({
2017
+ code: "custom",
2018
+ message: error instanceof Error ? error.message : String(error),
2019
+ path: [
2020
+ "dns",
2021
+ domain,
2022
+ "records"
2023
+ ]
2024
+ });
2025
+ }
2026
+ if (data.state?.provider === "ssm" && !data.name) ctx.addIssue({
2027
+ code: "custom",
2028
+ message: "Workspace name is required when using SSM state provider. Add \"name\" to your gkm.config.ts.",
2029
+ path: ["name"]
2030
+ });
2031
+ });
2032
+ /**
2033
+ * Validate workspace configuration.
2034
+ * Throws ZodError with detailed messages on validation failure.
2035
+ */
2036
+ function validateWorkspaceConfig(config) {
2037
+ return WorkspaceConfigSchema.parse(config);
2038
+ }
2039
+ /**
2040
+ * Safe validation that returns result instead of throwing.
2041
+ */
2042
+ function safeValidateWorkspaceConfig(config) {
2043
+ const result = WorkspaceConfigSchema.safeParse(config);
2044
+ if (result.success) return {
2045
+ success: true,
2046
+ data: result.data
2047
+ };
2048
+ return {
2049
+ success: false,
2050
+ error: result.error
2051
+ };
2052
+ }
2053
+ /**
2054
+ * Format Zod errors into user-friendly messages.
2055
+ */
2056
+ function formatValidationErrors(error) {
2057
+ return `Workspace configuration validation failed:\n${error.issues.map((issue) => {
2058
+ const path = issue.path.join(".");
2059
+ return path ? ` - ${path}: ${issue.message}` : ` - ${issue.message}`;
2060
+ }).join("\n")}`;
2061
+ }
2062
+ //#endregion
2063
+ //#region src/workspace/types.ts
2064
+ /**
2065
+ * Type guard to check if a config is a WorkspaceConfig.
2066
+ *
2067
+ * @example
2068
+ * ```ts
2069
+ * const config = await loadConfig();
2070
+ * if (isWorkspaceConfig(config)) {
2071
+ * // config.apps is available
2072
+ * console.log(Object.keys(config.apps));
2073
+ * }
2074
+ * ```
2075
+ */
2076
+ function isWorkspaceConfig(config) {
2077
+ if (typeof config !== "object" || config === null) return false;
2078
+ if ("apps" in config && typeof config.apps === "object") return true;
2079
+ return "constructs" in config && Object.keys(config).every((key) => WORKSPACE_KEYS.has(key));
2080
+ }
2081
+ /** Every top-level key a workspace config has — see `WorkspaceConfigSchema`. */
2082
+ const WORKSPACE_KEYS = /* @__PURE__ */ new Set([
2083
+ "name",
2084
+ "constructs",
2085
+ "apps",
2086
+ "shared",
2087
+ "domains",
2088
+ "protectedSubdomains",
2089
+ "dns",
2090
+ "deploy",
2091
+ "stages",
2092
+ "secrets",
2093
+ "state"
2094
+ ]);
2095
+ //#endregion
2096
+ //#region src/workspace/publicEnv.ts
2097
+ /**
2098
+ * All public env-var prefixes the toolbox understands.
2099
+ *
2100
+ * Used when resolving incoming var names back to a dependency
2101
+ * (e.g. `VITE_AUTH_URL` → `auth`). A var matching any of these
2102
+ * is considered safe to inline into a client bundle.
2103
+ */
2104
+ const PUBLIC_ENV_PREFIXES = [
2105
+ "NEXT_PUBLIC_",
2106
+ "VITE_",
2107
+ "EXPO_PUBLIC_"
2108
+ ];
2109
+ /**
2110
+ * Resolve the public env-var prefix that a frontend framework's bundler
2111
+ * inlines into client code at build time:
2112
+ *
2113
+ * - `nextjs` → `NEXT_PUBLIC_`
2114
+ * - `vite` → `VITE_`
2115
+ * - `tanstack-start` → `VITE_` (uses Vite under the hood)
2116
+ * - `expo` → `EXPO_PUBLIC_`
2117
+ * - `remix` → `''` (Remix exposes via loaders, no prefix convention)
2118
+ *
2119
+ * For backend frameworks or unspecified, falls back to `NEXT_PUBLIC_` to
2120
+ * preserve the historical default. Backend apps never read these vars
2121
+ * from a bundle, so the prefix only affects scaffolding/symmetry.
2122
+ */
2123
+ function getPublicEnvPrefix(framework) {
2124
+ switch (framework) {
2125
+ case "vite":
2126
+ case "tanstack-start": return "VITE_";
2127
+ case "expo": return "EXPO_PUBLIC_";
2128
+ case "remix": return "";
2129
+ case "nextjs": return "NEXT_PUBLIC_";
2130
+ default: return "NEXT_PUBLIC_";
2131
+ }
2132
+ }
2133
+ /**
2134
+ * Strip a known public prefix from a var name.
2135
+ * Returns the un-prefixed name, or `null` if no prefix matched.
2136
+ */
2137
+ function stripPublicPrefix(name) {
2138
+ for (const prefix of PUBLIC_ENV_PREFIXES) if (prefix && name.startsWith(prefix)) return name.slice(prefix.length);
2139
+ return null;
2140
+ }
2141
+ //#endregion
2142
+ //#region src/workspace/index.ts
2143
+ /**
2144
+ * Validate that all dependencies reference existing apps.
2145
+ * Returns the config if valid, throws otherwise.
2146
+ */
2147
+ function validateDependencies(apps) {
2148
+ const appNames = new Set(Object.keys(apps));
2149
+ for (const [appName, app] of Object.entries(apps)) for (const dep of app.dependencies ?? []) {
2150
+ if (!appNames.has(dep)) throw new Error(`Invalid dependency: App "${appName}" depends on "${dep}" which does not exist. Valid apps are: ${[...appNames].join(", ")}`);
2151
+ if (dep === appName) throw new Error(`Invalid dependency: App "${appName}" cannot depend on itself.`);
2152
+ }
2153
+ }
2154
+ /**
2155
+ * Define workspace configuration with full TypeScript support and type inference.
2156
+ *
2157
+ * Uses `const` type parameter to infer literal app names, providing:
2158
+ * - Autocomplete for app names in dependencies
2159
+ * - Type errors for invalid dependency references
2160
+ * - Full type inference for the returned config
2161
+ *
2162
+ * @example
2163
+ * ```ts
2164
+ * // gkm.config.ts
2165
+ * import { defineWorkspace } from '@geekmidas/cli';
2166
+ *
2167
+ * export default defineWorkspace({
2168
+ * name: 'my-saas',
2169
+ * apps: {
2170
+ * api: {
2171
+ * type: 'backend',
2172
+ * path: 'apps/api',
2173
+ * port: 3000,
2174
+ * routes: './src/endpoints/**\/*.ts',
2175
+ * envParser: './src/config/env',
2176
+ * logger: './src/logger',
2177
+ * },
2178
+ * web: {
2179
+ * type: 'web',
2180
+ * framework: 'nextjs',
2181
+ * path: 'apps/web',
2182
+ * port: 3001,
2183
+ * dependencies: ['api'], // <- autocomplete shows 'api' | 'web'
2184
+ * },
2185
+ * },
2186
+ * });
2187
+ *
2188
+ * // config.apps.api <- full type inference
2189
+ * // config.apps.foo <- TypeScript error
2190
+ * ```
2191
+ */
2192
+ function defineWorkspace(config) {
2193
+ assertNoMovedDeployKeys(config.deploy);
2194
+ assertKnownSecretsStore(config.secrets?.store);
2195
+ if (config.apps) validateDependencies(config.apps);
2196
+ const result = safeValidateWorkspaceConfig(config);
2197
+ if (!result.success && result.error) throw new Error(formatValidationErrors(result.error));
2198
+ return config;
2199
+ }
2200
+ /**
2201
+ * Get the package name from package.json in the given directory.
2202
+ */
2203
+ function getPackageName(cwd) {
2204
+ try {
2205
+ return require(`${cwd}/package.json`).name?.replace(/^@[^/]+\//, "");
2206
+ } catch {
2207
+ return;
2208
+ }
2209
+ }
2210
+ /**
2211
+ * Normalize a workspace configuration with resolved defaults.
2212
+ */
2213
+ function normalizeWorkspace(config, cwd) {
2214
+ const name = config.name ?? getPackageName(cwd) ?? (0, node_path.basename)(cwd);
2215
+ const defaultTarget = config.deploy?.default ?? "dokploy";
2216
+ const normalizedApps = {};
2217
+ for (const [appName, app] of Object.entries(config.apps ?? {})) normalizedApps[appName] = normalizeAppConfig(app, defaultTarget);
2218
+ return {
2219
+ name,
2220
+ root: cwd,
2221
+ ...config.constructs ? { constructs: config.constructs } : {},
2222
+ apps: normalizedApps,
2223
+ ...config.domains ? { domains: config.domains } : {},
2224
+ ...config.protectedSubdomains ? { protectedSubdomains: config.protectedSubdomains } : {},
2225
+ ...config.dns ? { dns: config.dns } : {},
2226
+ deploy: config.deploy ?? { default: "dokploy" },
2227
+ shared: config.shared ?? { packages: ["packages/*"] },
2228
+ stages: validateStages(config.stages),
2229
+ secrets: config.secrets ?? {},
2230
+ state: config.state,
2231
+ test: config.test ?? {},
2232
+ ...config.dev ? { dev: config.dev } : {}
2233
+ };
2234
+ }
2235
+ /**
2236
+ * Normalize an app configuration with resolved defaults.
2237
+ * @param app - App configuration
2238
+ * @param defaultTarget - Default deploy target from workspace config
2239
+ */
2240
+ function normalizeAppConfig(app, defaultTarget) {
2241
+ return {
2242
+ ...app,
2243
+ type: app.type ?? "backend",
2244
+ port: app.port,
2245
+ path: app.path,
2246
+ dependencies: app.dependencies ?? [],
2247
+ resolvedDeployTarget: app.deploy ?? defaultTarget
2248
+ };
2249
+ }
2250
+ /**
2251
+ * Wrap a single-app GkmConfig as a workspace.
2252
+ * This allows existing single-app configs to work seamlessly.
2253
+ */
2254
+ function wrapSingleAppAsWorkspace(config, cwd) {
2255
+ return {
2256
+ name: config.name ?? getPackageName(cwd) ?? (0, node_path.basename)(cwd),
2257
+ root: cwd,
2258
+ apps: { api: {
2259
+ type: "backend",
2260
+ path: ".",
2261
+ port: 3e3,
2262
+ dependencies: [],
2263
+ resolvedDeployTarget: config.deploy?.default ?? "dokploy",
2264
+ constructs: config.constructs,
2265
+ hooks: config.hooks,
2266
+ telescope: config.telescope,
2267
+ openapi: config.openapi,
2268
+ runtime: config.runtime,
2269
+ env: config.env
2270
+ } },
2271
+ ...config.domains ? { domains: config.domains } : {},
2272
+ ...config.dns ? { dns: config.dns } : {},
2273
+ deploy: {
2274
+ default: "dokploy",
2275
+ ...config.deploy
2276
+ },
2277
+ shared: { packages: [] },
2278
+ stages: validateStages(config.stages),
2279
+ secrets: config.secrets ?? {},
2280
+ test: config.test ?? {},
2281
+ ...config.dev ? { dev: config.dev } : {}
2282
+ };
2283
+ }
2284
+ /**
2285
+ * Process a loaded configuration (either single-app or workspace).
2286
+ * Returns a normalized workspace in both cases.
2287
+ */
2288
+ /**
2289
+ * `deploy.dokploy.registry`, which became `deploy.registry`: every target
2290
+ * pushes and pulls through the one registry, so it is not Dokploy's to hold.
2291
+ *
2292
+ * Refused by name rather than dropped: the schema strips keys it does not
2293
+ * know, and a registry silently gone would deploy images under no registry.
2294
+ */
2295
+ var DokployRegistryMoved = class extends require_errors.GkmError {
2296
+ registry;
2297
+ constructor(registry) {
2298
+ super(`deploy.dokploy.registry is now deploy.registry, read by every deploy target. In gkm.config.ts, move it up one level: deploy: { registry: ${JSON.stringify(registry)}, dokploy: { … } }.`);
2299
+ this.registry = registry;
2300
+ this.name = "DokployRegistryMoved";
2301
+ }
2302
+ };
2303
+ /**
2304
+ * `deploy.domains`, which became `domains` at the root of the config: a stage's
2305
+ * domain is a fact about the product every target and every command reads,
2306
+ * not a deploy setting.
2307
+ */
2308
+ var DomainsMoved = class extends require_errors.GkmError {
2309
+ domains;
2310
+ constructor(domains) {
2311
+ super(`deploy.domains is now domains, at the root of gkm.config.ts. Move it out of deploy: defineWorkspace({ …, domains: ${JSON.stringify(domains)}, deploy: { … } }).`);
2312
+ this.domains = domains;
2313
+ this.name = "DomainsMoved";
2314
+ }
2315
+ };
2316
+ /**
2317
+ * `deploy.dns`, which became `dns` at the root of the config, keyed by root
2318
+ * domain.
2319
+ */
2320
+ var DnsMoved = class extends require_errors.GkmError {
2321
+ dns;
2322
+ constructor(dns) {
2323
+ const legacy = dns && typeof dns === "object" && "domain" in dns && "provider" in dns;
2324
+ const { domain, ...rest } = legacy ? dns : {};
2325
+ super(`deploy.dns is now dns, at the root of gkm.config.ts, keyed by root domain. Move it out of deploy: defineWorkspace({ …, dns: ${JSON.stringify(legacy ? { [String(domain)]: rest } : dns)}, deploy: { … } }).`);
2326
+ this.dns = dns;
2327
+ this.name = "DnsMoved";
2328
+ }
2329
+ };
2330
+ /** Refuse a deploy key that has moved, naming where it lives now. */
2331
+ function assertNoMovedDeployKeys(deploy) {
2332
+ const dokploy = deploy?.dokploy;
2333
+ if (dokploy && typeof dokploy === "object" && "registry" in dokploy) throw new DokployRegistryMoved(dokploy.registry);
2334
+ if (deploy && typeof deploy === "object") {
2335
+ if ("domains" in deploy) throw new DomainsMoved(deploy.domains);
2336
+ if ("dns" in deploy) throw new DnsMoved(deploy.dns);
2337
+ }
2338
+ }
2339
+ function processConfig(config, cwd) {
2340
+ assertNoMovedDeployKeys(config.deploy);
2341
+ if (isWorkspaceConfig(config)) {
2342
+ assertKnownSecretsStore(config.secrets?.store);
2343
+ if (config.stages === void 0) throw new InvalidStages(stageProblems(void 0));
2344
+ const result = safeValidateWorkspaceConfig(config);
2345
+ if (!result.success && result.error) throw new InvalidWorkspaceConfig(formatValidationErrors(result.error));
2346
+ return {
2347
+ type: "workspace",
2348
+ raw: config,
2349
+ workspace: normalizeWorkspace(config, cwd)
2350
+ };
2351
+ }
2352
+ return {
2353
+ type: "single",
2354
+ raw: config,
2355
+ workspace: wrapSingleAppAsWorkspace(config, cwd)
2356
+ };
2357
+ }
2358
+ /** A workspace config the schema refuses; the message lists every issue. */
2359
+ var InvalidWorkspaceConfig = class extends require_errors.GkmError {
2360
+ constructor(message) {
2361
+ super(message);
2362
+ this.name = "InvalidWorkspaceConfig";
2363
+ }
2364
+ };
2365
+ /**
2366
+ * The workspace's own constructs globs, absolute.
2367
+ *
2368
+ * Infrastructure two apps share is a fact about the product, and declaring it
2369
+ * inside one of them makes moving that app a change to the other's database.
2370
+ */
2371
+ function workspaceConstructGlobs(workspace) {
2372
+ return constructPatterns(workspace.constructs).map((pattern) => (0, node_path.isAbsolute)(pattern) ? pattern : (0, node_path.join)(workspace.root, pattern));
2373
+ }
2374
+ /**
2375
+ * Every constructs glob an app can see, absolute.
2376
+ *
2377
+ * The workspace's own first, then the app's. Absolute because the app builds
2378
+ * from its own directory while the workspace's constructs live above it —
2379
+ * a relative glob resolved from the app would look for the product's
2380
+ * infrastructure inside one of its consumers and find nothing.
2381
+ *
2382
+ * Additive, not overriding: an app that declares its own constructs still sees
2383
+ * the ones the workspace declared for everybody.
2384
+ */
2385
+ function appConstructGlobs(workspace, appName) {
2386
+ const globs = workspaceConstructGlobs(workspace);
2387
+ const app = workspace.apps[appName];
2388
+ if (app) {
2389
+ const root = (0, node_path.isAbsolute)(app.path) ? app.path : (0, node_path.join)(workspace.root, app.path);
2390
+ for (const pattern of constructPatterns(app.constructs)) globs.push((0, node_path.isAbsolute)(pattern) ? pattern : (0, node_path.join)(root, pattern));
2391
+ }
2392
+ return globs;
2393
+ }
2394
+ /**
2395
+ * Every constructs glob in the workspace: its own, plus each app's.
2396
+ *
2397
+ * One list, so what a deploy provisions and what an app's entry point
2398
+ * registers drivers for are read off the same globs.
2399
+ */
2400
+ function allConstructGlobs(workspace) {
2401
+ const globs = [...workspaceConstructGlobs(workspace), ...Object.keys(workspace.apps).flatMap((appName) => appConstructGlobs(workspace, appName))];
2402
+ return [...new Set(globs)];
2403
+ }
2404
+ /** A `Routes` in any of its accepted shapes, as a flat list of patterns. */
2405
+ function constructPatterns(routes) {
2406
+ if (!routes) return [];
2407
+ return typeof routes === "string" ? [routes] : routes;
2408
+ }
2409
+ /**
2410
+ * Get the GkmConfig for a specific app in a workspace.
2411
+ * Useful for running existing single-app commands on a specific app.
2412
+ */
2413
+ function getAppGkmConfig(workspace, appName) {
2414
+ const app = workspace.apps[appName];
2415
+ if (!app || app.type !== "backend") return;
2416
+ return {
2417
+ ...workspace.deploy ? { deploy: workspace.deploy } : {},
2418
+ stages: workspace.stages,
2419
+ constructs: appConstructGlobs(workspace, appName),
2420
+ hooks: app.hooks,
2421
+ telescope: app.telescope,
2422
+ openapi: app.openapi,
2423
+ runtime: app.runtime,
2424
+ env: app.env
2425
+ };
2426
+ }
2427
+ /**
2428
+ * Get topologically sorted app names based on dependencies.
2429
+ * Apps with no dependencies come first, then apps that depend on them.
2430
+ */
2431
+ function getAppBuildOrder(workspace) {
2432
+ const appNames = Object.keys(workspace.apps);
2433
+ const visited = /* @__PURE__ */ new Set();
2434
+ const result = [];
2435
+ function visit(name) {
2436
+ if (visited.has(name)) return;
2437
+ visited.add(name);
2438
+ const app = workspace.apps[name];
2439
+ if (app) for (const dep of app.dependencies) visit(dep);
2440
+ result.push(name);
2441
+ }
2442
+ for (const name of appNames) visit(name);
2443
+ return result;
2444
+ }
2445
+ /**
2446
+ * Resolve the Dokploy endpoint for a specific stage.
2447
+ *
2448
+ * Uses per-stage endpoint from `endpoints` if available,
2449
+ * otherwise falls back to the global `endpoint`.
2450
+ *
2451
+ * @param dokployConfig - Dokploy workspace configuration
2452
+ * @param stage - Deployment stage (e.g., 'development', 'production')
2453
+ * @returns The endpoint URL for the stage, or undefined if not configured
2454
+ *
2455
+ * @example
2456
+ * ```ts
2457
+ * // With per-stage endpoints
2458
+ * const config = {
2459
+ * endpoints: {
2460
+ * development: 'https://dev.dokploy.example.com:3000',
2461
+ * production: 'https://prod.dokploy.example.com:3000',
2462
+ * },
2463
+ * };
2464
+ * getEndpointForStage(config, 'production'); // => 'https://prod.dokploy.example.com:3000'
2465
+ *
2466
+ * // With single endpoint
2467
+ * const config = { endpoint: 'https://dokploy.example.com:3000' };
2468
+ * getEndpointForStage(config, 'production'); // => 'https://dokploy.example.com:3000'
2469
+ * ```
2470
+ */
2471
+ function getEndpointForStage(dokployConfig, stage) {
2472
+ if (!dokployConfig) return void 0;
2473
+ if (dokployConfig.endpoints?.[stage]) return dokployConfig.endpoints[stage];
2474
+ return dokployConfig.endpoint;
2475
+ }
2476
+ //#endregion
2477
+ Object.defineProperty(exports, "AccessKeyLimit", {
2478
+ enumerable: true,
2479
+ get: function() {
2480
+ return AccessKeyLimit;
2481
+ }
2482
+ });
2483
+ Object.defineProperty(exports, "BucketKeySetElsewhere", {
2484
+ enumerable: true,
2485
+ get: function() {
2486
+ return BucketKeySetElsewhere;
2487
+ }
2488
+ });
2489
+ Object.defineProperty(exports, "BucketNameUnavailable", {
2490
+ enumerable: true,
2491
+ get: function() {
2492
+ return BucketNameUnavailable;
2493
+ }
2494
+ });
2495
+ Object.defineProperty(exports, "BucketOwnedByAnotherProject", {
2496
+ enumerable: true,
2497
+ get: function() {
2498
+ return BucketOwnedByAnotherProject;
2499
+ }
2500
+ });
2501
+ Object.defineProperty(exports, "BucketProbeFailed", {
2502
+ enumerable: true,
2503
+ get: function() {
2504
+ return BucketProbeFailed;
2505
+ }
2506
+ });
2507
+ Object.defineProperty(exports, "BucketRegionMismatch", {
2508
+ enumerable: true,
2509
+ get: function() {
2510
+ return BucketRegionMismatch;
2511
+ }
2512
+ });
2513
+ Object.defineProperty(exports, "BucketRegionUnknown", {
2514
+ enumerable: true,
2515
+ get: function() {
2516
+ return BucketRegionUnknown;
2517
+ }
2518
+ });
2519
+ Object.defineProperty(exports, "ComposeTlsFileMissing", {
2520
+ enumerable: true,
2521
+ get: function() {
2522
+ return ComposeTlsFileMissing;
2523
+ }
2524
+ });
2525
+ Object.defineProperty(exports, "DnsMoved", {
2526
+ enumerable: true,
2527
+ get: function() {
2528
+ return DnsMoved;
2529
+ }
2530
+ });
2531
+ Object.defineProperty(exports, "DokployRegistryMoved", {
2532
+ enumerable: true,
2533
+ get: function() {
2534
+ return DokployRegistryMoved;
2535
+ }
2536
+ });
2537
+ Object.defineProperty(exports, "DomainsMoved", {
2538
+ enumerable: true,
2539
+ get: function() {
2540
+ return DomainsMoved;
2541
+ }
2542
+ });
2543
+ Object.defineProperty(exports, "IamUserNotOwned", {
2544
+ enumerable: true,
2545
+ get: function() {
2546
+ return IamUserNotOwned;
2547
+ }
2548
+ });
2549
+ Object.defineProperty(exports, "InboxNotProvisioned", {
2550
+ enumerable: true,
2551
+ get: function() {
2552
+ return InboxNotProvisioned;
2553
+ }
2554
+ });
2555
+ Object.defineProperty(exports, "InvalidStages", {
2556
+ enumerable: true,
2557
+ get: function() {
2558
+ return InvalidStages;
2559
+ }
2560
+ });
2561
+ Object.defineProperty(exports, "InvalidWorkspaceConfig", {
2562
+ enumerable: true,
2563
+ get: function() {
2564
+ return InvalidWorkspaceConfig;
2565
+ }
2566
+ });
2567
+ Object.defineProperty(exports, "LOGS_PORT", {
2568
+ enumerable: true,
2569
+ get: function() {
2570
+ return LOGS_PORT;
2571
+ }
2572
+ });
2573
+ Object.defineProperty(exports, "PHASE_2_DEPLOY_TARGETS", {
2574
+ enumerable: true,
2575
+ get: function() {
2576
+ return PHASE_2_DEPLOY_TARGETS;
2577
+ }
2578
+ });
2579
+ Object.defineProperty(exports, "PUBLIC_ENV_PREFIXES", {
2580
+ enumerable: true,
2581
+ get: function() {
2582
+ return PUBLIC_ENV_PREFIXES;
2583
+ }
2584
+ });
2585
+ Object.defineProperty(exports, "ProvisionedBucketUnreachable", {
2586
+ enumerable: true,
2587
+ get: function() {
2588
+ return ProvisionedBucketUnreachable;
2589
+ }
2590
+ });
2591
+ Object.defineProperty(exports, "RecordedBucketUnreachable", {
2592
+ enumerable: true,
2593
+ get: function() {
2594
+ return RecordedBucketUnreachable;
2595
+ }
2596
+ });
2597
+ Object.defineProperty(exports, "RotationInProgress", {
2598
+ enumerable: true,
2599
+ get: function() {
2600
+ return RotationInProgress;
2601
+ }
2602
+ });
2603
+ Object.defineProperty(exports, "S3RegionRequired", {
2604
+ enumerable: true,
2605
+ get: function() {
2606
+ return S3RegionRequired;
2607
+ }
2608
+ });
2609
+ Object.defineProperty(exports, "S3_PROVISIONING", {
2610
+ enumerable: true,
2611
+ get: function() {
2612
+ return S3_PROVISIONING;
2613
+ }
2614
+ });
2615
+ Object.defineProperty(exports, "SECRETS_STORE_PROVIDERS", {
2616
+ enumerable: true,
2617
+ get: function() {
2618
+ return SECRETS_STORE_PROVIDERS;
2619
+ }
2620
+ });
2621
+ Object.defineProperty(exports, "SERVER_IPV4_KEY", {
2622
+ enumerable: true,
2623
+ get: function() {
2624
+ return SERVER_IPV4_KEY;
2625
+ }
2626
+ });
2627
+ Object.defineProperty(exports, "SERVER_IPV6_KEY", {
2628
+ enumerable: true,
2629
+ get: function() {
2630
+ return SERVER_IPV6_KEY;
2631
+ }
2632
+ });
2633
+ Object.defineProperty(exports, "SES_PROVISIONING", {
2634
+ enumerable: true,
2635
+ get: function() {
2636
+ return SES_PROVISIONING;
2637
+ }
2638
+ });
2639
+ Object.defineProperty(exports, "SUPPORTED_DEPLOY_TARGETS", {
2640
+ enumerable: true,
2641
+ get: function() {
2642
+ return SUPPORTED_DEPLOY_TARGETS;
2643
+ }
2644
+ });
2645
+ Object.defineProperty(exports, "SesReceivingUnsupported", {
2646
+ enumerable: true,
2647
+ get: function() {
2648
+ return SesReceivingUnsupported;
2649
+ }
2650
+ });
2651
+ Object.defineProperty(exports, "TEST_STAGE", {
2652
+ enumerable: true,
2653
+ get: function() {
2654
+ return TEST_STAGE;
2655
+ }
2656
+ });
2657
+ Object.defineProperty(exports, "UndeclaredStage", {
2658
+ enumerable: true,
2659
+ get: function() {
2660
+ return UndeclaredStage;
2661
+ }
2662
+ });
2663
+ Object.defineProperty(exports, "UnknownSecretsStoreProvider", {
2664
+ enumerable: true,
2665
+ get: function() {
2666
+ return UnknownSecretsStoreProvider;
2667
+ }
2668
+ });
2669
+ Object.defineProperty(exports, "UnknownStageProvider", {
2670
+ enumerable: true,
2671
+ get: function() {
2672
+ return UnknownStageProvider;
2673
+ }
2674
+ });
2675
+ Object.defineProperty(exports, "WorkspaceConfigSchema", {
2676
+ enumerable: true,
2677
+ get: function() {
2678
+ return WorkspaceConfigSchema;
2679
+ }
2680
+ });
2681
+ Object.defineProperty(exports, "allConstructGlobs", {
2682
+ enumerable: true,
2683
+ get: function() {
2684
+ return allConstructGlobs;
2685
+ }
2686
+ });
2687
+ Object.defineProperty(exports, "appConstructGlobs", {
2688
+ enumerable: true,
2689
+ get: function() {
2690
+ return appConstructGlobs;
2691
+ }
2692
+ });
2693
+ Object.defineProperty(exports, "assertDeployedStage", {
2694
+ enumerable: true,
2695
+ get: function() {
2696
+ return assertDeployedStage;
2697
+ }
2698
+ });
2699
+ Object.defineProperty(exports, "assertNoMovedDeployKeys", {
2700
+ enumerable: true,
2701
+ get: function() {
2702
+ return assertNoMovedDeployKeys;
2703
+ }
2704
+ });
2705
+ Object.defineProperty(exports, "certificateFor", {
2706
+ enumerable: true,
2707
+ get: function() {
2708
+ return certificateFor;
2709
+ }
2710
+ });
2711
+ Object.defineProperty(exports, "checkS3Config", {
2712
+ enumerable: true,
2713
+ get: function() {
2714
+ return checkS3Config;
2715
+ }
2716
+ });
2717
+ Object.defineProperty(exports, "checkSesConfig", {
2718
+ enumerable: true,
2719
+ get: function() {
2720
+ return checkSesConfig;
2721
+ }
2722
+ });
2723
+ Object.defineProperty(exports, "checkStageBackups", {
2724
+ enumerable: true,
2725
+ get: function() {
2726
+ return checkStageBackups;
2727
+ }
2728
+ });
2729
+ Object.defineProperty(exports, "cnameTarget", {
2730
+ enumerable: true,
2731
+ get: function() {
2732
+ return cnameTarget;
2733
+ }
2734
+ });
2735
+ Object.defineProperty(exports, "constructPatterns", {
2736
+ enumerable: true,
2737
+ get: function() {
2738
+ return constructPatterns;
2739
+ }
2740
+ });
2741
+ Object.defineProperty(exports, "defineWorkspace", {
2742
+ enumerable: true,
2743
+ get: function() {
2744
+ return defineWorkspace;
2745
+ }
2746
+ });
2747
+ Object.defineProperty(exports, "deployedProblems", {
2748
+ enumerable: true,
2749
+ get: function() {
2750
+ return deployedProblems;
2751
+ }
2752
+ });
2753
+ Object.defineProperty(exports, "formatValidationErrors", {
2754
+ enumerable: true,
2755
+ get: function() {
2756
+ return formatValidationErrors;
2757
+ }
2758
+ });
2759
+ Object.defineProperty(exports, "getAppBuildOrder", {
2760
+ enumerable: true,
2761
+ get: function() {
2762
+ return getAppBuildOrder;
2763
+ }
2764
+ });
2765
+ Object.defineProperty(exports, "getAppGkmConfig", {
2766
+ enumerable: true,
2767
+ get: function() {
2768
+ return getAppGkmConfig;
2769
+ }
2770
+ });
2771
+ Object.defineProperty(exports, "getDeployTargetError", {
2772
+ enumerable: true,
2773
+ get: function() {
2774
+ return getDeployTargetError;
2775
+ }
2776
+ });
2777
+ Object.defineProperty(exports, "getEndpointForStage", {
2778
+ enumerable: true,
2779
+ get: function() {
2780
+ return getEndpointForStage;
2781
+ }
2782
+ });
2783
+ Object.defineProperty(exports, "getPublicEnvPrefix", {
2784
+ enumerable: true,
2785
+ get: function() {
2786
+ return getPublicEnvPrefix;
2787
+ }
2788
+ });
2789
+ Object.defineProperty(exports, "isDeployTargetSupported", {
2790
+ enumerable: true,
2791
+ get: function() {
2792
+ return isDeployTargetSupported;
2793
+ }
2794
+ });
2795
+ Object.defineProperty(exports, "isPhase2DeployTarget", {
2796
+ enumerable: true,
2797
+ get: function() {
2798
+ return isPhase2DeployTarget;
2799
+ }
2800
+ });
2801
+ Object.defineProperty(exports, "isReservedStageKey", {
2802
+ enumerable: true,
2803
+ get: function() {
2804
+ return isReservedStageKey;
2805
+ }
2806
+ });
2807
+ Object.defineProperty(exports, "isWorkspaceConfig", {
2808
+ enumerable: true,
2809
+ get: function() {
2810
+ return isWorkspaceConfig;
2811
+ }
2812
+ });
2813
+ Object.defineProperty(exports, "normalizeWorkspace", {
2814
+ enumerable: true,
2815
+ get: function() {
2816
+ return normalizeWorkspace;
2817
+ }
2818
+ });
2819
+ Object.defineProperty(exports, "otlpTelemetryEnv", {
2820
+ enumerable: true,
2821
+ get: function() {
2822
+ return otlpTelemetryEnv;
2823
+ }
2824
+ });
2825
+ Object.defineProperty(exports, "processConfig", {
2826
+ enumerable: true,
2827
+ get: function() {
2828
+ return processConfig;
2829
+ }
2830
+ });
2831
+ Object.defineProperty(exports, "provisioningOf", {
2832
+ enumerable: true,
2833
+ get: function() {
2834
+ return provisioningOf;
2835
+ }
2836
+ });
2837
+ Object.defineProperty(exports, "proxyFor", {
2838
+ enumerable: true,
2839
+ get: function() {
2840
+ return proxyFor;
2841
+ }
2842
+ });
2843
+ Object.defineProperty(exports, "resolveStageTelemetry", {
2844
+ enumerable: true,
2845
+ get: function() {
2846
+ return resolveStageTelemetry;
2847
+ }
2848
+ });
2849
+ Object.defineProperty(exports, "s3SecretsKey", {
2850
+ enumerable: true,
2851
+ get: function() {
2852
+ return s3SecretsKey;
2853
+ }
2854
+ });
2855
+ Object.defineProperty(exports, "s3SecretsLocation", {
2856
+ enumerable: true,
2857
+ get: function() {
2858
+ return s3SecretsLocation;
2859
+ }
2860
+ });
2861
+ Object.defineProperty(exports, "safeValidateWorkspaceConfig", {
2862
+ enumerable: true,
2863
+ get: function() {
2864
+ return safeValidateWorkspaceConfig;
2865
+ }
2866
+ });
2867
+ Object.defineProperty(exports, "stageProblems", {
2868
+ enumerable: true,
2869
+ get: function() {
2870
+ return stageProblems;
2871
+ }
2872
+ });
2873
+ Object.defineProperty(exports, "stageProvider", {
2874
+ enumerable: true,
2875
+ get: function() {
2876
+ return stageProvider;
2877
+ }
2878
+ });
2879
+ Object.defineProperty(exports, "stageSampleRate", {
2880
+ enumerable: true,
2881
+ get: function() {
2882
+ return stageSampleRate;
2883
+ }
2884
+ });
2885
+ Object.defineProperty(exports, "stripPublicPrefix", {
2886
+ enumerable: true,
2887
+ get: function() {
2888
+ return stripPublicPrefix;
2889
+ }
2890
+ });
2891
+ Object.defineProperty(exports, "telemetryEnv", {
2892
+ enumerable: true,
2893
+ get: function() {
2894
+ return telemetryEnv;
2895
+ }
2896
+ });
2897
+ Object.defineProperty(exports, "validateWorkspaceConfig", {
2898
+ enumerable: true,
2899
+ get: function() {
2900
+ return validateWorkspaceConfig;
2901
+ }
2902
+ });
2903
+ Object.defineProperty(exports, "workspaceConstructGlobs", {
2904
+ enumerable: true,
2905
+ get: function() {
2906
+ return workspaceConstructGlobs;
2907
+ }
2908
+ });
2909
+ Object.defineProperty(exports, "wrapSingleAppAsWorkspace", {
2910
+ enumerable: true,
2911
+ get: function() {
2912
+ return wrapSingleAppAsWorkspace;
2913
+ }
2914
+ });
2915
+
2916
+ //# sourceMappingURL=workspace-1szcahj9.cjs.map