@@ -88,6 +88,25 @@ interface UpdateUserAuthParams {
88
88
deleteIds ?: string [ ] ; // API key IDs to delete
89
89
} ;
90
90
}
91
+
92
+ interface DeleteUserAuthParams {
93
+ userId : string ; // Unique identifier of the user
94
+ phoneNumber ?: boolean ; // true to remove the phone number
95
+ email ?: boolean ; // true to remove the email
96
+ authenticatorIds ?: string [ ] ; // Array of authenticator IDs to remove
97
+ oauthProviderIds ?: string [ ] ; // Array of OAuth provider IDs to remove
98
+ apiKeyIds ?: string [ ] ; // Array of API key IDs to remove
99
+ }
100
+
101
+ interface AddUserAuthParams {
102
+ userId : string ; // Unique identifier of the user
103
+ phoneNumber ?: string ; // New phone number to set
104
+ email ?: string ; // New email address to set
105
+ authenticators ?: Authenticator [ ] ; // Array of authenticator objects to add
106
+ oauthProviders ?: OauthProvider [ ] ; // Array of OAuth provider objects to add
107
+ apiKeys ?: ApiKey [ ] ; // Array of API key objects to add
108
+ }
109
+
91
110
export class TurnkeyBrowserSDK {
92
111
config : TurnkeySDKBrowserConfig ;
93
112
@@ -397,43 +416,45 @@ export class TurnkeyBrowserClient extends TurnkeySDKClientBase {
397
416
* All removal operations are executed in parallel if multiple
398
417
* parameters are provided.
399
418
*
400
- * @param userId - Unique identifier of the user
401
- * @param phoneNumber - If true, removes the user's phone number
402
- * @param email - If true, removes the user's email
403
- * @param authenticatorIds - Array of authenticator IDs to remove
404
- * @param oauthProviderIds - Array of OAuth provider IDs to remove
405
- * @param apiKeyIds - Array of API key IDs to remove
419
+ * @param params - A structured object containing all the removal parameters
420
+ * @param params.userId - Unique identifier of the user
421
+ * @param params.phoneNumber - true to remove the phone number
422
+ * @param params.email - true to remove the email
423
+ * @param params.authenticatorIds - Array of authenticator IDs to remove
424
+ * @param params.oauthProviderIds - Array of OAuth provider IDs to remove
425
+ * @param params.apiKeyIds - Array of API key IDs to remove
406
426
* @returns A promise that resolves to an array of results from each removal operation
407
427
*/
408
- deleteUserAuth = async (
409
- userId : string ,
410
- phoneNumber ?: boolean ,
411
- email ?: boolean ,
412
- authenticatorIds ?: string [ ] ,
413
- oauthProviderIds ?: string [ ] ,
414
- apiKeyIds ?: string [ ] ,
415
- ) : Promise < any [ ] > => {
428
+ deleteUserAuth = async ( params : DeleteUserAuthParams ) : Promise < any [ ] > => {
416
429
try {
430
+ const {
431
+ userId,
432
+ phoneNumber,
433
+ email,
434
+ authenticatorIds,
435
+ oauthProviderIds,
436
+ apiKeyIds,
437
+ } = params ;
417
438
const promises : Promise < any > [ ] = [ ] ;
418
439
419
440
if ( phoneNumber ) {
420
- promises . push ( this . updateUser ( { userId, userPhoneNumber : "" } ) ) ;
441
+ promises . push (
442
+ this . updateUser ( { userId, userPhoneNumber : "" , userTagIds : [ ] } ) ,
443
+ ) ;
421
444
}
422
-
423
445
if ( email ) {
424
- promises . push ( this . updateUser ( { userId, userEmail : "" } ) ) ;
446
+ promises . push (
447
+ this . updateUser ( { userId, userEmail : "" , userTagIds : [ ] } ) ,
448
+ ) ;
425
449
}
426
-
427
450
if ( authenticatorIds && authenticatorIds . length > 0 ) {
428
451
promises . push ( this . deleteAuthenticators ( { userId, authenticatorIds } ) ) ;
429
452
}
430
-
431
453
if ( oauthProviderIds && oauthProviderIds . length > 0 ) {
432
454
promises . push (
433
455
this . deleteOauthProviders ( { userId, providerIds : oauthProviderIds } ) ,
434
456
) ;
435
457
}
436
-
437
458
if ( apiKeyIds && apiKeyIds . length > 0 ) {
438
459
promises . push ( this . deleteApiKeys ( { userId, apiKeyIds } ) ) ;
439
460
}
@@ -459,43 +480,47 @@ export class TurnkeyBrowserClient extends TurnkeySDKClientBase {
459
480
* All additions/updates are executed in parallel if multiple
460
481
* parameters are provided.
461
482
*
462
- * @param userId - Unique identifier of the user
463
- * @param phoneNumber - New phone number for the user
464
- * @param email - New email address for the user
465
- * @param authenticators - Array of authenticator objects to create
466
- * @param oauthProviders - Array of OAuth provider objects to create
467
- * @param apiKeys - Array of API key objects to create
483
+ * @param params - A structured object containing all the addition/update parameters
484
+ * @param params.userId - Unique identifier of the user
485
+ * @param params.phoneNumber - New phone number for the user
486
+ * @param params.email - New email address for the user
487
+ * @param params.authenticators - Array of authenticator objects to create
488
+ * @param params.oauthProviders - Array of OAuth provider objects to create
489
+ * @param params.apiKeys - Array of API key objects to create
468
490
* @returns A promise that resolves to an array of results from each addition or update
469
491
*/
470
- addUserAuth = async (
471
- userId : string ,
472
- phoneNumber ?: string ,
473
- email ?: string ,
474
- authenticators ?: Authenticator [ ] ,
475
- oauthProviders ?: OauthProvider [ ] ,
476
- apiKeys ?: ApiKey [ ] ,
477
- ) : Promise < any [ ] > => {
492
+ addUserAuth = async ( params : AddUserAuthParams ) : Promise < any [ ] > => {
478
493
try {
494
+ const {
495
+ userId,
496
+ phoneNumber,
497
+ email,
498
+ authenticators,
499
+ oauthProviders,
500
+ apiKeys,
501
+ } = params ;
479
502
const promises : Promise < any > [ ] = [ ] ;
480
503
481
504
if ( phoneNumber ) {
482
505
promises . push (
483
- this . updateUser ( { userId, userPhoneNumber : phoneNumber } ) ,
506
+ this . updateUser ( {
507
+ userId,
508
+ userPhoneNumber : phoneNumber ,
509
+ userTagIds : [ ] ,
510
+ } ) ,
484
511
) ;
485
512
}
486
-
487
513
if ( email ) {
488
- promises . push ( this . updateUser ( { userId, userEmail : email } ) ) ;
514
+ promises . push (
515
+ this . updateUser ( { userId, userEmail : email , userTagIds : [ ] } ) ,
516
+ ) ;
489
517
}
490
-
491
518
if ( authenticators && authenticators . length > 0 ) {
492
519
promises . push ( this . createAuthenticators ( { userId, authenticators } ) ) ;
493
520
}
494
-
495
521
if ( oauthProviders && oauthProviders . length > 0 ) {
496
522
promises . push ( this . createOauthProviders ( { userId, oauthProviders } ) ) ;
497
523
}
498
-
499
524
if ( apiKeys && apiKeys . length > 0 ) {
500
525
promises . push ( this . createApiKeys ( { userId, apiKeys } ) ) ;
501
526
}
@@ -551,7 +576,9 @@ export class TurnkeyBrowserClient extends TurnkeySDKClientBase {
551
576
userUpdates . userEmail = email === null ? "" : email ;
552
577
}
553
578
if ( Object . keys ( userUpdates ) . length > 0 ) {
554
- promises . push ( this . updateUser ( { userId, ...userUpdates } ) ) ;
579
+ promises . push (
580
+ this . updateUser ( { userId, ...userUpdates , userTagIds : [ ] } ) ,
581
+ ) ;
555
582
}
556
583
557
584
// Handle authenticators
0 commit comments