Skip to content
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

fix(backend): Align Session resource with OpenAPI spec #4869

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions .changeset/bright-mangos-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@clerk/backend': minor
---

Update Session resource with new properties to align with OpenAPI spec
- `lastActiveOrganizationId`
- `latestActivity`
- `actor`
14 changes: 13 additions & 1 deletion packages/backend/src/api/resources/JSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,25 @@ export interface RedirectUrlJSON extends ClerkResourceJSON {
updated_at: number;
}

export interface SessionActivityJSON extends ClerkResourceJSON {
id: string;
device_type?: string;
is_mobile: boolean;
browser_name?: string;
browser_version?: string;
ip_address?: string;
city?: string;
country?: string;
}

export interface SessionJSON extends ClerkResourceJSON {
object: typeof ObjectType.Session;
client_id: string;
user_id: string;
status: string;
last_active_organization_id?: string;
actor?: Record<string, unknown>;
actor: Record<string, unknown> | null;
latest_activity?: SessionActivityJSON;
last_active_at: number;
expire_at: number;
abandon_at: number;
Expand Down
34 changes: 33 additions & 1 deletion packages/backend/src/api/resources/Session.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
import type { SessionJSON } from './JSON';
import type { SessionActivityJSON, SessionJSON } from './JSON';

export class SessionActivity {
constructor(
readonly id: string,
readonly isMobile: boolean,
readonly ipAddress?: string,
readonly city?: string,
readonly country?: string,
readonly browserVersion?: string,
readonly browserName?: string,
readonly deviceType?: string,
) {}

static fromJSON(data: SessionActivityJSON): SessionActivity {
return new SessionActivity(
data.id,
data.is_mobile,
data.ip_address,
data.city,
data.country,
data.browser_version,
data.browser_name,
data.device_type,
);
}
}

export class Session {
constructor(
Expand All @@ -11,6 +37,9 @@ export class Session {
readonly abandonAt: number,
readonly createdAt: number,
readonly updatedAt: number,
readonly lastActiveOrganizationId?: string,
readonly latestActivity?: SessionActivity,
readonly actor: Record<string, unknown> | null = null,
) {}

static fromJSON(data: SessionJSON): Session {
Expand All @@ -24,6 +53,9 @@ export class Session {
data.abandon_at,
data.created_at,
data.updated_at,
data.last_active_organization_id,
data.latest_activity && SessionActivity.fromJSON(data.latest_activity),
data.actor,
);
}
}
Loading