-
Notifications
You must be signed in to change notification settings - Fork 514
[Dashboard][Backend][SDK] - Adds sharable session replay ids. #1294
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
Open
madster456
wants to merge
15
commits into
dev
Choose a base branch
from
dashboard/share-replays
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f7dcc2f
Added AdminGetSessionReplayResponse type for the single-replay GET en…
madster456 f568871
Added AdminGetSessionReplayResponse import and getSessionReplay (sess…
madster456 0bb4e86
Added AdminSessionReplay to the import, added getSessionReplay(sessio…
madster456 67d847f
Added getSessionReplay implementation that calls this._interface.getS…
madster456 67c6998
Backend admin GET endpoint for fetching a single session replay by ID…
madster456 eca5155
Thin server page wrapper that awaits params.replayId and passes it to…
madster456 344c57f
Added ArrowLeftIcon and LinkIcon imports. Added initialReplayId prop …
madster456 a9e34ac
Added 2 new tests: admin can fetch a single session replay by id. adm…
madster456 fa22972
update lock
madster456 b1885d5
Merge dev into
madster456 dddb611
dedupe internal session replay SQL + chunk mapping
madster456 ac97154
Merge branch 'dev' into dashboard/share-replays
madster456 cbafe00
async click handler no longer missing
madster456 fd9fe69
Add visual feedback to copy button
madster456 bc5784d
Merge branch 'dev' into dashboard/share-replays
madster456 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Backend admin GET endpoint for fetching a single session replay by ID…
…. Uses raw SQL to join SessinoReplay with ProjectUser and ContactChannel, aggregates chunk/event counts via Prisma groupBy. Returns 303 ItemNotFound if not found.
- Loading branch information
commit 67c6998b8c2bc78a7327fe8d1ec551ac25d931ff
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
apps/backend/src/app/api/latest/internal/session-replays/[session_replay_id]/route.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import { getPrismaClientForTenancy, getPrismaSchemaForTenancy, sqlQuoteIdent } from "@/prisma-client"; | ||
| import { createSmartRouteHandler } from "@/route-handlers/smart-route-handler"; | ||
| import { KnownErrors } from "@stackframe/stack-shared"; | ||
| import { adaptSchema, adminAuthTypeSchema, yupNumber, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields"; | ||
|
|
||
| type ReplayRow = { | ||
| id: string, | ||
| projectUserId: string, | ||
| startedAt: Date, | ||
| lastEventAt: Date, | ||
| projectUserDisplayName: string | null, | ||
| primaryEmail: string | null, | ||
| }; | ||
|
|
||
| export const GET = createSmartRouteHandler({ | ||
| metadata: { hidden: true }, | ||
| request: yupObject({ | ||
| auth: yupObject({ | ||
| type: adminAuthTypeSchema.defined(), | ||
| tenancy: adaptSchema.defined(), | ||
| }).defined(), | ||
| params: yupObject({ | ||
| session_replay_id: yupString().defined(), | ||
| }).defined(), | ||
| }), | ||
| response: yupObject({ | ||
| statusCode: yupNumber().oneOf([200]).defined(), | ||
| bodyType: yupString().oneOf(["json"]).defined(), | ||
| body: yupObject({ | ||
| id: yupString().defined(), | ||
| project_user: yupObject({ | ||
| id: yupString().defined(), | ||
| display_name: yupString().nullable().defined(), | ||
| primary_email: yupString().nullable().defined(), | ||
| }).defined(), | ||
| started_at_millis: yupNumber().defined(), | ||
| last_event_at_millis: yupNumber().defined(), | ||
| chunk_count: yupNumber().defined(), | ||
| event_count: yupNumber().defined(), | ||
| }).defined(), | ||
| }), | ||
| async handler({ auth, params }) { | ||
| const prisma = await getPrismaClientForTenancy(auth.tenancy); | ||
| const schema = await getPrismaSchemaForTenancy(auth.tenancy); | ||
| const sessionReplayId = params.session_replay_id; | ||
|
|
||
| const rows = await prisma.$queryRaw<ReplayRow[]>` | ||
| SELECT | ||
| sr."id", | ||
| sr."projectUserId", | ||
| sr."startedAt", | ||
| sr."lastEventAt", | ||
| pu."displayName" AS "projectUserDisplayName", | ||
| ( | ||
| SELECT cc."value" | ||
| FROM ${sqlQuoteIdent(schema)}."ContactChannel" cc | ||
| WHERE cc."projectUserId" = sr."projectUserId" | ||
| AND cc."tenancyId" = sr."tenancyId" | ||
| AND cc."type" = 'EMAIL' | ||
| AND cc."isPrimary" = 'TRUE'::"BooleanTrue" | ||
| LIMIT 1 | ||
| ) AS "primaryEmail" | ||
| FROM ${sqlQuoteIdent(schema)}."SessionReplay" sr | ||
| JOIN ${sqlQuoteIdent(schema)}."ProjectUser" pu | ||
| ON pu."projectUserId" = sr."projectUserId" | ||
| AND pu."tenancyId" = sr."tenancyId" | ||
| WHERE sr."tenancyId" = ${auth.tenancy.id}::UUID | ||
| AND sr."id" = ${sessionReplayId} | ||
| LIMIT 1 | ||
| `; | ||
|
|
||
| const row = rows.at(0); | ||
| if (row == null) { | ||
| throw new KnownErrors.ItemNotFound(sessionReplayId); | ||
| } | ||
|
|
||
| const chunkAgg = (await prisma.sessionReplayChunk.groupBy({ | ||
| by: ["sessionReplayId"], | ||
| where: { | ||
| tenancyId: auth.tenancy.id, | ||
| sessionReplayId, | ||
| }, | ||
| _count: { _all: true }, | ||
| _sum: { eventCount: true }, | ||
| })).at(0); | ||
|
|
||
| return { | ||
| statusCode: 200, | ||
| bodyType: "json", | ||
| body: { | ||
| id: row.id, | ||
| project_user: { | ||
| id: row.projectUserId, | ||
| display_name: row.projectUserDisplayName ?? null, | ||
| primary_email: row.primaryEmail ?? null, | ||
| }, | ||
| started_at_millis: row.startedAt.getTime(), | ||
| last_event_at_millis: row.lastEventAt.getTime(), | ||
| chunk_count: chunkAgg == null ? 0 : chunkAgg._count._all, | ||
| event_count: chunkAgg == null ? 0 : (chunkAgg._sum.eventCount ?? 0), | ||
| }, | ||
| }; | ||
| }, | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.