diff --git a/.changeset/curly-lamps-rescue.md b/.changeset/curly-lamps-rescue.md new file mode 100644 index 00000000000..4f7f68e8d2f --- /dev/null +++ b/.changeset/curly-lamps-rescue.md @@ -0,0 +1,5 @@ +--- +"firebase": patch +--- + +Fix database.useEmulator typing. diff --git a/packages/firebase/index.d.ts b/packages/firebase/index.d.ts index 28f51f54314..ec0ac79c432 100644 --- a/packages/firebase/index.d.ts +++ b/packages/firebase/index.d.ts @@ -1006,6 +1006,81 @@ declare namespace firebase { uid: string; } + type FirebaseSignInProvider = + | 'custom' + | 'email' + | 'password' + | 'phone' + | 'anonymous' + | 'google.com' + | 'facebook.com' + | 'github.com' + | 'twitter.com' + | 'microsoft.com' + | 'apple.com'; + + interface FirebaseIdToken { + /** Always set to https://securetoken.google.com/PROJECT_ID */ + iss: string; + + /** Always set to PROJECT_ID */ + aud: string; + + /** The user's unique id */ + sub: string; + + /** The token issue time, in seconds since epoch */ + iat: number; + + /** The token expiry time, normally 'iat' + 3600 */ + exp: number; + + /** The user's unique id, must be equal to 'sub' */ + user_id: string; + + /** The time the user authenticated, normally 'iat' */ + auth_time: number; + + /** The sign in provider, only set when the provider is 'anonymous' */ + provider_id?: 'anonymous'; + + /** The user's primary email */ + email?: string; + + /** The user's email verification status */ + email_verified?: boolean; + + /** The user's primary phone number */ + phone_number?: string; + + /** The user's display name */ + name?: string; + + /** The user's profile photo URL */ + picture?: string; + + /** Information on all identities linked to this user */ + firebase: { + /** The primary sign-in provider */ + sign_in_provider: FirebaseSignInProvider; + + /** A map of providers to the user's list of unique identifiers from each provider */ + identities?: { [provider in FirebaseSignInProvider]?: string[] }; + }; + + /** Custom claims set by the developer */ + [claim: string]: unknown; + + // NO LONGER SUPPORTED. Use "sub" instead. (Not a jsdoc comment to avoid generating docs.) + uid?: never; + } + + export type EmulatorMockTokenOptions = ( + | { user_id: string } + | { sub: string } + ) & + Partial; + /** * Retrieves a Firebase {@link firebase.app.App app} instance. * @@ -5711,8 +5786,15 @@ declare namespace firebase.database { * * @param host the emulator host (ex: localhost) * @param port the emulator port (ex: 8080) + * @param options.mockUserToken the mock auth token to use for unit testing Security Rules */ - useEmulator(host: string, port: number): void; + useEmulator( + host: string, + port: number, + options?: { + mockUserToken?: EmulatorMockTokenOptions; + } + ): void; /** * Disconnects from the server (all Database operations will be completed * offline). @@ -7054,6 +7136,8 @@ declare namespace firebase.database { logger?: boolean | ((a: string) => any), persistent?: boolean ): any; + + export type EmulatorMockTokenOptions = firebase.EmulatorMockTokenOptions; } declare namespace firebase.database.ServerValue { @@ -9985,80 +10069,7 @@ declare namespace firebase.firestore { stack?: string; } - type FirebaseSignInProvider = - | 'custom' - | 'email' - | 'password' - | 'phone' - | 'anonymous' - | 'google.com' - | 'facebook.com' - | 'github.com' - | 'twitter.com' - | 'microsoft.com' - | 'apple.com'; - - interface FirebaseIdToken { - /** Always set to https://securetoken.google.com/PROJECT_ID */ - iss: string; - - /** Always set to PROJECT_ID */ - aud: string; - - /** The user's unique id */ - sub: string; - - /** The token issue time, in seconds since epoch */ - iat: number; - - /** The token expiry time, normally 'iat' + 3600 */ - exp: number; - - /** The user's unique id, must be equal to 'sub' */ - user_id: string; - - /** The time the user authenticated, normally 'iat' */ - auth_time: number; - - /** The sign in provider, only set when the provider is 'anonymous' */ - provider_id?: 'anonymous'; - - /** The user's primary email */ - email?: string; - - /** The user's email verification status */ - email_verified?: boolean; - - /** The user's primary phone number */ - phone_number?: string; - - /** The user's display name */ - name?: string; - - /** The user's profile photo URL */ - picture?: string; - - /** Information on all identities linked to this user */ - firebase: { - /** The primary sign-in provider */ - sign_in_provider: FirebaseSignInProvider; - - /** A map of providers to the user's list of unique identifiers from each provider */ - identities?: { [provider in FirebaseSignInProvider]?: string[] }; - }; - - /** Custom claims set by the developer */ - [claim: string]: unknown; - - // NO LONGER SUPPORTED. Use "sub" instead. (Not a jsdoc comment to avoid generating docs.) - uid?: never; - } - - export type EmulatorMockTokenOptions = ( - | { user_id: string } - | { sub: string } - ) & - Partial; + export type EmulatorMockTokenOptions = firebase.EmulatorMockTokenOptions; } export default firebase;