-
Notifications
You must be signed in to change notification settings - Fork 2
Updated some stuff #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ async function upsertMachine( | |
| timestamp: number; | ||
| meta?: Record<string, unknown>; | ||
| geo?: { ip?: string; country?: string; region?: string; city?: string }; | ||
| userInfo?: { email?: string; name?: string; provider?: string }; | ||
| } | ||
| ) { | ||
| const existing = await ctx.db | ||
|
|
@@ -51,6 +52,9 @@ async function upsertMachine( | |
| country: args.geo?.country, | ||
| region: args.geo?.region, | ||
| city: args.geo?.city, | ||
| userEmail: args.userInfo?.email, | ||
| userName: args.userInfo?.name, | ||
| authProvider: args.userInfo?.provider, | ||
| }); | ||
| return { isNewMachine: true }; | ||
| } | ||
|
|
@@ -62,6 +66,9 @@ async function upsertMachine( | |
| platform: args.meta?.platform ?? existing.platform, | ||
| referrer: args.meta?.referrer ?? existing.referrer, | ||
| screen: args.meta?.screen ?? existing.screen, | ||
| userEmail: args.userInfo?.email ?? existing.userEmail, | ||
| userName: args.userInfo?.name ?? existing.userName, | ||
| authProvider: args.userInfo?.provider ?? existing.authProvider, | ||
| }); | ||
| return { isNewMachine: false }; | ||
| } | ||
|
|
@@ -122,20 +129,32 @@ async function upsertSession( | |
| } | ||
| } | ||
|
|
||
| function extractUserInfo(events: Array<{ name: string; payload?: unknown }>): { email?: string; name?: string; provider?: string } | undefined { | ||
| const identifyEvent = events.find((e) => e.name === "session_identify"); | ||
| if (!identifyEvent?.payload || typeof identifyEvent.payload !== "object") return undefined; | ||
| const p = identifyEvent.payload as Record<string, unknown>; | ||
| const email = typeof p.email === "string" ? p.email : undefined; | ||
| const name = typeof p.name === "string" ? p.name : undefined; | ||
| const provider = typeof p.provider === "string" ? p.provider : undefined; | ||
| return email || name || provider ? { email, name, provider } : undefined; | ||
| } | ||
|
|
||
| export const recordBatch = mutation({ | ||
| args: { events: v.array(eventValidator) }, | ||
| handler: async (ctx, { events }) => { | ||
| // Process oldest-first so ordering-dependent bookkeeping (session creation, counters) is correct. | ||
| const sorted = [...events].sort((a, b) => a.timestamp - b.timestamp); | ||
| const userInfo = extractUserInfo(sorted); | ||
|
|
||
| for (const event of sorted) { | ||
| const isBookkeeping = event.name === "session_start"; | ||
| const isBookkeeping = event.name === "session_start" || event.name === "session_identify"; | ||
|
|
||
| await upsertMachine(ctx, { | ||
| machineId: event.machineId, | ||
| userId: event.userId, | ||
| timestamp: event.timestamp, | ||
| meta: isBookkeeping ? event.payload : undefined, | ||
| userInfo, | ||
|
Comment on lines
+132
to
+157
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift Scope identity extraction to the machine/session being processed.
Also applies to: 233-244 🤖 Prompt for AI Agents |
||
| }); | ||
|
|
||
| await upsertSession(ctx, { | ||
|
|
@@ -211,16 +230,18 @@ export const recordBatchWithGeo = internalMutation({ | |
| }, | ||
| handler: async (ctx, { events, geo }) => { | ||
| const sorted = [...events].sort((a, b) => a.timestamp - b.timestamp); | ||
| const userInfo = extractUserInfo(sorted); | ||
|
|
||
| for (const event of sorted) { | ||
| const isBookkeeping = event.name === "session_start"; | ||
| const isBookkeeping = event.name === "session_start" || event.name === "session_identify"; | ||
|
|
||
| await upsertMachine(ctx, { | ||
| machineId: event.machineId, | ||
| userId: event.userId, | ||
| timestamp: event.timestamp, | ||
| meta: isBookkeeping ? event.payload : undefined, | ||
| geo, | ||
| userInfo, | ||
| }); | ||
|
|
||
| await upsertSession(ctx, { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift
Gate the new PII before returning it.
getMachineStats,getPageVisitors, andsearchMachinesnow return email/name/provider, but the supplied dashboard handlers are publicquerys without an auth or tenant check. Anyone able to call these endpoints can retrieve user PII; add authorization and tenant scoping, or keep identity fields behind authenticated endpoints. (raw.githubusercontent.com)Also applies to: 387-389, 442-444
🤖 Prompt for AI Agents