Skip to content

Commit c2ba745

Browse files
authored
chore(clerk-react,types): Add JSDoc comments (#6669)
1 parent f1ccc98 commit c2ba745

File tree

8 files changed

+294
-37
lines changed

8 files changed

+294
-37
lines changed

.changeset/ninety-crews-find.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

.typedoc/__tests__/__snapshots__/file-structure.test.ts.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
6363
"types/create-organization-params.mdx",
6464
"types/element-object-key.mdx",
6565
"types/elements-config.mdx",
66+
"types/errors.mdx",
6667
"types/experimental_checkout-button-props.mdx",
6768
"types/experimental_plan-details-button-props.mdx",
6869
"types/experimental_subscription-details-button-props.mdx",
70+
"types/field-error.mdx",
71+
"types/field-errors.mdx",
6972
"types/for-payer-type.mdx",
7073
"types/get-payment-attempts-params.mdx",
7174
"types/get-payment-sources-params.mdx",
@@ -119,9 +122,12 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
119122
"types/session-verification-types.mdx",
120123
"types/set-active-params.mdx",
121124
"types/set-active.mdx",
125+
"types/sign-in-future-resource.mdx",
122126
"types/sign-in-resource.mdx",
127+
"types/sign-in-signal-value.mdx",
123128
"types/sign-out.mdx",
124129
"types/sign-up-authenticate-with-metamask-params.mdx",
130+
"types/sign-up-future-resource.mdx",
125131
"types/sign-up-resource.mdx",
126132
"types/signed-in-session-resource.mdx",
127133
"types/state-selectors.mdx",
@@ -203,19 +209,27 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
203209
"nextjs/current-user.mdx",
204210
"nextjs/get-auth.mdx",
205211
"clerk-react/api-keys.mdx",
212+
"clerk-react/checkout-button-props.mdx",
213+
"clerk-react/checkout-button.mdx",
206214
"clerk-react/clerk-provider-props.mdx",
215+
"clerk-react/plan-details-button-props.mdx",
216+
"clerk-react/plan-details-button.mdx",
207217
"clerk-react/protect.mdx",
208218
"clerk-react/redirect-to-create-organization.mdx",
209219
"clerk-react/redirect-to-organization-profile.mdx",
210220
"clerk-react/redirect-to-user-profile.mdx",
221+
"clerk-react/subscription-details-button-props.mdx",
222+
"clerk-react/subscription-details-button.mdx",
211223
"clerk-react/use-auth.mdx",
212224
"clerk-react/use-clerk.mdx",
213225
"clerk-react/use-organization-list.mdx",
214226
"clerk-react/use-organization.mdx",
215227
"clerk-react/use-reverification.mdx",
216228
"clerk-react/use-session-list.mdx",
217229
"clerk-react/use-session.mdx",
230+
"clerk-react/use-sign-in-signal.mdx",
218231
"clerk-react/use-sign-in.mdx",
232+
"clerk-react/use-sign-up-signal.mdx",
219233
"clerk-react/use-sign-up.mdx",
220234
"clerk-react/use-user.mdx",
221235
"backend/allowlist-identifier.mdx",

packages/react/src/hooks/useClerkSignal.ts

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
import type { SignInSignal, SignUpSignal } from '@clerk/types';
1+
import type { SignInSignalValue, SignUpSignalValue } from '@clerk/types';
22
import { useCallback, useSyncExternalStore } from 'react';
33

44
import { useIsomorphicClerkContext } from '../contexts/IsomorphicClerkContext';
55
import { useAssertWrappedByClerkProvider } from './useAssertWrappedByClerkProvider';
66

7-
// These types are used to remove the `null` value from the underlying resource. This is safe because IsomorphicClerk
8-
// always returns a valid resource, even before Clerk is loaded, and if Clerk is loaded, the resource is guaranteed to
9-
// be non-null
10-
type NonNullSignInSignal = Omit<ReturnType<SignInSignal>, 'signIn'> & {
11-
signIn: NonNullable<ReturnType<SignInSignal>['signIn']>;
12-
};
13-
type NonNullSignUpSignal = Omit<ReturnType<SignUpSignal>, 'signUp'> & {
14-
signUp: NonNullable<ReturnType<SignUpSignal>['signUp']>;
15-
};
16-
17-
function useClerkSignal(signal: 'signIn'): NonNullSignInSignal;
18-
function useClerkSignal(signal: 'signUp'): NonNullSignUpSignal;
19-
function useClerkSignal(signal: 'signIn' | 'signUp'): NonNullSignInSignal | NonNullSignUpSignal {
7+
function useClerkSignal(signal: 'signIn'): SignInSignalValue;
8+
function useClerkSignal(signal: 'signUp'): SignUpSignalValue;
9+
function useClerkSignal(signal: 'signIn' | 'signUp'): SignInSignalValue | SignUpSignalValue {
2010
useAssertWrappedByClerkProvider('useClerkSignal');
2111

2212
const clerk = useIsomorphicClerkContext();
@@ -46,9 +36,9 @@ function useClerkSignal(signal: 'signIn' | 'signUp'): NonNullSignInSignal | NonN
4636
const getSnapshot = useCallback(() => {
4737
switch (signal) {
4838
case 'signIn':
49-
return clerk.__internal_state.signInSignal() as NonNullSignInSignal;
39+
return clerk.__internal_state.signInSignal() as SignInSignalValue;
5040
case 'signUp':
51-
return clerk.__internal_state.signUpSignal() as NonNullSignUpSignal;
41+
return clerk.__internal_state.signUpSignal() as SignUpSignalValue;
5242
default:
5343
throw new Error(`Unknown signal: ${signal}`);
5444
}
@@ -59,10 +49,34 @@ function useClerkSignal(signal: 'signIn' | 'signUp'): NonNullSignInSignal | NonN
5949
return value;
6050
}
6151

52+
/**
53+
* This hook allows you to access the Signal-based `SignIn` resource.
54+
*
55+
* @experimental This experimental API is subject to change.
56+
* @example
57+
* import { useSignInSignal } from "@clerk/clerk-react/experimental";
58+
*
59+
* function SignInForm() {
60+
* const { signIn, errors, fetchStatus } = useSignInSignal();
61+
* //
62+
* }
63+
*/
6264
export function useSignInSignal() {
6365
return useClerkSignal('signIn');
6466
}
6567

68+
/**
69+
* This hook allows you to access the Signal-based `SignUp` resource.
70+
*
71+
* @experimental This experimental API is subject to change.
72+
* @example
73+
* import { useSignUpSignal } from "@clerk/clerk-react/experimental";
74+
*
75+
* function SignUpForm() {
76+
* const { signUp, errors, fetchStatus } = useSignUpSignal();
77+
* //
78+
* }
79+
*/
6680
export function useSignUpSignal() {
6781
return useClerkSignal('signUp');
6882
}

packages/react/typedoc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"$schema": "https://typedoc.org/schema.json",
3-
"entryPoints": ["./src/index.ts"]
3+
"entryPoints": ["./src/index.ts", "./src/experimental.ts"]
44
}

packages/types/src/signInFuture.ts

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,32 +82,123 @@ export interface SignInFutureFinalizeParams {
8282
navigate?: SetActiveNavigate;
8383
}
8484

85+
/**
86+
* The current active `SignIn` instance, for use in custom flows.
87+
*/
8588
export interface SignInFutureResource {
86-
availableStrategies: SignInFirstFactor[];
87-
status: SignInStatus | null;
88-
isTransferable: boolean;
89-
existingSession?: { sessionId: string };
89+
/**
90+
* The list of first-factor strategies that are available for the current sign-in attempt.
91+
*/
92+
readonly availableStrategies: SignInFirstFactor[];
93+
94+
/**
95+
* The status of the current sign-in attempt as a string (for example, `'needs_identifier'`, `'needs_first_factor'`,
96+
* `'complete'`, etc.)
97+
*/
98+
readonly status: SignInStatus | null;
99+
100+
/**
101+
* Indicates that there is not a matching user for the first-factor verification used, and that the sign-in can be
102+
* transferred to a sign-up.
103+
*/
104+
readonly isTransferable: boolean;
105+
106+
readonly existingSession?: { sessionId: string };
107+
108+
/**
109+
* Used to supply an identifier for the sign-in attempt. Calling this method will populate data on the sign-in
110+
* attempt, such as `signIn.resource.supportedFirstFactors`.
111+
*/
90112
create: (params: SignInFutureCreateParams) => Promise<{ error: unknown }>;
113+
114+
/**
115+
* Used to submit a password to sign-in.
116+
*/
91117
password: (params: SignInFuturePasswordParams) => Promise<{ error: unknown }>;
118+
119+
/**
120+
*
121+
*/
92122
emailCode: {
123+
/**
124+
* Used to send an email code to sign-in
125+
*/
93126
sendCode: (params: SignInFutureEmailCodeSendParams) => Promise<{ error: unknown }>;
127+
128+
/**
129+
* Used to verify a code sent via email to sign-in
130+
*/
94131
verifyCode: (params: SignInFutureEmailCodeVerifyParams) => Promise<{ error: unknown }>;
95132
};
133+
134+
/**
135+
*
136+
*/
96137
phoneCode: {
138+
/**
139+
* Used to send a phone code to sign-in
140+
*/
97141
sendCode: (params: SignInFuturePhoneCodeSendParams) => Promise<{ error: unknown }>;
142+
143+
/**
144+
* Used to verify a code sent via phone to sign-in
145+
*/
98146
verifyCode: (params: SignInFuturePhoneCodeVerifyParams) => Promise<{ error: unknown }>;
99147
};
148+
149+
/**
150+
*
151+
*/
100152
resetPasswordEmailCode: {
153+
/**
154+
* Used to send a password reset code to the first email address on the account
155+
*/
101156
sendCode: () => Promise<{ error: unknown }>;
157+
158+
/**
159+
* Used to verify a password reset code sent via email. Will cause `signIn.status` to become `'needs_new_password'`.
160+
*/
102161
verifyCode: (params: SignInFutureEmailCodeVerifyParams) => Promise<{ error: unknown }>;
162+
163+
/**
164+
* Used to submit a new password, and move the `signIn.status` to `'complete'`.
165+
*/
103166
submitPassword: (params: SignInFutureResetPasswordSubmitParams) => Promise<{ error: unknown }>;
104167
};
168+
169+
/**
170+
* Used to perform OAuth authentication.
171+
*/
105172
sso: (params: SignInFutureSSOParams) => Promise<{ error: unknown }>;
173+
174+
/**
175+
*
176+
*/
106177
mfa: {
178+
/**
179+
* Used to send a phone code as a second factor to sign-in
180+
*/
107181
sendPhoneCode: () => Promise<{ error: unknown }>;
182+
183+
/**
184+
* Used to verify a phone code sent as a second factor to sign-in
185+
*/
108186
verifyPhoneCode: (params: SignInFutureMFAPhoneCodeVerifyParams) => Promise<{ error: unknown }>;
187+
188+
/**
189+
* Used to verify a TOTP code as a second factor to sign-in
190+
*/
109191
verifyTOTP: (params: SignInFutureTOTPVerifyParams) => Promise<{ error: unknown }>;
192+
193+
/**
194+
* Used to verify a backup code as a second factor to sign-in
195+
*/
110196
verifyBackupCode: (params: SignInFutureBackupCodeVerifyParams) => Promise<{ error: unknown }>;
111197
};
198+
199+
/**
200+
* Used to convert a sign-in with `status === ‘complete’` into an active session. Will cause anything observing the
201+
* session state (such as the `useUser()` hook) to update automatically.
202+
*/
112203
finalize: (params?: SignInFutureFinalizeParams) => Promise<{ error: unknown }>;
113204
}

packages/types/src/signUpFuture.ts

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,68 @@ export interface SignUpFutureFinalizeParams {
4747
navigate?: SetActiveNavigate;
4848
}
4949

50+
/**
51+
* The current active `SignUp` instance, for use in custom flows.
52+
*/
5053
export interface SignUpFutureResource {
51-
status: SignUpStatus | null;
52-
unverifiedFields: SignUpIdentificationField[];
53-
isTransferable: boolean;
54-
existingSession?: { sessionId: string };
54+
/**
55+
* The status of the current sign-up attempt as a string (for example, `'missing_requirements'`, `'complete'`, `'abandoned'`, etc.)
56+
*/
57+
readonly status: SignUpStatus | null;
58+
59+
/**
60+
* An array of strings representing unverified fields such as `’email_address’`. Can be used to detect when verification is necessary.
61+
*/
62+
readonly unverifiedFields: SignUpIdentificationField[];
63+
64+
/**
65+
* Indicates that there is a matching user for provided identifier, and that the sign-up can be transferred to
66+
* a sign-in.
67+
*/
68+
readonly isTransferable: boolean;
69+
70+
readonly existingSession?: { sessionId: string };
71+
5572
create: (params: SignUpFutureCreateParams) => Promise<{ error: unknown }>;
73+
74+
/**
75+
*
76+
*/
5677
verifications: {
78+
/**
79+
* Used to send an email code to verify an email address.
80+
*/
5781
sendEmailCode: () => Promise<{ error: unknown }>;
82+
83+
/**
84+
* Used to verify a code sent via email.
85+
*/
5886
verifyEmailCode: (params: SignUpFutureEmailCodeVerifyParams) => Promise<{ error: unknown }>;
87+
88+
/**
89+
* Used to send a phone code to verify a phone number.
90+
*/
5991
sendPhoneCode: (params: SignUpFuturePhoneCodeSendParams) => Promise<{ error: unknown }>;
92+
93+
/**
94+
* Used to verify a code sent via phone.
95+
*/
6096
verifyPhoneCode: (params: SignUpFuturePhoneCodeVerifyParams) => Promise<{ error: unknown }>;
6197
};
98+
99+
/**
100+
* Used to sign up using an email address and password.
101+
*/
62102
password: (params: SignUpFuturePasswordParams) => Promise<{ error: unknown }>;
103+
104+
/**
105+
* Used to create an account using an OAuth connection.
106+
*/
63107
sso: (params: SignUpFutureSSOParams) => Promise<{ error: unknown }>;
108+
109+
/**
110+
* Used to convert a sign-up with `status === ‘complete’` into an active session. Will cause anything observing the
111+
* session state (such as the `useUser()` hook) to update automatically.
112+
*/
64113
finalize: (params?: SignUpFutureFinalizeParams) => Promise<{ error: unknown }>;
65114
}

0 commit comments

Comments
 (0)