Skip to content

Fix database.useEmulator typing. #4870

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 3 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curly-lamps-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"firebase": patch
---

Fix database.useEmulator typing.
161 changes: 86 additions & 75 deletions packages/firebase/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FirebaseIdToken>;

/**
* Retrieves a Firebase {@link firebase.app.App app} instance.
*
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<FirebaseIdToken>;
export type EmulatorMockTokenOptions = firebase.EmulatorMockTokenOptions;
}

export default firebase;
Expand Down