From 540e12e53f1fea2671b1fcb93a47b26f5734f5af Mon Sep 17 00:00:00 2001 From: Vaggelis Yfantis Date: Fri, 10 Jan 2025 16:40:51 +0200 Subject: [PATCH 1/4] fix(backend): Align Session resource with OpenAPI spec --- packages/backend/src/api/resources/JSON.ts | 16 +++++++-- packages/backend/src/api/resources/Session.ts | 34 ++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/api/resources/JSON.ts b/packages/backend/src/api/resources/JSON.ts index 0c5c544ba61..cb7301892f7 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; + last_active_organization_id: string | null; + actor: Record | null; + latest_activity: SessionActivityJSON | null; 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 cd0e3ea9829..4e77f1cd3df 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 deviceType: string, + readonly isMobile: boolean, + readonly browserName: string, + readonly browserVersion: string, + readonly ipAddress: string, + readonly city: string, + readonly country: string, + ) {} + + static fromJSON(data: SessionActivityJSON): SessionActivity { + return new SessionActivity( + data.id, + data.device_type, + data.is_mobile, + data.browser_name, + data.browser_version, + data.ip_address, + data.city, + data.country, + ); + } +} export class Session { constructor( @@ -11,6 +37,9 @@ export class Session { readonly abandonAt: number, readonly createdAt: number, readonly updatedAt: number, + readonly lastActiveOrganizationId: string | null, + readonly latestActivity: SessionActivity | null = null, + 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, ); } } From 23f692fa3266a514ae3ba46155741f80521a1db5 Mon Sep 17 00:00:00 2001 From: Vaggelis Yfantis Date: Fri, 10 Jan 2025 17:22:44 +0200 Subject: [PATCH 2/4] fix(backend): Align Session resource with OpenAPI spec --- packages/backend/src/api/resources/JSON.ts | 16 +++++++------- packages/backend/src/api/resources/Session.ts | 22 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/backend/src/api/resources/JSON.ts b/packages/backend/src/api/resources/JSON.ts index cb7301892f7..852c4546147 100644 --- a/packages/backend/src/api/resources/JSON.ts +++ b/packages/backend/src/api/resources/JSON.ts @@ -231,13 +231,13 @@ export interface RedirectUrlJSON extends ClerkResourceJSON { export interface SessionActivityJSON extends ClerkResourceJSON { id: string; - device_type: string; + device_type?: string; is_mobile: boolean; - browser_name: string; - browser_version: string; - ip_address: string; - city: string; - country: string; + browser_name?: string; + browser_version?: string; + ip_address?: string; + city?: string; + country?: string; } export interface SessionJSON extends ClerkResourceJSON { @@ -245,9 +245,9 @@ export interface SessionJSON extends ClerkResourceJSON { client_id: string; user_id: string; status: string; - last_active_organization_id: string | null; + last_active_organization_id?: string; actor: Record | null; - latest_activity: SessionActivityJSON | 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 4e77f1cd3df..9ba0f0b4699 100644 --- a/packages/backend/src/api/resources/Session.ts +++ b/packages/backend/src/api/resources/Session.ts @@ -3,25 +3,25 @@ import type { SessionActivityJSON, SessionJSON } from './JSON'; export class SessionActivity { constructor( readonly id: string, - readonly deviceType: string, readonly isMobile: boolean, - readonly browserName: string, - readonly browserVersion: string, - readonly ipAddress: string, - readonly city: string, - readonly country: string, + 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.device_type, data.is_mobile, - data.browser_name, - data.browser_version, data.ip_address, data.city, data.country, + data.browser_version, + data.browser_name, + data.device_type, ); } } @@ -37,8 +37,8 @@ export class Session { readonly abandonAt: number, readonly createdAt: number, readonly updatedAt: number, - readonly lastActiveOrganizationId: string | null, - readonly latestActivity: SessionActivity | null = null, + readonly lastActiveOrganizationId?: string, + readonly latestActivity?: SessionActivity, readonly actor: Record | null = null, ) {} From 243ccfc1a243fd7531fa06f4809c3ad27747ad41 Mon Sep 17 00:00:00 2001 From: Vaggelis Yfantis Date: Fri, 10 Jan 2025 17:27:19 +0200 Subject: [PATCH 3/4] chore(repo): Adding changeset --- .changeset/bright-mangos-grow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/bright-mangos-grow.md diff --git a/.changeset/bright-mangos-grow.md b/.changeset/bright-mangos-grow.md new file mode 100644 index 00000000000..230a2d3b4d3 --- /dev/null +++ b/.changeset/bright-mangos-grow.md @@ -0,0 +1,5 @@ +--- +'@clerk/backend': minor +--- + +Align Session resource with OpenAPI spec From 0ec92542ff125f649b73477a4e0be6d93836fee1 Mon Sep 17 00:00:00 2001 From: Vaggelis Yfantis Date: Sat, 11 Jan 2025 14:39:14 +0200 Subject: [PATCH 4/4] Update .changeset/bright-mangos-grow.md Co-authored-by: panteliselef --- .changeset/bright-mangos-grow.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.changeset/bright-mangos-grow.md b/.changeset/bright-mangos-grow.md index 230a2d3b4d3..cc646fe669d 100644 --- a/.changeset/bright-mangos-grow.md +++ b/.changeset/bright-mangos-grow.md @@ -2,4 +2,7 @@ '@clerk/backend': minor --- -Align Session resource with OpenAPI spec +Update Session resource with new properties to align with OpenAPI spec +- `lastActiveOrganizationId` +- `latestActivity` +- `actor`