summaryrefslogtreecommitdiffhomepage
path: root/packages/console/core/src
diff options
context:
space:
mode:
authorFrank <[email protected]>2025-10-01 19:34:37 -0400
committerFrank <[email protected]>2025-10-01 19:34:37 -0400
commit70da3a9399d3385b53f7831beb08f716b972860d (patch)
tree6934fafb8558d426df88ca83d043eb3ac5910dcd /packages/console/core/src
parent1024537b471c341581826b39c360d34d6c32404f (diff)
downloadopencode-70da3a9399d3385b53f7831beb08f716b972860d.tar.gz
opencode-70da3a9399d3385b53f7831beb08f716b972860d.zip
wip: zen
Diffstat (limited to 'packages/console/core/src')
-rw-r--r--packages/console/core/src/account.ts8
-rw-r--r--packages/console/core/src/actor.ts2
-rw-r--r--packages/console/core/src/aws.ts63
-rw-r--r--packages/console/core/src/billing.ts2
-rw-r--r--packages/console/core/src/schema/user.sql.ts3
-rw-r--r--packages/console/core/src/workspace.ts1
6 files changed, 67 insertions, 12 deletions
diff --git a/packages/console/core/src/account.ts b/packages/console/core/src/account.ts
index cb123e048..3bed2bef1 100644
--- a/packages/console/core/src/account.ts
+++ b/packages/console/core/src/account.ts
@@ -54,13 +54,7 @@ export namespace Account {
.select(getTableColumns(WorkspaceTable))
.from(WorkspaceTable)
.innerJoin(UserTable, eq(UserTable.workspaceID, WorkspaceTable.id))
- .where(
- and(
- eq(UserTable.email, actor.properties.email),
- isNull(UserTable.timeDeleted),
- isNull(WorkspaceTable.timeDeleted),
- ),
- )
+ .where(and(eq(UserTable.email, actor.properties.email), isNull(WorkspaceTable.timeDeleted)))
.execute(),
)
}
diff --git a/packages/console/core/src/actor.ts b/packages/console/core/src/actor.ts
index f9db01293..0d13f7216 100644
--- a/packages/console/core/src/actor.ts
+++ b/packages/console/core/src/actor.ts
@@ -1,5 +1,4 @@
import { Context } from "./context"
-import { UserRole } from "./schema/user.sql"
import { Log } from "./util/log"
export namespace Actor {
@@ -21,7 +20,6 @@ export namespace Actor {
properties: {
userID: string
workspaceID: string
- role: (typeof UserRole)[number]
}
}
diff --git a/packages/console/core/src/aws.ts b/packages/console/core/src/aws.ts
new file mode 100644
index 000000000..200e29e4a
--- /dev/null
+++ b/packages/console/core/src/aws.ts
@@ -0,0 +1,63 @@
+import { z } from "zod"
+import { Resource } from "@opencode/console-resource"
+import { AwsClient } from "aws4fetch"
+import { fn } from "./util/fn"
+
+export namespace AWS {
+ let client: AwsClient
+
+ const createClient = () => {
+ if (!client) {
+ client = new AwsClient({
+ accessKeyId: Resource.AWS_SES_ACCESS_KEY_ID.value,
+ secretAccessKey: Resource.AWS_SES_SECRET_ACCESS_KEY.value,
+ region: "us-east-1",
+ })
+ }
+ return client
+ }
+
+ export const sendEmail = fn(
+ z.object({
+ to: z.string(),
+ subject: z.string(),
+ body: z.string(),
+ }),
+ async (input) => {
+ const res = await createClient().fetch("https://email.us-east-1.amazonaws.com/v2/email/outbound-emails", {
+ method: "POST",
+ headers: {
+ "X-Amz-Target": "SES.SendEmail",
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ FromEmailAddress: `OpenCode Zen <[email protected]>`,
+ Destination: {
+ ToAddresses: [input.to],
+ },
+ Content: {
+ Simple: {
+ Subject: {
+ Charset: "UTF-8",
+ Data: input.subject,
+ },
+ Body: {
+ Text: {
+ Charset: "UTF-8",
+ Data: input.body,
+ },
+ Html: {
+ Charset: "UTF-8",
+ Data: input.body,
+ },
+ },
+ },
+ },
+ }),
+ })
+ if (!res.ok) {
+ throw new Error(`Failed to send email: ${res.statusText}`)
+ }
+ },
+ )
+}
diff --git a/packages/console/core/src/billing.ts b/packages/console/core/src/billing.ts
index a87498a33..9c683a359 100644
--- a/packages/console/core/src/billing.ts
+++ b/packages/console/core/src/billing.ts
@@ -206,7 +206,7 @@ export namespace Billing {
},
}
: {
- customer_email: user.email,
+ customer_email: user.email!,
customer_creation: "always",
}),
currency: "usd",
diff --git a/packages/console/core/src/schema/user.sql.ts b/packages/console/core/src/schema/user.sql.ts
index 34939474e..eaadb06d5 100644
--- a/packages/console/core/src/schema/user.sql.ts
+++ b/packages/console/core/src/schema/user.sql.ts
@@ -9,7 +9,8 @@ export const UserTable = mysqlTable(
{
...workspaceColumns,
...timestamps,
- email: varchar("email", { length: 255 }).notNull(),
+ email: varchar("email", { length: 255 }),
+ oldEmail: varchar("old_email", { length: 255 }),
name: varchar("name", { length: 255 }).notNull(),
timeSeen: utc("time_seen"),
color: int("color"),
diff --git a/packages/console/core/src/workspace.ts b/packages/console/core/src/workspace.ts
index 0ff3a1532..d6eeb80cf 100644
--- a/packages/console/core/src/workspace.ts
+++ b/packages/console/core/src/workspace.ts
@@ -21,7 +21,6 @@ export namespace Workspace {
id: Identifier.create("user"),
email: account.properties.email,
name: "",
- timeSeen: sql`now()`,
role: "admin",
})
await tx.insert(BillingTable).values({