From 16b65868d6fc3c4aac18ca55901d025fd0fcb153 Mon Sep 17 00:00:00 2001 From: Laura Beatris <48022589+LauraBeatris@users.noreply.github.com> Date: Fri, 14 Feb 2025 16:40:52 -0300 Subject: [PATCH 1/3] Add `tasks` on `Session` resource --- .../clerk-js/src/core/resources/Session.ts | 4 +++ packages/types/src/index.ts | 1 + packages/types/src/json.ts | 25 ++----------------- packages/types/src/tasks.ts | 3 +++ 4 files changed, 10 insertions(+), 23 deletions(-) create mode 100644 packages/types/src/tasks.ts diff --git a/packages/clerk-js/src/core/resources/Session.ts b/packages/clerk-js/src/core/resources/Session.ts index 2a6c1b6e3aa..b28a899db4e 100644 --- a/packages/clerk-js/src/core/resources/Session.ts +++ b/packages/clerk-js/src/core/resources/Session.ts @@ -12,6 +12,7 @@ import type { SessionJSONSnapshot, SessionResource, SessionStatus, + SessionTasks, SessionVerificationJSON, SessionVerificationResource, SessionVerifyAttemptFirstFactorParams, @@ -42,6 +43,7 @@ export class Session extends BaseResource implements SessionResource { user!: UserResource | null; publicUserData!: PublicUserData; factorVerificationAge: [number, number] | null = null; + tasks!: SessionTasks | null; expireAt!: Date; abandonAt!: Date; createdAt!: Date; @@ -224,6 +226,7 @@ export class Session extends BaseResource implements SessionResource { this.createdAt = unixEpochToDate(data.created_at); this.updatedAt = unixEpochToDate(data.updated_at); this.user = new User(data.user); + this.tasks = data.tasks; if (data.public_user_data) { this.publicUserData = new PublicUserData(data.public_user_data); @@ -245,6 +248,7 @@ export class Session extends BaseResource implements SessionResource { last_active_at: this.lastActiveAt.getTime(), last_active_organization_id: this.lastActiveOrganizationId, actor: this.actor, + tasks: this.tasks, user: this.user?.__internal_toSnapshot() || null, public_user_data: this.publicUserData.__internal_toSnapshot(), last_active_token: this.lastActiveToken?.__internal_toSnapshot() || null, diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index ea41eaa12aa..b122e4cce9d 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -65,3 +65,4 @@ export * from './customMenuItems'; export * from './samlConnection'; export * from './waitlist'; export * from './snapshots'; +export * from './tasks'; diff --git a/packages/types/src/json.ts b/packages/types/src/json.ts index 663a4303d0e..a7acb98ad5c 100644 --- a/packages/types/src/json.ts +++ b/packages/types/src/json.ts @@ -16,6 +16,7 @@ import type { SessionStatus } from './session'; import type { SessionVerificationLevel, SessionVerificationStatus } from './sessionVerification'; import type { SignInFirstFactor, SignInJSON, SignInSecondFactor } from './signIn'; import type { SignUpField, SignUpIdentificationField, SignUpStatus } from './signUp'; +import type { SessionTasks } from './tasks'; import type { BoxShadow, Color, EmUnit, FontWeight, HexColor } from './theme'; import type { UserSettingsJSON } from './userSettings'; import type { CamelToSnake } from './utils'; @@ -76,29 +77,6 @@ export interface ClientJSON extends ClerkResourceJSON { created_at: number; updated_at: number; } -// export type ClientJSON = ClerkResourceJSON & { -// object: 'client'; -// id: string; -// status: any; -// sessions: SessionJSON[]; -// sign_up: SignUpJSON | null; -// sign_in: SignInJSON | null; -// last_active_session_id: string | null; -// cookie_expires_at: number | null; -// created_at: number; -// updated_at: number; -// } | { -// object: 'client'; -// id: null; -// status: null; -// sessions: null -// sign_up: null -// sign_in: null -// last_active_session_id: null -// cookie_expires_at: null -// created_at: null; -// updated_at: null; -// } export interface SignUpJSON extends ClerkResourceJSON { object: 'sign_up'; @@ -140,6 +118,7 @@ export interface SessionJSON extends ClerkResourceJSON { last_active_token: TokenJSON; last_active_organization_id: string | null; actor: ActJWTClaim | null; + tasks: SessionTasks | null; user: UserJSON; public_user_data: PublicUserDataJSON; created_at: number; diff --git a/packages/types/src/tasks.ts b/packages/types/src/tasks.ts new file mode 100644 index 00000000000..068ebd3e9b7 --- /dev/null +++ b/packages/types/src/tasks.ts @@ -0,0 +1,3 @@ +export interface SessionTasks { + orgs: Record; +} From 34763e5d21ed062f15651a24cbca390e1a661c5d Mon Sep 17 00:00:00 2001 From: Laura Beatris <48022589+LauraBeatris@users.noreply.github.com> Date: Fri, 14 Feb 2025 17:09:00 -0300 Subject: [PATCH 2/3] Add changeset --- .changeset/plenty-peas-pretend.md | 6 ++++++ packages/types/src/index.ts | 1 - packages/types/src/json.ts | 3 +-- packages/types/src/session.ts | 9 +++++++-- packages/types/src/tasks.ts | 3 --- 5 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 .changeset/plenty-peas-pretend.md delete mode 100644 packages/types/src/tasks.ts diff --git a/.changeset/plenty-peas-pretend.md b/.changeset/plenty-peas-pretend.md new file mode 100644 index 00000000000..d52fe008d5c --- /dev/null +++ b/.changeset/plenty-peas-pretend.md @@ -0,0 +1,6 @@ +--- +'@clerk/clerk-js': patch +'@clerk/types': patch +--- + +Initialize `tasks` on `Session` resource diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index b122e4cce9d..ea41eaa12aa 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -65,4 +65,3 @@ export * from './customMenuItems'; export * from './samlConnection'; export * from './waitlist'; export * from './snapshots'; -export * from './tasks'; diff --git a/packages/types/src/json.ts b/packages/types/src/json.ts index a7acb98ad5c..962179431d8 100644 --- a/packages/types/src/json.ts +++ b/packages/types/src/json.ts @@ -12,11 +12,10 @@ import type { OrganizationCustomRoleKey, OrganizationPermissionKey } from './org import type { OrganizationSettingsJSON } from './organizationSettings'; import type { OrganizationSuggestionStatus } from './organizationSuggestion'; import type { SamlIdpSlug } from './saml'; -import type { SessionStatus } from './session'; +import type { SessionStatus, SessionTasks } from './session'; import type { SessionVerificationLevel, SessionVerificationStatus } from './sessionVerification'; import type { SignInFirstFactor, SignInJSON, SignInSecondFactor } from './signIn'; import type { SignUpField, SignUpIdentificationField, SignUpStatus } from './signUp'; -import type { SessionTasks } from './tasks'; import type { BoxShadow, Color, EmUnit, FontWeight, HexColor } from './theme'; import type { UserSettingsJSON } from './userSettings'; import type { CamelToSnake } from './utils'; diff --git a/packages/types/src/session.ts b/packages/types/src/session.ts index 75fa93e6b92..76a782b9e24 100644 --- a/packages/types/src/session.ts +++ b/packages/types/src/session.ts @@ -96,13 +96,14 @@ export interface SessionResource extends ClerkResource { /** * Factor Verification Age * Each item represents the minutes that have passed since the last time a first or second factor were verified. - * [fistFactorAge, secondFactorAge] + * [firstFactorAge, secondFactorAge] */ - factorVerificationAge: [fistFactorAge: number, secondFactorAge: number] | null; + factorVerificationAge: [firstFactorAge: number, secondFactorAge: number] | null; lastActiveToken: TokenResource | null; lastActiveOrganizationId: string | null; lastActiveAt: Date; actor: ActJWTClaim | null; + tasks: SessionTasks | null; user: UserResource | null; publicUserData: PublicUserData; end: () => Promise; @@ -169,6 +170,10 @@ export interface PublicUserData { userId?: string; } +export interface SessionTasks { + orgs: Record; +} + export type GetTokenOptions = { template?: string; organizationId?: string; diff --git a/packages/types/src/tasks.ts b/packages/types/src/tasks.ts deleted file mode 100644 index 068ebd3e9b7..00000000000 --- a/packages/types/src/tasks.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface SessionTasks { - orgs: Record; -} From aa2c20a1806c0bec8743abe23ca742d1c9dcfbf1 Mon Sep 17 00:00:00 2001 From: Laura Beatris <48022589+LauraBeatris@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:19:33 -0300 Subject: [PATCH 3/3] Update tasks to array --- packages/clerk-js/src/core/resources/Session.ts | 4 ++-- packages/types/src/json.ts | 6 +++--- packages/types/src/session.ts | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/clerk-js/src/core/resources/Session.ts b/packages/clerk-js/src/core/resources/Session.ts index b28a899db4e..d10845636f2 100644 --- a/packages/clerk-js/src/core/resources/Session.ts +++ b/packages/clerk-js/src/core/resources/Session.ts @@ -12,7 +12,7 @@ import type { SessionJSONSnapshot, SessionResource, SessionStatus, - SessionTasks, + SessionTask, SessionVerificationJSON, SessionVerificationResource, SessionVerifyAttemptFirstFactorParams, @@ -43,7 +43,7 @@ export class Session extends BaseResource implements SessionResource { user!: UserResource | null; publicUserData!: PublicUserData; factorVerificationAge: [number, number] | null = null; - tasks!: SessionTasks | null; + tasks: Array | null = null; expireAt!: Date; abandonAt!: Date; createdAt!: Date; diff --git a/packages/types/src/json.ts b/packages/types/src/json.ts index 962179431d8..32dada36382 100644 --- a/packages/types/src/json.ts +++ b/packages/types/src/json.ts @@ -12,7 +12,7 @@ import type { OrganizationCustomRoleKey, OrganizationPermissionKey } from './org import type { OrganizationSettingsJSON } from './organizationSettings'; import type { OrganizationSuggestionStatus } from './organizationSuggestion'; import type { SamlIdpSlug } from './saml'; -import type { SessionStatus, SessionTasks } from './session'; +import type { SessionStatus, SessionTask } from './session'; import type { SessionVerificationLevel, SessionVerificationStatus } from './sessionVerification'; import type { SignInFirstFactor, SignInJSON, SignInSecondFactor } from './signIn'; import type { SignUpField, SignUpIdentificationField, SignUpStatus } from './signUp'; @@ -110,14 +110,14 @@ export interface SessionJSON extends ClerkResourceJSON { * This API is experimental and may change at any moment. * @experimental */ - factor_verification_age: [fistFactorAge: number, secondFactorAge: number] | null; + factor_verification_age: [firstFactorAge: number, secondFactorAge: number] | null; expire_at: number; abandon_at: number; last_active_at: number; last_active_token: TokenJSON; last_active_organization_id: string | null; actor: ActJWTClaim | null; - tasks: SessionTasks | null; + tasks: Array | null; user: UserJSON; public_user_data: PublicUserDataJSON; created_at: number; diff --git a/packages/types/src/session.ts b/packages/types/src/session.ts index 76a782b9e24..32f18a93260 100644 --- a/packages/types/src/session.ts +++ b/packages/types/src/session.ts @@ -103,7 +103,7 @@ export interface SessionResource extends ClerkResource { lastActiveOrganizationId: string | null; lastActiveAt: Date; actor: ActJWTClaim | null; - tasks: SessionTasks | null; + tasks: Array | null; user: UserResource | null; publicUserData: PublicUserData; end: () => Promise; @@ -170,8 +170,8 @@ export interface PublicUserData { userId?: string; } -export interface SessionTasks { - orgs: Record; +export interface SessionTask { + key: 'orgs'; } export type GetTokenOptions = {