@imtbl/auth 2.10.7-alpha.4 → 2.10.7-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.js +29 -29
- package/dist/node/index.cjs +34 -36
- package/dist/node/index.js +23 -23
- package/dist/types/Auth.d.ts +56 -26
- package/dist/types/index.d.ts +2 -3
- package/dist/types/types.d.ts +10 -17
- package/dist/types/utils/metrics.d.ts +2 -0
- package/package.json +4 -4
- package/src/Auth.ts +676 -98
- package/src/index.ts +1 -5
- package/src/types.ts +7 -17
- package/src/utils/metrics.ts +29 -0
- package/dist/types/authManager.d.ts +0 -61
- package/src/authManager.ts +0 -657
package/src/index.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// Export Auth class (public API)
|
|
2
2
|
export { Auth } from './Auth';
|
|
3
3
|
|
|
4
|
-
// Export AuthManager for use by other packages
|
|
5
|
-
export { default as AuthManager } from './authManager';
|
|
6
|
-
|
|
7
4
|
// Export configuration
|
|
8
5
|
export { AuthConfiguration, type IAuthConfiguration } from './config';
|
|
9
6
|
|
|
@@ -11,7 +8,6 @@ export { AuthConfiguration, type IAuthConfiguration } from './config';
|
|
|
11
8
|
export type {
|
|
12
9
|
User,
|
|
13
10
|
UserProfile,
|
|
14
|
-
UserImx,
|
|
15
11
|
UserZkEvm,
|
|
16
12
|
DirectLoginMethod,
|
|
17
13
|
DirectLoginOptions,
|
|
@@ -26,7 +22,7 @@ export type {
|
|
|
26
22
|
AuthEventMap,
|
|
27
23
|
} from './types';
|
|
28
24
|
export {
|
|
29
|
-
isUserZkEvm,
|
|
25
|
+
isUserZkEvm, RollupType, MarketingConsentStatus, AuthEvents,
|
|
30
26
|
} from './types';
|
|
31
27
|
|
|
32
28
|
// Export TypedEventEmitter
|
package/src/types.ts
CHANGED
|
@@ -12,7 +12,6 @@ export type UserProfile = {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export enum RollupType {
|
|
15
|
-
IMX = 'imx',
|
|
16
15
|
ZKEVM = 'zkEvm',
|
|
17
16
|
}
|
|
18
17
|
|
|
@@ -22,11 +21,6 @@ export type User = {
|
|
|
22
21
|
refreshToken?: string;
|
|
23
22
|
profile: UserProfile;
|
|
24
23
|
expired?: boolean;
|
|
25
|
-
[RollupType.IMX]?: {
|
|
26
|
-
ethAddress: string;
|
|
27
|
-
starkAddress: string;
|
|
28
|
-
userAdminAddress: string;
|
|
29
|
-
};
|
|
30
24
|
[RollupType.ZKEVM]?: {
|
|
31
25
|
ethAddress: string;
|
|
32
26
|
userAdminAddress: string;
|
|
@@ -34,11 +28,8 @@ export type User = {
|
|
|
34
28
|
};
|
|
35
29
|
|
|
36
30
|
export type PassportMetadata = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
imx_user_admin_address: string;
|
|
40
|
-
zkevm_eth_address: string;
|
|
41
|
-
zkevm_user_admin_address: string;
|
|
31
|
+
zkevm_eth_address?: string;
|
|
32
|
+
zkevm_user_admin_address?: string;
|
|
42
33
|
};
|
|
43
34
|
|
|
44
35
|
export interface OidcConfiguration {
|
|
@@ -82,11 +73,9 @@ export interface AuthModuleConfiguration extends OidcConfiguration {
|
|
|
82
73
|
|
|
83
74
|
type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
|
|
84
75
|
|
|
85
|
-
export type UserImx = WithRequired<User, RollupType.IMX>;
|
|
86
76
|
export type UserZkEvm = WithRequired<User, RollupType.ZKEVM>;
|
|
87
77
|
|
|
88
78
|
export const isUserZkEvm = (user: User): user is UserZkEvm => !!user[RollupType.ZKEVM];
|
|
89
|
-
export const isUserImx = (user: User): user is UserImx => !!user[RollupType.IMX];
|
|
90
79
|
|
|
91
80
|
export type DeviceTokenResponse = {
|
|
92
81
|
access_token: string;
|
|
@@ -122,10 +111,11 @@ export enum MarketingConsentStatus {
|
|
|
122
111
|
}
|
|
123
112
|
|
|
124
113
|
export type DirectLoginOptions = {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
email
|
|
128
|
-
}
|
|
114
|
+
marketingConsentStatus: MarketingConsentStatus;
|
|
115
|
+
} & (
|
|
116
|
+
| { directLoginMethod: 'email'; email: string }
|
|
117
|
+
| { directLoginMethod: Exclude<DirectLoginMethod, 'email'>; email?: never }
|
|
118
|
+
);
|
|
129
119
|
|
|
130
120
|
/**
|
|
131
121
|
* Extended login options with caching and silent login support
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Flow, trackError, trackFlow } from '@imtbl/metrics';
|
|
2
|
+
|
|
3
|
+
export const withMetricsAsync = async <T>(
|
|
4
|
+
fn: (flow: Flow) => Promise<T>,
|
|
5
|
+
flowName: string,
|
|
6
|
+
trackStartEvent: boolean = true,
|
|
7
|
+
trackEndEvent: boolean = true,
|
|
8
|
+
): Promise<T> => {
|
|
9
|
+
const flow: Flow = trackFlow(
|
|
10
|
+
'passport',
|
|
11
|
+
flowName,
|
|
12
|
+
trackStartEvent,
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
return await fn(flow);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (error instanceof Error) {
|
|
19
|
+
trackError('passport', flowName, error, { flowId: flow.details.flowId });
|
|
20
|
+
} else {
|
|
21
|
+
flow.addEvent('errored');
|
|
22
|
+
}
|
|
23
|
+
throw error;
|
|
24
|
+
} finally {
|
|
25
|
+
if (trackEndEvent) {
|
|
26
|
+
flow.addEvent('End');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { DirectLoginOptions, User, DeviceTokenResponse, UserZkEvm, UserImx } from './types';
|
|
2
|
-
import { IAuthConfiguration } from './config';
|
|
3
|
-
import EmbeddedLoginPrompt from './login/embeddedLoginPrompt';
|
|
4
|
-
export default class AuthManager {
|
|
5
|
-
private userManager;
|
|
6
|
-
private deviceCredentialsManager;
|
|
7
|
-
private readonly config;
|
|
8
|
-
private readonly embeddedLoginPrompt;
|
|
9
|
-
private readonly logoutMode;
|
|
10
|
-
/**
|
|
11
|
-
* Promise that is used to prevent multiple concurrent calls to the refresh token endpoint.
|
|
12
|
-
*/
|
|
13
|
-
private refreshingPromise;
|
|
14
|
-
constructor(config: IAuthConfiguration, embeddedLoginPrompt: EmbeddedLoginPrompt);
|
|
15
|
-
private static mapOidcUserToDomainModel;
|
|
16
|
-
private static mapDeviceTokenResponseToOidcUser;
|
|
17
|
-
private buildExtraQueryParams;
|
|
18
|
-
loginWithRedirect(directLoginOptions?: DirectLoginOptions): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* login
|
|
21
|
-
* @param directLoginOptions If provided, contains login method and marketing consent options
|
|
22
|
-
* @param directLoginOptions.directLoginMethod The login method to use (e.g., 'google', 'apple', 'email')
|
|
23
|
-
* @param directLoginOptions.marketingConsentStatus Marketing consent status ('opted_in' or 'unsubscribed')
|
|
24
|
-
* @param directLoginOptions.email Required when directLoginMethod is 'email'
|
|
25
|
-
*/
|
|
26
|
-
login(directLoginOptions?: DirectLoginOptions): Promise<User>;
|
|
27
|
-
getUserOrLogin(): Promise<User>;
|
|
28
|
-
private static shouldUseSigninPopupCallback;
|
|
29
|
-
loginCallback(): Promise<undefined | User>;
|
|
30
|
-
getPKCEAuthorizationUrl(directLoginOptions?: DirectLoginOptions, imPassportTraceId?: string): Promise<string>;
|
|
31
|
-
loginWithPKCEFlowCallback(authorizationCode: string, state: string): Promise<User>;
|
|
32
|
-
private getPKCEToken;
|
|
33
|
-
storeTokens(tokenResponse: DeviceTokenResponse): Promise<User>;
|
|
34
|
-
logout(): Promise<void>;
|
|
35
|
-
logoutSilentCallback(url: string): Promise<void>;
|
|
36
|
-
removeUser(): Promise<void>;
|
|
37
|
-
getLogoutUrl(): Promise<string | null>;
|
|
38
|
-
forceUserRefreshInBackground(): void;
|
|
39
|
-
forceUserRefresh(): Promise<User | null>;
|
|
40
|
-
/**
|
|
41
|
-
* Refreshes the token and returns the user.
|
|
42
|
-
* If the token is already being refreshed, returns the existing promise.
|
|
43
|
-
*/
|
|
44
|
-
private refreshTokenAndUpdatePromise;
|
|
45
|
-
/**
|
|
46
|
-
*
|
|
47
|
-
* @param typeAssertion {(user: User) => boolean} - Optional. If provided, then the User will be checked against
|
|
48
|
-
* the typeAssertion. If the user meets the requirements, then it will be typed as T and returned. If the User
|
|
49
|
-
* does NOT meet the type assertion, then execution will continue, and we will attempt to obtain a User that does
|
|
50
|
-
* meet the type assertion.
|
|
51
|
-
*
|
|
52
|
-
* This function will attempt to obtain a User in the following order:
|
|
53
|
-
* 1. If the User is currently refreshing, wait for the refresh to complete.
|
|
54
|
-
* 2. Attempt to obtain a User from storage that has not expired.
|
|
55
|
-
* 3. Attempt to refresh the User if a refresh token is present.
|
|
56
|
-
* 4. Return null if no valid User can be obtained.
|
|
57
|
-
*/
|
|
58
|
-
getUser<T extends User>(typeAssertion?: (user: User) => user is T): Promise<T | null>;
|
|
59
|
-
getUserZkEvm(): Promise<UserZkEvm>;
|
|
60
|
-
getUserImx(): Promise<UserImx>;
|
|
61
|
-
}
|