forked from clerk/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession.ts
More file actions
166 lines (149 loc) · 4.99 KB
/
Copy pathsession.ts
File metadata and controls
166 lines (149 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import type {
BackupCodeAttempt,
EmailCodeAttempt,
EmailCodeConfig,
PasswordAttempt,
PhoneCodeAttempt,
PhoneCodeConfig,
PhoneCodeSecondFactorConfig,
TOTPAttempt,
} from './factors';
import type { ActJWTClaim } from './jwt';
import type {
OrganizationCustomPermissionKey,
OrganizationCustomRoleKey,
OrganizationPermissionKey,
} from './organizationMembership';
import type { ClerkResource } from './resource';
import type {
__experimental_ReverificationConfig,
__experimental_SessionVerificationLevel,
__experimental_SessionVerificationResource,
} from './sessionVerification';
import type { TokenResource } from './token';
import type { UserResource } from './user';
export type CheckAuthorizationFn<Params> = (isAuthorizedParams: Params) => boolean;
export type CheckAuthorizationWithCustomPermissions =
CheckAuthorizationFn<CheckAuthorizationParamsWithCustomPermissions>;
export type CheckAuthorizationParamsWithCustomPermissions = (
| {
role: OrganizationCustomRoleKey;
permission?: never;
}
| {
role?: never;
permission: OrganizationCustomPermissionKey;
}
| { role?: never; permission?: never }
) & {
__experimental_reverification?: __experimental_ReverificationConfig;
};
export type CheckAuthorization = CheckAuthorizationFn<CheckAuthorizationParams>;
type CheckAuthorizationParams = (
| {
role: OrganizationCustomRoleKey;
permission?: never;
}
| {
role?: never;
permission: OrganizationPermissionKey;
}
| {
role?: never;
permission?: never;
}
) & {
__experimental_reverification?: __experimental_ReverificationConfig;
};
export interface SessionResource extends ClerkResource {
id: string;
status: SessionStatus;
expireAt: Date;
abandonAt: Date;
/**
* Factor Verification Age
* Each item represents the minutes that have passed since the last time a first or second factor were verified.
* [fistFactorAge, secondFactorAge]
* @experimental This API is experimental and may change at any moment.
*/
__experimental_factorVerificationAge: [number, number] | null;
lastActiveToken: TokenResource | null;
lastActiveOrganizationId: string | null;
lastActiveAt: Date;
actor: ActJWTClaim | null;
user: UserResource | null;
publicUserData: PublicUserData;
end: () => Promise<SessionResource>;
remove: () => Promise<SessionResource>;
touch: () => Promise<SessionResource>;
getToken: GetToken;
checkAuthorization: CheckAuthorization;
clearCache: () => void;
createdAt: Date;
updatedAt: Date;
__experimental_startVerification: (
params: __experimental_SessionVerifyCreateParams,
) => Promise<__experimental_SessionVerificationResource>;
__experimental_prepareFirstFactorVerification: (
factor: __experimental_SessionVerifyPrepareFirstFactorParams,
) => Promise<__experimental_SessionVerificationResource>;
__experimental_attemptFirstFactorVerification: (
attemptFactor: __experimental_SessionVerifyAttemptFirstFactorParams,
) => Promise<__experimental_SessionVerificationResource>;
__experimental_prepareSecondFactorVerification: (
params: __experimental_SessionVerifyPrepareSecondFactorParams,
) => Promise<__experimental_SessionVerificationResource>;
__experimental_attemptSecondFactorVerification: (
params: __experimental_SessionVerifyAttemptSecondFactorParams,
) => Promise<__experimental_SessionVerificationResource>;
}
export interface ActiveSessionResource extends SessionResource {
status: 'active';
user: UserResource;
}
export interface SessionWithActivitiesResource extends ClerkResource {
id: string;
status: string;
expireAt: Date;
abandonAt: Date;
lastActiveAt: Date;
latestActivity: SessionActivity;
actor: ActJWTClaim | null;
revoke: () => Promise<SessionWithActivitiesResource>;
}
export interface SessionActivity {
id: string;
browserName?: string;
browserVersion?: string;
deviceType?: string;
ipAddress?: string;
city?: string;
country?: string;
isMobile?: boolean;
}
export type SessionStatus = 'abandoned' | 'active' | 'ended' | 'expired' | 'removed' | 'replaced' | 'revoked';
export interface PublicUserData {
firstName: string | null;
lastName: string | null;
imageUrl: string;
hasImage: boolean;
identifier: string;
userId?: string;
}
export type GetTokenOptions = {
template?: string;
organizationId?: string;
leewayInSeconds?: number;
skipCache?: boolean;
};
export type GetToken = (options?: GetTokenOptions) => Promise<string | null>;
export type __experimental_SessionVerifyCreateParams = {
level: __experimental_SessionVerificationLevel;
};
export type __experimental_SessionVerifyPrepareFirstFactorParams = EmailCodeConfig | PhoneCodeConfig;
export type __experimental_SessionVerifyAttemptFirstFactorParams =
| EmailCodeAttempt
| PhoneCodeAttempt
| PasswordAttempt;
export type __experimental_SessionVerifyPrepareSecondFactorParams = PhoneCodeSecondFactorConfig;
export type __experimental_SessionVerifyAttemptSecondFactorParams = PhoneCodeAttempt | TOTPAttempt | BackupCodeAttempt;