@@ -34,7 +34,7 @@ import {
3434 AuthProviderConfig , AuthProviderConfigFilter , ListProviderConfigResults , UpdateAuthProviderRequest ,
3535 SAMLConfig , OIDCConfig , OIDCConfigServerResponse , SAMLConfigServerResponse ,
3636} from './auth-config' ;
37- import { Tenant , TenantOptions , ListTenantsResult , TenantServerResponse } from './tenant' ;
37+ import { TenantManager } from './tenant-manager ' ;
3838
3939
4040/**
@@ -722,7 +722,7 @@ export class TenantAwareAuth extends BaseAuth<TenantAwareAuthRequestHandler> {
722722 */
723723export class Auth extends BaseAuth < AuthRequestHandler > implements FirebaseServiceInterface {
724724 public INTERNAL : AuthInternals = new AuthInternals ( ) ;
725- private readonly tenantsMap : { [ key : string ] : TenantAwareAuth } ;
725+ private readonly tenantManager_ : TenantManager ;
726726 private readonly app_ : FirebaseApp ;
727727
728728 /**
@@ -751,7 +751,7 @@ export class Auth extends BaseAuth<AuthRequestHandler> implements FirebaseServic
751751 new AuthRequestHandler ( app ) ,
752752 cryptoSignerFromApp ( app ) ) ;
753753 this . app_ = app ;
754- this . tenantsMap = { } ;
754+ this . tenantManager_ = new TenantManager ( app ) ;
755755 }
756756
757757 /**
@@ -763,107 +763,8 @@ export class Auth extends BaseAuth<AuthRequestHandler> implements FirebaseServic
763763 return this . app_ ;
764764 }
765765
766- /**
767- * Returns a TenantAwareAuth instance for the corresponding tenant ID.
768- *
769- * @param {string } tenantId The tenant ID whose TenantAwareAuth is to be returned.
770- * @return {TenantAwareAuth } The corresponding TenantAwareAuth instance.
771- */
772- public forTenant ( tenantId : string ) : TenantAwareAuth {
773- if ( ! validator . isNonEmptyString ( tenantId ) ) {
774- throw new FirebaseAuthError ( AuthClientErrorCode . INVALID_TENANT_ID ) ;
775- }
776- if ( typeof this . tenantsMap [ tenantId ] === 'undefined' ) {
777- this . tenantsMap [ tenantId ] = new TenantAwareAuth ( this . app , tenantId ) ;
778- }
779- return this . tenantsMap [ tenantId ] ;
780- }
781-
782- /**
783- * Looks up the tenant identified by the provided tenant ID and returns a promise that is
784- * fulfilled with the corresponding tenant if it is found.
785- *
786- * @param {string } tenantId The tenant ID of the tenant to look up.
787- * @return {Promise<Tenant> } A promise that resolves with the corresponding tenant.
788- */
789- public getTenant ( tenantId : string ) : Promise < Tenant > {
790- return this . authRequestHandler . getTenant ( tenantId )
791- . then ( ( response : TenantServerResponse ) => {
792- return new Tenant ( response ) ;
793- } ) ;
794- }
795-
796- /**
797- * Exports a batch of tenant accounts. Batch size is determined by the maxResults argument.
798- * Starting point of the batch is determined by the pageToken argument.
799- *
800- * @param {number= } maxResults The page size, 1000 if undefined. This is also the maximum
801- * allowed limit.
802- * @param {string= } pageToken The next page token. If not specified, returns users starting
803- * without any offset.
804- * @return {Promise<{users: Tenant[], pageToken?: string}> } A promise that resolves with
805- * the current batch of downloaded tenants and the next page token. For the last page, an
806- * empty list of tenants and no page token are returned.
807- */
808- public listTenants (
809- maxResults ?: number ,
810- pageToken ?: string ) : Promise < ListTenantsResult > {
811- return this . authRequestHandler . listTenants ( maxResults , pageToken )
812- . then ( ( response : { tenants : TenantServerResponse [ ] , nextPageToken ?: string } ) => {
813- // List of tenants to return.
814- const tenants : Tenant [ ] = [ ] ;
815- // Convert each user response to a Tenant.
816- response . tenants . forEach ( ( tenantResponse : TenantServerResponse ) => {
817- tenants . push ( new Tenant ( tenantResponse ) ) ;
818- } ) ;
819- // Return list of tenants and the next page token if available.
820- const result = {
821- tenants,
822- pageToken : response . nextPageToken ,
823- } ;
824- // Delete result.pageToken if undefined.
825- if ( typeof result . pageToken === 'undefined' ) {
826- delete result . pageToken ;
827- }
828- return result ;
829- } ) ;
830- }
831-
832- /**
833- * Deletes the tenant identified by the provided tenant ID and returns a promise that is
834- * fulfilled when the tenant is found and successfully deleted.
835- *
836- * @param {string } tenantId The tenant ID of the tenant to delete.
837- * @return {Promise<void> } A promise that resolves when the tenant is successfully deleted.
838- */
839- public deleteTenant ( tenantId : string ) : Promise < void > {
840- return this . authRequestHandler . deleteTenant ( tenantId ) ;
841- }
842-
843- /**
844- * Creates a new tenant with the properties provided.
845- *
846- * @param {TenantOptions } tenantOptions The properties to set on the new tenant to be created.
847- * @return {Promise<Tenant> } A promise that resolves with the newly created tenant.
848- */
849- public createTenant ( tenantOptions : TenantOptions ) : Promise < Tenant > {
850- return this . authRequestHandler . createTenant ( tenantOptions )
851- . then ( ( response : TenantServerResponse ) => {
852- return new Tenant ( response ) ;
853- } ) ;
854- }
855-
856- /**
857- * Updates an existing tenant identified by the tenant ID with the properties provided.
858- *
859- * @param {string } tenantId The tenant identifier of the tenant to update.
860- * @param {TenantOptions } tenantOptions The properties to update on the existing tenant.
861- * @return {Promise<Tenant> } A promise that resolves with the modified tenant.
862- */
863- public updateTenant ( tenantId : string , tenantOptions : TenantOptions ) : Promise < Tenant > {
864- return this . authRequestHandler . updateTenant ( tenantId , tenantOptions )
865- . then ( ( response : TenantServerResponse ) => {
866- return new Tenant ( response ) ;
867- } ) ;
766+ /** @return The current Auth instance's tenant manager. */
767+ public tenantManager ( ) : TenantManager {
768+ return this . tenantManager_ ;
868769 }
869770}
0 commit comments