opencode_offline/infra/console.ts

154 lines
4.2 KiB
TypeScript
Raw Normal View History

2025-08-09 01:22:54 +08:00
import { domain } from "./stage"
2025-09-30 02:17:53 +08:00
import { EMAILOCTOPUS_API_KEY } from "./app"
2025-08-09 01:22:54 +08:00
2025-08-10 13:17:48 +08:00
////////////////
// DATABASE
////////////////
2025-08-09 01:22:54 +08:00
2025-09-02 15:14:56 +08:00
const cluster = planetscale.getDatabaseOutput({
name: "opencode",
2025-09-09 03:46:57 +08:00
organization: "anomalyco",
2025-09-02 15:14:56 +08:00
})
const branch =
$app.stage === "production"
? planetscale.getBranchOutput({
name: "production",
organization: cluster.organization,
database: cluster.name,
})
: new planetscale.Branch("DatabaseBranch", {
database: cluster.name,
organization: cluster.organization,
name: $app.stage,
parentBranch: "production",
})
const password = new planetscale.Password("DatabasePassword", {
name: $app.stage,
database: cluster.name,
organization: cluster.organization,
branch: branch.name,
})
2025-08-09 01:22:54 +08:00
export const database = new sst.Linkable("Database", {
properties: {
2025-09-02 15:14:56 +08:00
host: password.accessHostUrl,
database: cluster.name,
username: password.username,
password: password.plaintext,
port: 3306,
2025-08-09 01:22:54 +08:00
},
})
new sst.x.DevCommand("Studio", {
link: [database],
dev: {
command: "bun db studio",
2025-09-18 22:59:01 +08:00
directory: "packages/console/core",
2025-08-09 01:22:54 +08:00
autostart: true,
},
})
2025-08-10 13:17:48 +08:00
////////////////
// AUTH
////////////////
2025-08-09 01:22:54 +08:00
const GITHUB_CLIENT_ID_CONSOLE = new sst.Secret("GITHUB_CLIENT_ID_CONSOLE")
const GITHUB_CLIENT_SECRET_CONSOLE = new sst.Secret("GITHUB_CLIENT_SECRET_CONSOLE")
2025-08-09 13:28:27 +08:00
const GOOGLE_CLIENT_ID = new sst.Secret("GOOGLE_CLIENT_ID")
2025-08-09 01:22:54 +08:00
const authStorage = new sst.cloudflare.Kv("AuthStorage")
export const auth = new sst.cloudflare.Worker("AuthApi", {
domain: `auth.${domain}`,
2025-09-18 22:59:01 +08:00
handler: "packages/console/function/src/auth.ts",
2025-08-09 01:22:54 +08:00
url: true,
2025-08-09 13:28:27 +08:00
link: [database, authStorage, GITHUB_CLIENT_ID_CONSOLE, GITHUB_CLIENT_SECRET_CONSOLE, GOOGLE_CLIENT_ID],
2025-08-09 01:22:54 +08:00
})
2025-08-10 13:17:48 +08:00
////////////////
// GATEWAY
////////////////
2025-09-26 19:54:30 +08:00
export const stripeWebhook = new stripe.WebhookEndpoint("StripeWebhookEndpoint", {
2025-09-03 23:40:59 +08:00
url: $interpolate`https://${domain}/stripe/webhook`,
2025-08-10 13:17:48 +08:00
enabledEvents: [
"checkout.session.async_payment_failed",
"checkout.session.async_payment_succeeded",
"checkout.session.completed",
"checkout.session.expired",
2025-09-24 05:58:26 +08:00
"charge.refunded",
2025-08-10 13:17:48 +08:00
"customer.created",
"customer.deleted",
"customer.updated",
"customer.discount.created",
"customer.discount.deleted",
"customer.discount.updated",
"customer.source.created",
"customer.source.deleted",
"customer.source.expiring",
"customer.source.updated",
"customer.subscription.created",
"customer.subscription.deleted",
"customer.subscription.paused",
"customer.subscription.pending_update_applied",
"customer.subscription.pending_update_expired",
"customer.subscription.resumed",
"customer.subscription.trial_will_end",
"customer.subscription.updated",
],
})
2025-09-20 02:08:02 +08:00
const ZEN_MODELS = new sst.Secret("ZEN_MODELS")
2025-08-09 01:22:54 +08:00
const STRIPE_SECRET_KEY = new sst.Secret("STRIPE_SECRET_KEY")
const AUTH_API_URL = new sst.Linkable("AUTH_API_URL", {
properties: { value: auth.url.apply((url) => url!) },
})
const STRIPE_WEBHOOK_SECRET = new sst.Linkable("STRIPE_WEBHOOK_SECRET", {
properties: { value: stripeWebhook.secret },
})
2025-08-10 13:17:48 +08:00
////////////////
// CONSOLE
////////////////
2025-10-02 07:34:37 +08:00
const AWS_SES_ACCESS_KEY_ID = new sst.Secret("AWS_SES_ACCESS_KEY_ID")
const AWS_SES_SECRET_ACCESS_KEY = new sst.Secret("AWS_SES_SECRET_ACCESS_KEY")
2025-09-09 03:46:57 +08:00
let logProcessor
if ($app.stage === "production" || $app.stage === "frank") {
2025-09-09 03:57:29 +08:00
const HONEYCOMB_API_KEY = new sst.Secret("HONEYCOMB_API_KEY")
2025-09-09 03:46:57 +08:00
logProcessor = new sst.cloudflare.Worker("LogProcessor", {
2025-09-18 22:59:01 +08:00
handler: "packages/console/function/src/log-processor.ts",
2025-09-09 03:46:57 +08:00
link: [HONEYCOMB_API_KEY],
})
}
2025-09-02 15:14:56 +08:00
new sst.cloudflare.x.SolidStart("Console", {
2025-09-03 11:56:10 +08:00
domain,
2025-09-18 22:59:01 +08:00
path: "packages/console/app",
2025-10-02 07:34:37 +08:00
link: [
database,
AUTH_API_URL,
STRIPE_WEBHOOK_SECRET,
STRIPE_SECRET_KEY,
ZEN_MODELS,
EMAILOCTOPUS_API_KEY,
AWS_SES_ACCESS_KEY_ID,
AWS_SES_SECRET_ACCESS_KEY,
],
2025-08-21 04:52:43 +08:00
environment: {
2025-08-30 07:34:56 +08:00
//VITE_DOCS_URL: web.url.apply((url) => url!),
//VITE_API_URL: gateway.url.apply((url) => url!),
2025-08-21 04:52:43 +08:00
VITE_AUTH_URL: auth.url.apply((url) => url!),
},
2025-09-04 01:52:01 +08:00
transform: {
server: {
transform: {
worker: {
2025-09-09 03:46:57 +08:00
placement: { mode: "smart" },
tailConsumers: logProcessor ? [{ service: logProcessor.nodes.worker.scriptName }] : [],
2025-09-04 01:52:01 +08:00
},
},
},
},
2025-08-21 04:52:43 +08:00
})