console.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { domain } from "./stage"
  2. ////////////////
  3. // DATABASE
  4. ////////////////
  5. const cluster = planetscale.getDatabaseOutput({
  6. name: "opencode",
  7. organization: "anomalyco",
  8. })
  9. const branch =
  10. $app.stage === "production"
  11. ? planetscale.getBranchOutput({
  12. name: "production",
  13. organization: cluster.organization,
  14. database: cluster.name,
  15. })
  16. : new planetscale.Branch("DatabaseBranch", {
  17. database: cluster.name,
  18. organization: cluster.organization,
  19. name: $app.stage,
  20. parentBranch: "production",
  21. })
  22. const password = new planetscale.Password("DatabasePassword", {
  23. name: $app.stage,
  24. database: cluster.name,
  25. organization: cluster.organization,
  26. branch: branch.name,
  27. })
  28. export const database = new sst.Linkable("Database", {
  29. properties: {
  30. host: password.accessHostUrl,
  31. database: cluster.name,
  32. username: password.username,
  33. password: password.plaintext,
  34. port: 3306,
  35. },
  36. })
  37. new sst.x.DevCommand("Studio", {
  38. link: [database],
  39. dev: {
  40. command: "bun db studio",
  41. directory: "packages/console/core",
  42. autostart: true,
  43. },
  44. })
  45. ////////////////
  46. // AUTH
  47. ////////////////
  48. const GITHUB_CLIENT_ID_CONSOLE = new sst.Secret("GITHUB_CLIENT_ID_CONSOLE")
  49. const GITHUB_CLIENT_SECRET_CONSOLE = new sst.Secret("GITHUB_CLIENT_SECRET_CONSOLE")
  50. const GOOGLE_CLIENT_ID = new sst.Secret("GOOGLE_CLIENT_ID")
  51. const authStorage = new sst.cloudflare.Kv("AuthStorage")
  52. export const auth = new sst.cloudflare.Worker("AuthApi", {
  53. domain: `auth.${domain}`,
  54. handler: "packages/console/function/src/auth.ts",
  55. url: true,
  56. link: [database, authStorage, GITHUB_CLIENT_ID_CONSOLE, GITHUB_CLIENT_SECRET_CONSOLE, GOOGLE_CLIENT_ID],
  57. })
  58. ////////////////
  59. // GATEWAY
  60. ////////////////
  61. export const stripeWebhook = new stripe.WebhookEndpoint("StripeWebhookEndpoint", {
  62. url: $interpolate`https://${domain}/stripe/webhook`,
  63. enabledEvents: [
  64. "checkout.session.async_payment_failed",
  65. "checkout.session.async_payment_succeeded",
  66. "checkout.session.completed",
  67. "checkout.session.expired",
  68. "charge.refunded",
  69. "customer.created",
  70. "customer.deleted",
  71. "customer.updated",
  72. "customer.discount.created",
  73. "customer.discount.deleted",
  74. "customer.discount.updated",
  75. "customer.source.created",
  76. "customer.source.deleted",
  77. "customer.source.expiring",
  78. "customer.source.updated",
  79. "customer.subscription.created",
  80. "customer.subscription.deleted",
  81. "customer.subscription.paused",
  82. "customer.subscription.pending_update_applied",
  83. "customer.subscription.pending_update_expired",
  84. "customer.subscription.resumed",
  85. "customer.subscription.trial_will_end",
  86. "customer.subscription.updated",
  87. ],
  88. })
  89. const ZEN_MODELS = new sst.Secret("ZEN_MODELS")
  90. const STRIPE_SECRET_KEY = new sst.Secret("STRIPE_SECRET_KEY")
  91. const AUTH_API_URL = new sst.Linkable("AUTH_API_URL", {
  92. properties: { value: auth.url.apply((url) => url!) },
  93. })
  94. const STRIPE_WEBHOOK_SECRET = new sst.Linkable("STRIPE_WEBHOOK_SECRET", {
  95. properties: { value: stripeWebhook.secret },
  96. })
  97. ////////////////
  98. // CONSOLE
  99. ////////////////
  100. let logProcessor
  101. if ($app.stage === "production" || $app.stage === "frank") {
  102. const HONEYCOMB_API_KEY = new sst.Secret("HONEYCOMB_API_KEY")
  103. logProcessor = new sst.cloudflare.Worker("LogProcessor", {
  104. handler: "packages/console/function/src/log-processor.ts",
  105. link: [HONEYCOMB_API_KEY],
  106. })
  107. }
  108. new sst.cloudflare.x.SolidStart("Console", {
  109. domain,
  110. path: "packages/console/app",
  111. link: [database, AUTH_API_URL, STRIPE_WEBHOOK_SECRET, STRIPE_SECRET_KEY, ZEN_MODELS],
  112. environment: {
  113. //VITE_DOCS_URL: web.url.apply((url) => url!),
  114. //VITE_API_URL: gateway.url.apply((url) => url!),
  115. VITE_AUTH_URL: auth.url.apply((url) => url!),
  116. },
  117. transform: {
  118. server: {
  119. transform: {
  120. worker: {
  121. placement: { mode: "smart" },
  122. tailConsumers: logProcessor ? [{ service: logProcessor.nodes.worker.scriptName }] : [],
  123. },
  124. },
  125. },
  126. },
  127. })