-
Notifications
You must be signed in to change notification settings - Fork 361
feat(backend): Add sign ups to Backend API client #5625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
'@clerk/backend': minor | ||
--- | ||
|
||
Adds the ability to retrieve and update Sign Up Attempts to the Backend API client. | ||
|
||
|
||
```ts | ||
import { createClerkClient } from '@clerk/backend'; | ||
|
||
const clerkClient = createClerkClient(...); | ||
|
||
await clerkClient.signUps.get('signUpAttemptId'); | ||
await clerkClient.signUps.update({...}); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { joinPaths } from '../../util/path'; | ||
import type { SignUpAttempt } from '../resources/SignUpAttempt'; | ||
import { AbstractAPI } from './AbstractApi'; | ||
|
||
type UpdateSignUpParams = { | ||
signUpAttemptId: string; | ||
externalId?: string | null; | ||
customAction?: boolean | null; | ||
}; | ||
|
||
const basePath = '/sign_ups'; | ||
|
||
export class SignUpAPI extends AbstractAPI { | ||
public async get(signUpAttemptId: string) { | ||
this.requireId(signUpAttemptId); | ||
|
||
return this.request<SignUpAttempt>({ | ||
method: 'GET', | ||
path: joinPaths(basePath, signUpAttemptId), | ||
}); | ||
} | ||
|
||
public async update(params: UpdateSignUpParams) { | ||
const { signUpAttemptId, ...bodyParams } = params; | ||
|
||
return this.request<SignUpAttempt>({ | ||
method: 'PATCH', | ||
path: joinPaths(basePath, signUpAttemptId), | ||
bodyParams, | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import type { SignUpStatus } from '@clerk/types'; | ||
|
||
import type { SignUpVerificationNextAction } from './Enums'; | ||
import type { SignUpJSON, SignUpVerificationJSON, SignUpVerificationsJSON } from './JSON'; | ||
|
||
export class SignUpAttemptVerification { | ||
constructor( | ||
readonly nextAction: SignUpVerificationNextAction, | ||
readonly supportedStrategies: string[], | ||
) {} | ||
|
||
static fromJSON(data: SignUpVerificationJSON): SignUpAttemptVerification { | ||
return new SignUpAttemptVerification(data.next_action, data.supported_strategies); | ||
} | ||
} | ||
|
||
export class SignUpAttemptVerifications { | ||
constructor( | ||
readonly emailAddress: SignUpAttemptVerification | null, | ||
readonly phoneNumber: SignUpAttemptVerification | null, | ||
readonly web3Wallet: SignUpAttemptVerification | null, | ||
readonly externalAccount: object | null, | ||
) {} | ||
|
||
static fromJSON(data: SignUpVerificationsJSON): SignUpAttemptVerifications { | ||
return new SignUpAttemptVerifications( | ||
data.email_address && SignUpAttemptVerification.fromJSON(data.email_address), | ||
data.phone_number && SignUpAttemptVerification.fromJSON(data.phone_number), | ||
data.web3_wallet && SignUpAttemptVerification.fromJSON(data.web3_wallet), | ||
data.external_account, | ||
); | ||
} | ||
} | ||
|
||
export class SignUpAttempt { | ||
constructor( | ||
readonly id: string, | ||
readonly status: SignUpStatus, | ||
readonly requiredFields: string[], | ||
readonly optionalFields: string[], | ||
readonly missingFields: string[], | ||
readonly unverifiedFields: string[], | ||
readonly verifications: SignUpAttemptVerifications | null, | ||
readonly username: string | null, | ||
readonly emailAddress: string | null, | ||
readonly phoneNumber: string | null, | ||
readonly web3Wallet: string | null, | ||
readonly passwordEnabled: boolean, | ||
readonly firstName: string | null, | ||
readonly lastName: string | null, | ||
readonly customAction: boolean, | ||
readonly externalId: string | null, | ||
readonly createdSessionId: string | null, | ||
readonly createdUserId: string | null, | ||
readonly abandonAt: number | null, | ||
readonly legalAcceptedAt: number | null, | ||
readonly publicMetadata?: Record<string, unknown> | null, | ||
readonly unsafeMetadata?: Record<string, unknown> | null, | ||
) {} | ||
|
||
static fromJSON(data: SignUpJSON): SignUpAttempt { | ||
return new SignUpAttempt( | ||
data.id, | ||
data.status, | ||
data.required_fields, | ||
data.optional_fields, | ||
data.missing_fields, | ||
data.unverified_fields, | ||
data.verifications ? SignUpAttemptVerifications.fromJSON(data.verifications) : null, | ||
data.username, | ||
data.email_address, | ||
data.phone_number, | ||
data.web3_wallet, | ||
data.password_enabled, | ||
data.first_name, | ||
data.last_name, | ||
data.custom_action, | ||
data.external_id, | ||
data.created_session_id, | ||
data.created_user_id, | ||
data.abandon_at, | ||
data.legal_accepted_at, | ||
data.public_metadata, | ||
data.unsafe_metadata, | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,10 @@ export type { | |
OrganizationInvitationStatus, | ||
OrganizationMembershipRole, | ||
SignInStatus, | ||
SignUpStatus, | ||
} from './Enums'; | ||
|
||
export type { SignUpStatus } from '@clerk/types'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this re-export needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jacekradko In theory, no, but I added it to keep consistency with the code above:
|
||
|
||
export * from './ExternalAccount'; | ||
export * from './IdentificationLink'; | ||
export * from './Instance'; | ||
|
@@ -39,6 +40,7 @@ export * from './ProxyCheck'; | |
export * from './RedirectUrl'; | ||
export * from './Session'; | ||
export * from './SignInTokens'; | ||
export * from './SignUpAttempt'; | ||
export * from './SMSMessage'; | ||
export * from './Token'; | ||
export * from './User'; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.