cloud.ts 3.2 KB

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