@fnd-platform/cognito-auth 1.0.0-alpha.1 → 1.0.0-alpha.3
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/lib/client/auth-client.d.ts +151 -94
- package/lib/client/auth-client.d.ts.map +1 -1
- package/lib/client/auth-client.js +330 -209
- package/lib/client/auth-client.js.map +1 -1
- package/lib/client/errors.d.ts +45 -23
- package/lib/client/errors.d.ts.map +1 -1
- package/lib/client/errors.js +80 -38
- package/lib/client/errors.js.map +1 -1
- package/lib/client/index.js +8 -23
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/jwt.js +27 -27
- package/lib/remix/session.server.d.ts.map +1 -1
- package/lib/remix/session.server.js +100 -95
- package/lib/remix/session.server.js.map +1 -1
- package/lib/types.d.ts +140 -106
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +3 -3
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*/
|
|
9
|
-
import type { AuthClientConfig, AuthTokens, SignUpResult } from '../types.js';
|
|
9
|
+
import type { AuthClientConfig, AuthTokens, SignUpResult, ForgotPasswordResult } from '../types.js';
|
|
10
10
|
/**
|
|
11
11
|
* Clears the client cache. Useful for testing.
|
|
12
12
|
*/
|
|
@@ -35,97 +35,154 @@ export declare function clearClientCache(): void;
|
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
37
|
export declare class FndAuthClient {
|
|
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
|
-
|
|
38
|
+
private readonly client;
|
|
39
|
+
private readonly clientId;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new FndAuthClient.
|
|
42
|
+
*
|
|
43
|
+
* @param config - Configuration for the auth client
|
|
44
|
+
*/
|
|
45
|
+
constructor(config: AuthClientConfig);
|
|
46
|
+
/**
|
|
47
|
+
* Signs in a user with email and password.
|
|
48
|
+
*
|
|
49
|
+
* @param email - User's email address
|
|
50
|
+
* @param password - User's password
|
|
51
|
+
* @returns Authentication tokens
|
|
52
|
+
* @throws {AuthError} If authentication fails
|
|
53
|
+
* @throws {NewPasswordRequiredError} If user must change password first
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* try {
|
|
58
|
+
* const tokens = await authClient.signIn('user@example.com', 'password');
|
|
59
|
+
* console.log('Logged in!', tokens.accessToken);
|
|
60
|
+
* } catch (error) {
|
|
61
|
+
* if (error instanceof NewPasswordRequiredError) {
|
|
62
|
+
* // Redirect to change password page
|
|
63
|
+
* redirect(`/change-password?session=${error.session}&email=${email}`);
|
|
64
|
+
* } else if (error instanceof AuthError && error.code === 'USER_NOT_CONFIRMED') {
|
|
65
|
+
* // Redirect to confirmation page
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
signIn(email: string, password: string): Promise<AuthTokens>;
|
|
71
|
+
/**
|
|
72
|
+
* Completes password change for users with FORCE_CHANGE_PASSWORD status.
|
|
73
|
+
*
|
|
74
|
+
* Use this after catching NewPasswordRequiredError from signIn().
|
|
75
|
+
*
|
|
76
|
+
* @param email - User's email address
|
|
77
|
+
* @param newPassword - New password to set
|
|
78
|
+
* @param session - Session token from NewPasswordRequiredError
|
|
79
|
+
* @returns Authentication tokens
|
|
80
|
+
* @throws {AuthError} If password change fails
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // After catching NewPasswordRequiredError
|
|
85
|
+
* const tokens = await authClient.completeNewPassword(
|
|
86
|
+
* email,
|
|
87
|
+
* newPassword,
|
|
88
|
+
* error.session
|
|
89
|
+
* );
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
completeNewPassword(email: string, newPassword: string, session: string): Promise<AuthTokens>;
|
|
93
|
+
/**
|
|
94
|
+
* Initiates forgot password flow.
|
|
95
|
+
*
|
|
96
|
+
* Sends a verification code to the user's email for password reset.
|
|
97
|
+
*
|
|
98
|
+
* @param email - User's email address
|
|
99
|
+
* @returns Delivery details for the reset code
|
|
100
|
+
* @throws {AuthError} If request fails
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const result = await authClient.forgotPassword('user@example.com');
|
|
105
|
+
* console.log(`Code sent to ${result.codeDeliveryDetails?.destination}`);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
forgotPassword(email: string): Promise<ForgotPasswordResult>;
|
|
109
|
+
/**
|
|
110
|
+
* Completes forgot password flow with verification code.
|
|
111
|
+
*
|
|
112
|
+
* @param email - User's email address
|
|
113
|
+
* @param code - Verification code from email
|
|
114
|
+
* @param newPassword - New password to set
|
|
115
|
+
* @throws {AuthError} If password reset fails
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* await authClient.confirmForgotPassword('user@example.com', '123456', 'NewP@ssw0rd');
|
|
120
|
+
* // User can now sign in with new password
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
confirmForgotPassword(email: string, code: string, newPassword: string): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Signs up a new user.
|
|
126
|
+
*
|
|
127
|
+
* @param email - User's email address
|
|
128
|
+
* @param password - User's password
|
|
129
|
+
* @param name - Optional user's name
|
|
130
|
+
* @returns Sign-up result with confirmation status
|
|
131
|
+
* @throws {AuthError} If sign-up fails
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* const result = await authClient.signUp('user@example.com', 'password', 'John Doe');
|
|
136
|
+
* if (!result.userConfirmed) {
|
|
137
|
+
* // Show confirmation code input
|
|
138
|
+
* console.log(`Code sent to ${result.codeDeliveryDetails?.destination}`);
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
signUp(email: string, password: string, name?: string): Promise<SignUpResult>;
|
|
143
|
+
/**
|
|
144
|
+
* Confirms a user's sign-up with the verification code.
|
|
145
|
+
*
|
|
146
|
+
* @param email - User's email address
|
|
147
|
+
* @param code - Verification code from email/SMS
|
|
148
|
+
* @throws {AuthError} If confirmation fails
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* await authClient.confirmSignUp('user@example.com', '123456');
|
|
153
|
+
* // User is now confirmed, can sign in
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
confirmSignUp(email: string, code: string): Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Refreshes authentication tokens using a refresh token.
|
|
159
|
+
*
|
|
160
|
+
* @param refreshToken - The refresh token from a previous authentication
|
|
161
|
+
* @returns New authentication tokens
|
|
162
|
+
* @throws {AuthError} If refresh fails
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* // When access token is about to expire
|
|
167
|
+
* const newTokens = await authClient.refreshTokens(tokens.refreshToken);
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
refreshTokens(refreshToken: string): Promise<AuthTokens>;
|
|
171
|
+
/**
|
|
172
|
+
* Signs out the user from all devices.
|
|
173
|
+
*
|
|
174
|
+
* This invalidates all refresh tokens for the user, effectively
|
|
175
|
+
* signing them out from all devices.
|
|
176
|
+
*
|
|
177
|
+
* @param accessToken - The user's current access token
|
|
178
|
+
* @throws {AuthError} If sign-out fails
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* await authClient.signOut(tokens.accessToken);
|
|
183
|
+
* // User is now signed out from all devices
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
signOut(accessToken: string): Promise<void>;
|
|
130
187
|
}
|
|
131
|
-
//# sourceMappingURL=auth-client.d.ts.map
|
|
188
|
+
//# sourceMappingURL=auth-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-client.d.ts","sourceRoot":"","sources":["../../src/client/auth-client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"au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