Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/api/src/infrastructure/middleware/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export function auditMiddleware(app: FastifyInstance) {
await db
.insertInto("audit_logs")
.values({
workspace_id: (request.params as any)?.workspaceId || null,
user_id: (request as any).user?.userId || null,
workspace_id: (request.params as { workspaceId?: string })?.workspaceId || null,
user_id: request.user?.userId || null,
action,
resource_type: deriveResourceType(request.url),
resource_id: (request.params as any)?.id || null,
resource_id: (request.params as { id?: string })?.id || null,
details: {
method: request.method,
url: request.url,
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/infrastructure/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { authenticateRequestSession } from "../../modules/auth/service.js"
async function attachAuthenticatedRequest(request: FastifyRequest) {
const authenticated = await authenticateRequestSession(request)
if (!authenticated) return null
;(request as any).user = {
request.user = {
userId: authenticated.user.id,
email: authenticated.user.email,
}
;(request as any).authSession = authenticated.session
request.authSession = authenticated.session

return authenticated
}
Expand All @@ -36,5 +36,5 @@ export async function optionalAuth(request: FastifyRequest) {
}

export function getUserId(request: FastifyRequest): string {
return (request as any).user?.userId
return request.user?.userId ?? ""
}
6 changes: 3 additions & 3 deletions packages/api/src/infrastructure/middleware/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ export async function workspaceMiddleware(
request: FastifyRequest,
reply: FastifyReply
) {
const workspaceId = (request.params as any).workspaceId
const workspaceId = (request.params as { workspaceId?: string }).workspaceId
if (!workspaceId) {
return reply.status(400).send({ error: "Workspace ID is required" })
}

const user = (request as any).user
const user = request.user
if (!user) {
return reply.status(401).send({ error: "Authentication required" })
}
Expand All @@ -23,7 +23,7 @@ export async function workspaceMiddleware(
.where("user_id", "=", user.userId)
.executeTakeFirst()

;(request as any).workspaceMember = member ?? null
request.workspaceMember = member ?? null

const allowed = await requireRequestAction(
request,
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/modules/access/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function resolveWorkspaceAccessSubject(
}

export function getRequestUserId(request: FastifyRequest): string {
const userId = (request as any).user?.userId as string | undefined
const userId = request.user?.userId as string | undefined
if (!userId) {
throw new Error("Authenticated user is missing from request")
}
Expand All @@ -60,7 +60,7 @@ export function getRequestUserSubject(request: FastifyRequest): AccessSubject {
export function getRequestAccessSubject(
request: FastifyRequest
): AccessSubject {
const workspaceMemberId = (request as any).workspaceMember?.id as
const workspaceMemberId = request.workspaceMember?.id as
| string
| undefined
if (workspaceMemberId) {
Expand Down
26 changes: 13 additions & 13 deletions packages/api/src/modules/auth/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export function registerAuthRoutes(app: FastifyInstance) {
.send(
await authService.resolveQrLoginRequest(
body.token,
(request as any).user.userId
request.user.userId
)
)
} catch (error) {
Expand All @@ -267,7 +267,7 @@ export function registerAuthRoutes(app: FastifyInstance) {
.send(
await authService.approveQrLoginRequest(
body.token,
(request as any).user.userId,
request.user.userId,
body.sessionPersistence ?? "persistent"
)
)
Expand All @@ -288,7 +288,7 @@ export function registerAuthRoutes(app: FastifyInstance) {
.send(
await authService.rejectQrLoginRequest(
body.token,
(request as any).user.userId
request.user.userId
)
)
} catch (error) {
Expand Down Expand Up @@ -335,7 +335,7 @@ export function registerAuthRoutes(app: FastifyInstance) {
{ preHandler: [authMiddleware] },
async (request: FastifyRequest, reply: FastifyReply) => {
try {
const currentSession = (request as any).authSession
const currentSession = request.authSession
await authService.logoutCurrentSession(currentSession.id)
clearSessionCookie(reply)
return reply.status(204).send()
Expand All @@ -350,7 +350,7 @@ export function registerAuthRoutes(app: FastifyInstance) {
{ preHandler: [authMiddleware] },
async (request: FastifyRequest, reply: FastifyReply) => {
try {
await authService.logoutAllSessions((request as any).user.userId)
await authService.logoutAllSessions(request.user.userId)
clearSessionCookie(reply)
return reply.status(204).send()
} catch (error) {
Expand All @@ -365,8 +365,8 @@ export function registerAuthRoutes(app: FastifyInstance) {
async (request: FastifyRequest, reply: FastifyReply) => {
try {
return reply.status(200).send({
user: await authService.getProfile((request as any).user.userId),
session: (request as any).authSession,
user: await authService.getProfile(request.user.userId),
session: request.authSession,
})
} catch (error) {
return handleAuthError(error, reply)
Expand All @@ -381,11 +381,11 @@ export function registerAuthRoutes(app: FastifyInstance) {
try {
const body = updateMeSchema.parse(request.body)
return reply.status(200).send({
user: await authService.updateProfile((request as any).user.userId, {
user: await authService.updateProfile(request.user.userId, {
name: body.name,
avatarFileId: body.avatarFileId,
}),
session: (request as any).authSession,
session: request.authSession,
})
} catch (error) {
return handleAuthError(error, reply)
Expand All @@ -400,8 +400,8 @@ export function registerAuthRoutes(app: FastifyInstance) {
try {
return reply.status(200).send({
sessions: await authService.listSessions(
(request as any).user.userId,
(request as any).authSession.id
request.user.userId,
request.authSession.id
),
})
} catch (error) {
Expand All @@ -416,9 +416,9 @@ export function registerAuthRoutes(app: FastifyInstance) {
async (request: FastifyRequest, reply: FastifyReply) => {
try {
const params = sessionParamsSchema.parse(request.params)
const currentSessionId = (request as any).authSession.id as string
const currentSessionId = request.authSession.id as string
await authService.revokeSessionForUser(
(request as any).user.userId,
request.user.userId,
params.sessionId
)

Expand Down
18 changes: 9 additions & 9 deletions packages/api/src/modules/automation/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export default async function automationController(app: FastifyInstance) {
if (!allowed) return

const body = eventSourceSchema.parse(request.body)
const workspaceMemberId = (request as any).workspaceMember!.id as string
const workspaceMemberId = request.workspaceMember!.id as string
const source = await createAutomationEventSource(
workspaceId,
{ kind: "workspace_member", workspaceMemberId },
Expand Down Expand Up @@ -390,7 +390,7 @@ export default async function automationController(app: FastifyInstance) {
if (!allowed) return

const body = accessGrantSchema.parse(request.body || {})
const workspaceMemberId = (request as any).workspaceMember!.id as string
const workspaceMemberId = request.workspaceMember!.id as string
const grant = await grantAutomationEventSourceAccess({
workspaceId,
eventSourceId,
Expand Down Expand Up @@ -450,7 +450,7 @@ export default async function automationController(app: FastifyInstance) {
)
if (!allowed) return

const workspaceMemberId = (request as any).workspaceMember!.id as string
const workspaceMemberId = request.workspaceMember!.id as string
await revokeAutomationEventSourceAccess({
workspaceId,
eventSourceId,
Expand Down Expand Up @@ -502,7 +502,7 @@ export default async function automationController(app: FastifyInstance) {
if (!allowed) return

const body = updateEventSourceSchema.parse(request.body)
const workspaceMemberId = (request as any).workspaceMember!.id as string
const workspaceMemberId = request.workspaceMember!.id as string
return updateAutomationEventSource(
workspaceId,
eventSourceId,
Expand All @@ -529,7 +529,7 @@ export default async function automationController(app: FastifyInstance) {
)
if (!allowed) return

const workspaceMemberId = (request as any).workspaceMember!.id as string
const workspaceMemberId = request.workspaceMember!.id as string
await archiveAutomationEventSource(workspaceId, eventSourceId, {
workspaceMemberId,
})
Expand Down Expand Up @@ -628,7 +628,7 @@ export default async function automationController(app: FastifyInstance) {
issues,
})
}
const workspaceMemberId = (request as any).workspaceMember!.id as string
const workspaceMemberId = request.workspaceMember!.id as string
const automation = await createAutomationRule(
workspaceId,
{ kind: "workspace_member", workspaceMemberId },
Expand Down Expand Up @@ -681,7 +681,7 @@ export default async function automationController(app: FastifyInstance) {
if (!allowed) return

const body = updateAutomationSchema.parse(request.body)
const workspaceMemberId = (request as any).workspaceMember!.id as string
const workspaceMemberId = request.workspaceMember!.id as string
try {
const automation = await updateAutomationRule(
workspaceId,
Expand Down Expand Up @@ -722,7 +722,7 @@ export default async function automationController(app: FastifyInstance) {
)
if (!allowed) return

const workspaceMemberId = (request as any).workspaceMember!.id as string
const workspaceMemberId = request.workspaceMember!.id as string
await deleteAutomationRule(workspaceId, automationId, {
workspaceMemberId,
})
Expand Down Expand Up @@ -784,7 +784,7 @@ export default async function automationController(app: FastifyInstance) {
if (!allowed) return

const body = createWebhookEndpointSchema.parse(request.body)
const workspaceMemberId = (request as any).workspaceMember!.id as string
const workspaceMemberId = request.workspaceMember!.id as string
const created = await createAutomationWebhookEndpoint(
workspaceId,
workspaceMemberId,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/modules/chat/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const resolveInteractionSchema = z.union([
])

function getRequestUserId(request: any) {
return (request as any).user!.userId as string
return request.user!.userId as string
}

async function resolveRequestWorkspaceMemberId(
Expand Down
10 changes: 5 additions & 5 deletions packages/api/src/modules/files/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function filesUploadController(app: FastifyInstance) {
Params: { workspaceId: string }
}>("/workspaces/:workspaceId/files", async (request, reply) => {
const { workspaceId } = request.params
const userId = (request as any).user!.userId
const userId = request.user!.userId

let filePart: Awaited<ReturnType<typeof request.file>> | null = null
let originInput: FileCreateOriginInput | null = null
Expand Down Expand Up @@ -132,7 +132,7 @@ export async function filesReadController(app: FastifyInstance) {
app.get<{
Params: { fileId: string }
}>("/files/:fileId/info", async (request, reply) => {
const userId = (request as any).user!.userId
const userId = request.user!.userId
const detail = await getFileDetail(request.params.fileId)
if (!detail) {
return reply.status(404).send({ error: "File not found" })
Expand All @@ -152,7 +152,7 @@ export async function filesReadController(app: FastifyInstance) {
app.get<{
Params: { fileId: string }
}>("/files/:fileId/parses/latest", async (request, reply) => {
const userId = (request as any).user!.userId
const userId = request.user!.userId
const detail = await getFileDetail(request.params.fileId)
if (!detail) {
return reply.status(404).send({ error: "File not found" })
Expand All @@ -177,7 +177,7 @@ export async function filesReadController(app: FastifyInstance) {
app.post<{
Params: { fileId: string }
}>("/files/:fileId/parses", async (request, reply) => {
const userId = (request as any).user!.userId
const userId = request.user!.userId
const detail = await getFileDetail(request.params.fileId)
if (!detail) {
return reply.status(404).send({ error: "File not found" })
Expand Down Expand Up @@ -207,7 +207,7 @@ export async function filesReadController(app: FastifyInstance) {
app.get<{
Params: { fileId: string }
}>("/files/:fileId", async (request, reply) => {
const userId = (request as any).user!.userId
const userId = request.user!.userId
const info = await getFileRecord(request.params.fileId)
if (!info) {
return reply.status(404).send({ error: "File not found" })
Expand Down
12 changes: 6 additions & 6 deletions packages/api/src/modules/im/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ export default async function imController(app: FastifyInstance) {

const binding = await getCurrentUserWeixinBinding({
workspaceId: request.params.workspaceId,
userId: (request as any).user!.userId,
userId: request.user!.userId,
})
return reply.send({ binding })
}
Expand Down Expand Up @@ -451,8 +451,8 @@ export default async function imController(app: FastifyInstance) {
if (!allowed) return

const { workspaceId } = request.params
const workspaceMemberId = (request as any).workspaceMember?.id as string
const userId = (request as any).user!.userId as string
const workspaceMemberId = request.workspaceMember?.id as string
const userId = request.user!.userId as string
const existing = await getCurrentUserWeixinBinding({
workspaceId,
userId,
Expand Down Expand Up @@ -485,7 +485,7 @@ export default async function imController(app: FastifyInstance) {
if (!allowed) return

const { workspaceId, sessionId } = request.params
const workspaceMemberId = (request as any).workspaceMember?.id as string
const workspaceMemberId = request.workspaceMember?.id as string
const owner = getWeixinQrLoginSessionOwner({ workspaceId, sessionId })
if (
!owner ||
Expand Down Expand Up @@ -520,7 +520,7 @@ export default async function imController(app: FastifyInstance) {
try {
const binding = await linkCurrentUserWeixinBinding({
workspaceId: request.params.workspaceId,
userId: (request as any).user!.userId,
userId: request.user!.userId,
})
return reply.send({ binding })
} catch (error) {
Expand Down Expand Up @@ -555,7 +555,7 @@ export default async function imController(app: FastifyInstance) {
const body = bindingAutoLinkSchema.parse(request.body)
const binding = await setCurrentUserWeixinBindingAutoLink({
workspaceId: request.params.workspaceId,
userId: (request as any).user!.userId,
userId: request.user!.userId,
targetWorkspaceMemberId: body.workspaceMemberId,
})
return reply.send({ binding })
Expand Down
Loading