@@ -2,11 +2,13 @@ import { Poller } from '@clerk/shared/poller';
22import type {
33 AttemptEmailAddressVerificationParams ,
44 CreateEmailLinkFlowReturn ,
5+ CreateEnterpriseConnectionLinkFlowReturn ,
56 EmailAddressJSON ,
67 EmailAddressResource ,
78 IdentificationLinkResource ,
89 PrepareEmailAddressVerificationParams ,
910 StartEmailLinkFlowParams ,
11+ StartEnterpriseConnectionLinkFlowParams ,
1012 VerificationResource ,
1113} from '@clerk/types' ;
1214
@@ -16,6 +18,7 @@ import { BaseResource, IdentificationLink, Verification } from './internal';
1618export class EmailAddress extends BaseResource implements EmailAddressResource {
1719 id ! : string ;
1820 emailAddress = '' ;
21+ matchesEnterpriseConnection = false ;
1922 linkedTo : IdentificationLinkResource [ ] = [ ] ;
2023 verification ! : VerificationResource ;
2124
@@ -77,6 +80,45 @@ export class EmailAddress extends BaseResource implements EmailAddressResource {
7780 return { startEmailLinkFlow, cancelEmailLinkFlow : stop } ;
7881 } ;
7982
83+ createEnterpriseConnectionLinkFlow = ( ) : CreateEnterpriseConnectionLinkFlowReturn <
84+ StartEnterpriseConnectionLinkFlowParams ,
85+ EmailAddressResource
86+ > => {
87+ const { run, stop } = Poller ( ) ;
88+
89+ const startEnterpriseConnectionLinkFlow = async ( {
90+ redirectUrl,
91+ } : StartEnterpriseConnectionLinkFlowParams ) : Promise < EmailAddressResource > => {
92+ if ( ! this . id ) {
93+ clerkVerifyEmailAddressCalledBeforeCreate ( 'SignUp' ) ;
94+ }
95+ const response = await this . prepareVerification ( {
96+ strategy : 'saml' ,
97+ redirectUrl : redirectUrl ,
98+ } ) ;
99+ if ( ! response . verification . externalVerificationRedirectURL ) {
100+ throw Error ( 'Unexpected: External verification redirect URL is missing' ) ;
101+ }
102+ window . open ( response . verification . externalVerificationRedirectURL , '_blank' ) ;
103+ return new Promise ( ( resolve , reject ) => {
104+ void run ( ( ) => {
105+ return this . reload ( )
106+ . then ( res => {
107+ if ( res . verification . status === 'verified' ) {
108+ stop ( ) ;
109+ resolve ( res ) ;
110+ }
111+ } )
112+ . catch ( err => {
113+ stop ( ) ;
114+ reject ( err ) ;
115+ } ) ;
116+ } ) ;
117+ } ) ;
118+ } ;
119+ return { startEnterpriseConnectionLinkFlow, cancelEnterpriseConnectionLinkFlow : stop } ;
120+ } ;
121+
80122 destroy = ( ) : Promise < void > => this . _baseDelete ( ) ;
81123
82124 toString = ( ) : string => this . emailAddress ;
@@ -89,6 +131,7 @@ export class EmailAddress extends BaseResource implements EmailAddressResource {
89131 this . id = data . id ;
90132 this . emailAddress = data . email_address ;
91133 this . verification = new Verification ( data . verification ) ;
134+ this . matchesEnterpriseConnection = data . matches_enterprise_connection ;
92135 this . linkedTo = ( data . linked_to || [ ] ) . map ( link => new IdentificationLink ( link ) ) ;
93136 return this ;
94137 }
0 commit comments