@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.
@@ -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
- 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
- *
54
- * @example
55
- * ```typescript
56
- * try {
57
- * const tokens = await authClient.signIn('user@example.com', 'password');
58
- * console.log('Logged in!', tokens.accessToken);
59
- * } catch (error) {
60
- * if (error instanceof AuthError && error.code === 'USER_NOT_CONFIRMED') {
61
- * // Redirect to confirmation page
62
- * }
63
- * }
64
- * ```
65
- */
66
- signIn(email: string, password: string): Promise<AuthTokens>;
67
- /**
68
- * Signs up a new user.
69
- *
70
- * @param email - User's email address
71
- * @param password - User's password
72
- * @param name - Optional user's name
73
- * @returns Sign-up result with confirmation status
74
- * @throws {AuthError} If sign-up fails
75
- *
76
- * @example
77
- * ```typescript
78
- * const result = await authClient.signUp('user@example.com', 'password', 'John Doe');
79
- * if (!result.userConfirmed) {
80
- * // Show confirmation code input
81
- * console.log(`Code sent to ${result.codeDeliveryDetails?.destination}`);
82
- * }
83
- * ```
84
- */
85
- signUp(email: string, password: string, name?: string): Promise<SignUpResult>;
86
- /**
87
- * Confirms a user's sign-up with the verification code.
88
- *
89
- * @param email - User's email address
90
- * @param code - Verification code from email/SMS
91
- * @throws {AuthError} If confirmation fails
92
- *
93
- * @example
94
- * ```typescript
95
- * await authClient.confirmSignUp('user@example.com', '123456');
96
- * // User is now confirmed, can sign in
97
- * ```
98
- */
99
- confirmSignUp(email: string, code: string): Promise<void>;
100
- /**
101
- * Refreshes authentication tokens using a refresh token.
102
- *
103
- * @param refreshToken - The refresh token from a previous authentication
104
- * @returns New authentication tokens
105
- * @throws {AuthError} If refresh fails
106
- *
107
- * @example
108
- * ```typescript
109
- * // When access token is about to expire
110
- * const newTokens = await authClient.refreshTokens(tokens.refreshToken);
111
- * ```
112
- */
113
- refreshTokens(refreshToken: string): Promise<AuthTokens>;
114
- /**
115
- * Signs out the user from all devices.
116
- *
117
- * This invalidates all refresh tokens for the user, effectively
118
- * signing them out from all devices.
119
- *
120
- * @param accessToken - The user's current access token
121
- * @throws {AuthError} If sign-out fails
122
- *
123
- * @example
124
- * ```typescript
125
- * await authClient.signOut(tokens.accessToken);
126
- * // User is now signed out from all devices
127
- * ```
128
- */
129
- signOut(accessToken: string): Promise<void>;
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;AAUH,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;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