diff --git a/.changeset/bright-mangos-grow.md b/.changeset/bright-mangos-grow.md new file mode 100644 index 0000000000..cc646fe669 --- /dev/null +++ b/.changeset/bright-mangos-grow.md @@ -0,0 +1,8 @@ +--- +'@clerk/backend': minor +--- + +Update Session resource with new properties to align with OpenAPI spec +- `lastActiveOrganizationId` +- `latestActivity` +- `actor` diff --git a/packages/backend/src/api/resources/JSON.ts b/packages/backend/src/api/resources/JSON.ts index 0c5c544ba6..852c454614 100644 --- a/packages/backend/src/api/resources/JSON.ts +++ b/packages/backend/src/api/resources/JSON.ts @@ -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; + actor: Record | null; + latest_activity?: SessionActivityJSON; last_active_at: number; expire_at: number; abandon_at: number; diff --git a/packages/backend/src/api/resources/Session.ts b/packages/backend/src/api/resources/Session.ts index cd0e3ea982..9ba0f0b469 100644 --- a/packages/backend/src/api/resources/Session.ts +++ b/packages/backend/src/api/resources/Session.ts @@ -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( @@ -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 | null = null, ) {} static fromJSON(data: SessionJSON): Session { @@ -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, ); } }