cloud.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { WebhookEndpoint } from "pulumi-stripe"
  2. import { domain } from "./stage"
  3. ////////////////
  4. // DATABASE
  5. ////////////////
  6. const DATABASE_USERNAME = new sst.Secret("DATABASE_USERNAME")
  7. const DATABASE_PASSWORD = new sst.Secret("DATABASE_PASSWORD")
  8. export const database = new sst.Linkable("Database", {
  9. properties: {
  10. host: `aws-us-east-2-${$app.stage === "thdxr" ? "2" : "1"}.pg.psdb.cloud`,
  11. database: "postgres",
  12. username: DATABASE_USERNAME.value,
  13. password: DATABASE_PASSWORD.value,
  14. port: 5432,
  15. },
  16. })
  17. new sst.x.DevCommand("Studio", {
  18. link: [database],
  19. dev: {
  20. command: "bun db studio",
  21. directory: "cloud/core",
  22. autostart: true,
  23. },
  24. })
  25. ////////////////
  26. // AUTH
  27. ////////////////
  28. const GITHUB_CLIENT_ID_CONSOLE = new sst.Secret("GITHUB_CLIENT_ID_CONSOLE")
  29. const GITHUB_CLIENT_SECRET_CONSOLE = new sst.Secret("GITHUB_CLIENT_SECRET_CONSOLE")
  30. const GOOGLE_CLIENT_ID = new sst.Secret("GOOGLE_CLIENT_ID")
  31. const authStorage = new sst.cloudflare.Kv("AuthStorage")
  32. export const auth = new sst.cloudflare.Worker("AuthApi", {
  33. domain: `auth.${domain}`,
  34. handler: "cloud/function/src/auth.ts",
  35. url: true,
  36. link: [database, authStorage, GITHUB_CLIENT_ID_CONSOLE, GITHUB_CLIENT_SECRET_CONSOLE, GOOGLE_CLIENT_ID],
  37. })
  38. ////////////////
  39. // GATEWAY
  40. ////////////////
  41. export const stripeWebhook = new WebhookEndpoint("StripeWebhook", {
  42. url: $interpolate`https://console.${domain}/stripe/webhook`,
  43. enabledEvents: [
  44. "checkout.session.async_payment_failed",
  45. "checkout.session.async_payment_succeeded",
  46. "checkout.session.completed",
  47. "checkout.session.expired",
  48. "customer.created",
  49. "customer.deleted",
  50. "customer.updated",
  51. "customer.discount.created",
  52. "customer.discount.deleted",
  53. "customer.discount.updated",
  54. "customer.source.created",
  55. "customer.source.deleted",
  56. "customer.source.expiring",
  57. "customer.source.updated",
  58. "customer.subscription.created",
  59. "customer.subscription.deleted",
  60. "customer.subscription.paused",
  61. "customer.subscription.pending_update_applied",
  62. "customer.subscription.pending_update_expired",
  63. "customer.subscription.resumed",
  64. "customer.subscription.trial_will_end",
  65. "customer.subscription.updated",
  66. "customer.tax_id.created",
  67. "customer.tax_id.deleted",
  68. "customer.tax_id.updated",
  69. ],
  70. })
  71. const ANTHROPIC_API_KEY = new sst.Secret("ANTHROPIC_API_KEY")
  72. const OPENAI_API_KEY = new sst.Secret("OPENAI_API_KEY")
  73. const ZHIPU_API_KEY = new sst.Secret("ZHIPU_API_KEY")
  74. const STRIPE_SECRET_KEY = new sst.Secret("STRIPE_SECRET_KEY")
  75. const AUTH_API_URL = new sst.Linkable("AUTH_API_URL", {
  76. properties: { value: auth.url.apply((url) => url!) },
  77. })
  78. const STRIPE_WEBHOOK_SECRET = new sst.Linkable("STRIPE_WEBHOOK_SECRET", {
  79. properties: { value: stripeWebhook.secret },
  80. })
  81. export const gateway = new sst.cloudflare.Worker("GatewayApi", {
  82. domain: `api.gateway.${domain}`,
  83. handler: "cloud/function/src/gateway.ts",
  84. url: true,
  85. link: [
  86. database,
  87. AUTH_API_URL,
  88. STRIPE_WEBHOOK_SECRET,
  89. STRIPE_SECRET_KEY,
  90. ANTHROPIC_API_KEY,
  91. OPENAI_API_KEY,
  92. ZHIPU_API_KEY,
  93. ],
  94. })
  95. ////////////////
  96. // CONSOLE
  97. ////////////////
  98. export const console = new sst.cloudflare.x.SolidStart("Console", {
  99. domain: `console.${domain}`,
  100. path: "cloud/app",
  101. link: [
  102. database,
  103. AUTH_API_URL,
  104. STRIPE_WEBHOOK_SECRET,
  105. STRIPE_SECRET_KEY,
  106. ANTHROPIC_API_KEY,
  107. OPENAI_API_KEY,
  108. ZHIPU_API_KEY,
  109. ],
  110. environment: {
  111. //VITE_DOCS_URL: web.url.apply((url) => url!),
  112. //VITE_API_URL: gateway.url.apply((url) => url!),
  113. VITE_AUTH_URL: auth.url.apply((url) => url!),
  114. },
  115. })