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

chore(clerk-js,types): Initialize tasks on Session resource #5170

Merged
merged 3 commits into from
Feb 18, 2025
Merged
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
6 changes: 6 additions & 0 deletions .changeset/plenty-peas-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': patch
'@clerk/types': patch
---

Initialize `tasks` on `Session` resource
4 changes: 4 additions & 0 deletions packages/clerk-js/src/core/resources/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
SessionJSONSnapshot,
SessionResource,
SessionStatus,
SessionTask,
SessionVerificationJSON,
SessionVerificationResource,
SessionVerifyAttemptFirstFactorParams,
Expand Down Expand Up @@ -42,6 +43,7 @@ export class Session extends BaseResource implements SessionResource {
user!: UserResource | null;
publicUserData!: PublicUserData;
factorVerificationAge: [number, number] | null = null;
tasks: Array<SessionTask> | null = null;
expireAt!: Date;
abandonAt!: Date;
createdAt!: Date;
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
28 changes: 3 additions & 25 deletions packages/types/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } 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';
Expand Down Expand Up @@ -76,29 +76,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';
Expand Down Expand Up @@ -133,13 +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: Array<SessionTask> | null;
user: UserJSON;
public_user_data: PublicUserDataJSON;
created_at: number;
Expand Down
9 changes: 7 additions & 2 deletions packages/types/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: Array<SessionTask> | null;
user: UserResource | null;
publicUserData: PublicUserData;
end: () => Promise<SessionResource>;
Expand Down Expand Up @@ -169,6 +170,10 @@ export interface PublicUserData {
userId?: string;
}

export interface SessionTask {
key: 'orgs';
}

export type GetTokenOptions = {
template?: string;
organizationId?: string;
Expand Down