mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 01:34:22 +01:00
wip: zen
This commit is contained in:
@@ -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(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
63
packages/console/core/src/aws.ts
Normal file
63
packages/console/core/src/aws.ts
Normal file
@@ -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 <contact@anoma.ly>`,
|
||||
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}`)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -206,7 +206,7 @@ export namespace Billing {
|
||||
},
|
||||
}
|
||||
: {
|
||||
customer_email: user.email,
|
||||
customer_email: user.email!,
|
||||
customer_creation: "always",
|
||||
}),
|
||||
currency: "usd",
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user