feat: data encryption key
This commit is contained in:
parent
a2fa1dbd01
commit
31bb2892f2
@ -135,6 +135,7 @@ This document contains the development guidelines and instructions for the Happy
|
|||||||
- Use "inTx" to wrap database operations in transactions
|
- Use "inTx" to wrap database operations in transactions
|
||||||
- Do not update schema without absolute necessity
|
- Do not update schema without absolute necessity
|
||||||
- For complex fields, use "Json" type
|
- For complex fields, use "Json" type
|
||||||
|
- NEVER DO MIGRATION YOURSELF. Only run yarn generate when new types needed
|
||||||
|
|
||||||
### Current Schema Status
|
### Current Schema Status
|
||||||
The project has pending Prisma migrations that need to be applied:
|
The project has pending Prisma migrations that need to be applied:
|
||||||
|
@ -86,6 +86,8 @@ spec:
|
|||||||
key: /handy-github
|
key: /handy-github
|
||||||
- extract:
|
- extract:
|
||||||
key: /handy-files
|
key: /handy-files
|
||||||
|
- extract:
|
||||||
|
key: /handy-e2b
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Session" ADD COLUMN "dataEncryptionKey" BYTEA;
|
@ -90,6 +90,7 @@ model Session {
|
|||||||
metadataVersion Int @default(0)
|
metadataVersion Int @default(0)
|
||||||
agentState String?
|
agentState String?
|
||||||
agentStateVersion Int @default(0)
|
agentStateVersion Int @default(0)
|
||||||
|
dataEncryptionKey Bytes?
|
||||||
seq Int @default(0)
|
seq Int @default(0)
|
||||||
active Boolean @default(true)
|
active Boolean @default(true)
|
||||||
lastActiveAt DateTime @default(now())
|
lastActiveAt DateTime @default(now())
|
||||||
|
@ -28,6 +28,7 @@ export function sessionRoutes(app: Fastify, eventRouter: EventRouter) {
|
|||||||
metadataVersion: true,
|
metadataVersion: true,
|
||||||
agentState: true,
|
agentState: true,
|
||||||
agentStateVersion: true,
|
agentStateVersion: true,
|
||||||
|
dataEncryptionKey: true,
|
||||||
active: true,
|
active: true,
|
||||||
lastActiveAt: true,
|
lastActiveAt: true,
|
||||||
// messages: {
|
// messages: {
|
||||||
@ -61,6 +62,7 @@ export function sessionRoutes(app: Fastify, eventRouter: EventRouter) {
|
|||||||
metadataVersion: v.metadataVersion,
|
metadataVersion: v.metadataVersion,
|
||||||
agentState: v.agentState,
|
agentState: v.agentState,
|
||||||
agentStateVersion: v.agentStateVersion,
|
agentStateVersion: v.agentStateVersion,
|
||||||
|
dataEncryptionKey: v.dataEncryptionKey ? Buffer.from(v.dataEncryptionKey).toString('base64') : null,
|
||||||
lastMessage: null
|
lastMessage: null
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
@ -96,6 +98,7 @@ export function sessionRoutes(app: Fastify, eventRouter: EventRouter) {
|
|||||||
metadataVersion: true,
|
metadataVersion: true,
|
||||||
agentState: true,
|
agentState: true,
|
||||||
agentStateVersion: true,
|
agentStateVersion: true,
|
||||||
|
dataEncryptionKey: true,
|
||||||
active: true,
|
active: true,
|
||||||
lastActiveAt: true,
|
lastActiveAt: true,
|
||||||
}
|
}
|
||||||
@ -113,6 +116,7 @@ export function sessionRoutes(app: Fastify, eventRouter: EventRouter) {
|
|||||||
metadataVersion: v.metadataVersion,
|
metadataVersion: v.metadataVersion,
|
||||||
agentState: v.agentState,
|
agentState: v.agentState,
|
||||||
agentStateVersion: v.agentStateVersion,
|
agentStateVersion: v.agentStateVersion,
|
||||||
|
dataEncryptionKey: v.dataEncryptionKey ? Buffer.from(v.dataEncryptionKey).toString('base64') : null,
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -174,6 +178,7 @@ export function sessionRoutes(app: Fastify, eventRouter: EventRouter) {
|
|||||||
metadataVersion: true,
|
metadataVersion: true,
|
||||||
agentState: true,
|
agentState: true,
|
||||||
agentStateVersion: true,
|
agentStateVersion: true,
|
||||||
|
dataEncryptionKey: true,
|
||||||
active: true,
|
active: true,
|
||||||
lastActiveAt: true,
|
lastActiveAt: true,
|
||||||
}
|
}
|
||||||
@ -202,6 +207,7 @@ export function sessionRoutes(app: Fastify, eventRouter: EventRouter) {
|
|||||||
metadataVersion: v.metadataVersion,
|
metadataVersion: v.metadataVersion,
|
||||||
agentState: v.agentState,
|
agentState: v.agentState,
|
||||||
agentStateVersion: v.agentStateVersion,
|
agentStateVersion: v.agentStateVersion,
|
||||||
|
dataEncryptionKey: v.dataEncryptionKey ? Buffer.from(v.dataEncryptionKey).toString('base64') : null,
|
||||||
})),
|
})),
|
||||||
nextCursor,
|
nextCursor,
|
||||||
hasNext
|
hasNext
|
||||||
@ -214,13 +220,14 @@ export function sessionRoutes(app: Fastify, eventRouter: EventRouter) {
|
|||||||
body: z.object({
|
body: z.object({
|
||||||
tag: z.string(),
|
tag: z.string(),
|
||||||
metadata: z.string(),
|
metadata: z.string(),
|
||||||
agentState: z.string().nullish()
|
agentState: z.string().nullish(),
|
||||||
|
dataEncryptionKey: z.string().nullish()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
preHandler: app.authenticate
|
preHandler: app.authenticate
|
||||||
}, async (request, reply) => {
|
}, async (request, reply) => {
|
||||||
const userId = request.userId;
|
const userId = request.userId;
|
||||||
const { tag, metadata } = request.body;
|
const { tag, metadata, dataEncryptionKey } = request.body;
|
||||||
|
|
||||||
const session = await db.session.findFirst({
|
const session = await db.session.findFirst({
|
||||||
where: {
|
where: {
|
||||||
@ -238,6 +245,7 @@ export function sessionRoutes(app: Fastify, eventRouter: EventRouter) {
|
|||||||
metadataVersion: session.metadataVersion,
|
metadataVersion: session.metadataVersion,
|
||||||
agentState: session.agentState,
|
agentState: session.agentState,
|
||||||
agentStateVersion: session.agentStateVersion,
|
agentStateVersion: session.agentStateVersion,
|
||||||
|
dataEncryptionKey: session.dataEncryptionKey ? Buffer.from(session.dataEncryptionKey).toString('base64') : null,
|
||||||
active: session.active,
|
active: session.active,
|
||||||
activeAt: session.lastActiveAt.getTime(),
|
activeAt: session.lastActiveAt.getTime(),
|
||||||
createdAt: session.createdAt.getTime(),
|
createdAt: session.createdAt.getTime(),
|
||||||
@ -256,7 +264,8 @@ export function sessionRoutes(app: Fastify, eventRouter: EventRouter) {
|
|||||||
data: {
|
data: {
|
||||||
accountId: userId,
|
accountId: userId,
|
||||||
tag: tag,
|
tag: tag,
|
||||||
metadata: metadata
|
metadata: metadata,
|
||||||
|
dataEncryptionKey: dataEncryptionKey ? Buffer.from(dataEncryptionKey, 'base64') : undefined
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
log({ module: 'session-create', sessionId: session.id, userId }, `Session created: ${session.id}`);
|
log({ module: 'session-create', sessionId: session.id, userId }, `Session created: ${session.id}`);
|
||||||
@ -284,6 +293,7 @@ export function sessionRoutes(app: Fastify, eventRouter: EventRouter) {
|
|||||||
metadataVersion: session.metadataVersion,
|
metadataVersion: session.metadataVersion,
|
||||||
agentState: session.agentState,
|
agentState: session.agentState,
|
||||||
agentStateVersion: session.agentStateVersion,
|
agentStateVersion: session.agentStateVersion,
|
||||||
|
dataEncryptionKey: session.dataEncryptionKey ? Buffer.from(session.dataEncryptionKey).toString('base64') : null,
|
||||||
active: session.active,
|
active: session.active,
|
||||||
activeAt: session.lastActiveAt.getTime(),
|
activeAt: session.lastActiveAt.getTime(),
|
||||||
createdAt: session.createdAt.getTime(),
|
createdAt: session.createdAt.getTime(),
|
||||||
|
@ -56,6 +56,7 @@ export type UpdateEvent = {
|
|||||||
metadataVersion: number;
|
metadataVersion: number;
|
||||||
agentState: string | null;
|
agentState: string | null;
|
||||||
agentStateVersion: number;
|
agentStateVersion: number;
|
||||||
|
dataEncryptionKey: string | null;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
activeAt: number;
|
activeAt: number;
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
@ -266,6 +267,7 @@ export function buildNewSessionUpdate(session: {
|
|||||||
metadataVersion: number;
|
metadataVersion: number;
|
||||||
agentState: string | null;
|
agentState: string | null;
|
||||||
agentStateVersion: number;
|
agentStateVersion: number;
|
||||||
|
dataEncryptionKey: Uint8Array | null;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
lastActiveAt: Date;
|
lastActiveAt: Date;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
@ -282,6 +284,7 @@ export function buildNewSessionUpdate(session: {
|
|||||||
metadataVersion: session.metadataVersion,
|
metadataVersion: session.metadataVersion,
|
||||||
agentState: session.agentState,
|
agentState: session.agentState,
|
||||||
agentStateVersion: session.agentStateVersion,
|
agentStateVersion: session.agentStateVersion,
|
||||||
|
dataEncryptionKey: session.dataEncryptionKey ? Buffer.from(session.dataEncryptionKey).toString('base64') : null,
|
||||||
active: session.active,
|
active: session.active,
|
||||||
activeAt: session.lastActiveAt.getTime(),
|
activeAt: session.lastActiveAt.getTime(),
|
||||||
createdAt: session.createdAt.getTime(),
|
createdAt: session.createdAt.getTime(),
|
||||||
|
@ -40,6 +40,7 @@ declare global {
|
|||||||
metadataVersion: number;
|
metadataVersion: number;
|
||||||
agentState: string | null;
|
agentState: string | null;
|
||||||
agentStateVersion: number;
|
agentStateVersion: number;
|
||||||
|
dataEncryptionKey: string | null;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
activeAt: number;
|
activeAt: number;
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
|
Loading…
Reference in New Issue
Block a user