Skip to content

Commit

Permalink
Fixing up for merge
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubox76 committed Sep 26, 2022
1 parent 777c206 commit e09043c
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 63 deletions.
11 changes: 4 additions & 7 deletions common/api-review/util.api.md
Expand Up @@ -4,11 +4,6 @@
```ts

// Warning: (ae-missing-release-tag) "__PRIVATE_getDefaultEmulatorHost" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const __PRIVATE_getDefaultEmulatorHost: (name: string) => string | undefined;

// Warning: (ae-missing-release-tag) "areCookiesEnabled" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
Expand Down Expand Up @@ -203,17 +198,19 @@ export type FirebaseSignInProvider = 'custom' | 'email' | 'password' | 'phone' |
// Warning: (ae-missing-release-tag) "getDefaultAppConfig" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const getDefaultAppConfig: () => Object | undefined;
export const getDefaultAppConfig: () => Record<string, string> | undefined;

// Warning: (ae-missing-release-tag) "getDefaultEmulatorHost" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const getDefaultEmulatorHost: (name: string) => string | undefined;

// Warning: (ae-forgotten-export) The symbol "ExperimentalKey" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "FirebaseDefaults" needs to be exported by the entry point index.d.ts
// Warning: (ae-missing-release-tag) "getExperimentalSetting" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const getExperimentalSetting: (name: string) => any;
export const getExperimentalSetting: <T extends ExperimentalKey>(name: T) => FirebaseDefaults[`_${T}`];

// Warning: (ae-missing-release-tag) "getGlobal" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
Expand Down
2 changes: 1 addition & 1 deletion config/.eslintrc.js
Expand Up @@ -129,7 +129,7 @@ module.exports = {
{
// Check dependencies from both local package.json
// and from root package.json.
'packageDir': [path.join(__dirname, '../'), './'],
'packageDir': [context.getFilename(), path.join(__dirname, '../'), './'],
'devDependencies': [
'**/*.test.ts',
'**/test/**/*.ts',
Expand Down
10 changes: 7 additions & 3 deletions packages/app/src/api.ts
Expand Up @@ -115,7 +115,7 @@ export function initializeApp(
*
* @public
*/
export function initializeApp(): FirebaseApp;
export function initializeApp(): FirebaseApp;
export function initializeApp(
_options?: FirebaseOptions,
rawConfig = {}
Expand All @@ -142,7 +142,9 @@ export function initializeApp(

options ||= getDefaultAppConfig();

if (!options) throw 'Need to provide options, when not being deployed to hosting via source.';
if (!options) {
throw ERROR_FACTORY.create(AppError.NO_OPTIONS);
}

const existingApp = _apps.get(name) as FirebaseAppImpl;
if (existingApp) {
Expand Down Expand Up @@ -200,7 +202,9 @@ export function initializeApp(
*/
export function getApp(name: string = DEFAULT_ENTRY_NAME): FirebaseApp {
const app = _apps.get(name);
if (!app && name === DEFAULT_ENTRY_NAME) return initializeApp();
if (!app && name === DEFAULT_ENTRY_NAME) {
return initializeApp();
}
if (!app) {
throw ERROR_FACTORY.create(AppError.NO_APP, { appName: name });
}
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/errors.ts
Expand Up @@ -22,6 +22,7 @@ export const enum AppError {
BAD_APP_NAME = 'bad-app-name',
DUPLICATE_APP = 'duplicate-app',
APP_DELETED = 'app-deleted',
NO_OPTIONS = 'no-options',
INVALID_APP_ARGUMENT = 'invalid-app-argument',
INVALID_LOG_ARGUMENT = 'invalid-log-argument',
IDB_OPEN = 'idb-open',
Expand All @@ -38,6 +39,7 @@ const ERRORS: ErrorMap<AppError> = {
[AppError.DUPLICATE_APP]:
"Firebase App named '{$appName}' already exists with different options or config",
[AppError.APP_DELETED]: "Firebase App named '{$appName}' already deleted",
[AppError.NO_OPTIONS]: "Need to provide options, when not being deployed to hosting via source.",
[AppError.INVALID_APP_ARGUMENT]:
'firebase.{$appName}() takes either no argument or a ' +
'Firebase App instance.',
Expand Down
5 changes: 3 additions & 2 deletions packages/auth/src/platform_browser/index.ts
Expand Up @@ -27,14 +27,15 @@ import { browserPopupRedirectResolver } from './popup_redirect';
import { Auth, User } from '../model/public_types';
import { getDefaultEmulatorHost, getExperimentalSetting } from '@firebase/util';

const ID_TOKEN_MAX_AGE = 5 * 60;
const DEFAULT_ID_TOKEN_MAX_AGE = 5 * 60;
const authIdTokenMaxAge = getExperimentalSetting('authIdTokenMaxAge') || DEFAULT_ID_TOKEN_MAX_AGE;

let lastPostedIdToken: string|undefined|null = null;

const mintCookieFactory = (url:string) => async (user: User|null) => {
const idTokenResult = user && await user.getIdTokenResult();
const idTokenAge = idTokenResult && (new Date().getTime() - Date.parse(idTokenResult.issuedAtTime)) / 1_000;
if (idTokenAge && idTokenAge > ID_TOKEN_MAX_AGE) return;
if (idTokenAge && idTokenAge > authIdTokenMaxAge) return;
// Specifically trip null => undefined when logged out, to delete any existing cookie
const idToken = idTokenResult?.token;
if (lastPostedIdToken === idToken) return;
Expand Down
10 changes: 7 additions & 3 deletions packages/database/src/api/Database.ts
Expand Up @@ -27,7 +27,8 @@ import { Provider } from '@firebase/component';
import {
getModularInstance,
createMockUserToken,
EmulatorMockTokenOptions
EmulatorMockTokenOptions,
getDefaultEmulatorHost
} from '@firebase/util';

import { AppCheckTokenProvider } from '../core/AppCheckTokenProvider';
Expand All @@ -53,7 +54,10 @@ import { WebSocketConnection } from '../realtime/WebSocketConnection';

import { ReferenceImpl } from './Reference_impl';

export { EmulatorMockTokenOptions, getDefaultEmulatorHost } from '@firebase/util';
export {
EmulatorMockTokenOptions,
getDefaultEmulatorHost
} from '@firebase/util';
/**
* This variable is also defined in the firebase Node.js Admin SDK. Before
* modifying this definition, consult the definition in:
Expand Down Expand Up @@ -321,7 +325,7 @@ export function getDatabase(
}) as Database;
const databaseEmulatorHost = getDefaultEmulatorHost('database');
if (databaseEmulatorHost) {
const [ host, port ] = databaseEmulatorHost.split(':');
const [host, port] = databaseEmulatorHost.split(':');
connectDatabaseEmulator(db, host, parseInt(port, 10));
}
return db;
Expand Down
25 changes: 13 additions & 12 deletions packages/firestore/src/api/database.ts
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import {
_getProvider,
_removeServiceInstance,
Expand Down Expand Up @@ -43,7 +42,10 @@ import {
setOnlineComponentProvider
} from '../core/firestore_client';
import { makeDatabaseInfo } from '../lite-api/components';
import { Firestore as LiteFirestore } from '../lite-api/database';
import {
Firestore as LiteFirestore,
connectFirestoreEmulator
} from '../lite-api/database';
import { Query } from '../lite-api/reference';
import {
indexedDbClearPersistence,
Expand All @@ -66,7 +68,6 @@ export {
connectFirestoreEmulator,
EmulatorMockTokenOptions
} from '../lite-api/database';
import { connectFirestoreEmulator } from '../lite-api/database';

declare module '@firebase/component' {
interface NameServiceMapping {
Expand Down Expand Up @@ -153,9 +154,9 @@ export function initializeFirestore(
throw new FirestoreError(
Code.FAILED_PRECONDITION,
'initializeFirestore() has already been called with ' +
'different options. To avoid this error, call initializeFirestore() with the ' +
'same options as when it was originally called, or call getFirestore() to return the' +
' already initialized instance.'
'different options. To avoid this error, call initializeFirestore() with the ' +
'same options as when it was originally called, or call getFirestore() to return the' +
' already initialized instance.'
);
}
}
Expand Down Expand Up @@ -188,7 +189,7 @@ export function getFirestore(app: FirebaseApp = getApp()): Firestore {
if (!db._initialized) {
const firestoreEmulatorHost = getDefaultEmulatorHost('firestore');
if (firestoreEmulatorHost) {
const [ host, port ] = firestoreEmulatorHost.split(':');
const [host, port] = firestoreEmulatorHost.split(':');
connectFirestoreEmulator(db, host, parseInt(port, 10));
}
}
Expand Down Expand Up @@ -344,8 +345,8 @@ function setPersistenceProviders(
}
logWarn(
'Error enabling offline persistence. Falling back to ' +
'persistence disabled: ' +
error
'persistence disabled: ' +
error
);
persistenceResult.reject(error);
}
Expand Down Expand Up @@ -418,7 +419,7 @@ export function clearIndexedDbPersistence(firestore: Firestore): Promise<void> {
throw new FirestoreError(
Code.FAILED_PRECONDITION,
'Persistence can only be cleared before a Firestore instance is ' +
'initialized or after it is terminated.'
'initialized or after it is terminated.'
);
}

Expand Down Expand Up @@ -570,8 +571,8 @@ function verifyNotInitialized(firestore: Firestore): void {
throw new FirestoreError(
Code.FAILED_PRECONDITION,
'Firestore has already been started and persistence can no longer be ' +
'enabled. You can only enable persistence before calling any other ' +
'methods on a Firestore object.'
'enabled. You can only enable persistence before calling any other ' +
'methods on a Firestore object.'
);
}
}
11 changes: 8 additions & 3 deletions packages/firestore/src/lite-api/database.ts
Expand Up @@ -22,7 +22,11 @@ import {
FirebaseApp,
getApp
} from '@firebase/app';
import { createMockUserToken, EmulatorMockTokenOptions, getDefaultEmulatorHost } from '@firebase/util';
import {
createMockUserToken,
EmulatorMockTokenOptions,
getDefaultEmulatorHost
} from '@firebase/util';

import {
CredentialsProvider,
Expand All @@ -44,6 +48,8 @@ import {
FirestoreSettings
} from './settings';

export { EmulatorMockTokenOptions } from '@firebase/util';

declare module '@firebase/component' {
interface NameServiceMapping {
'firestore/lite': Firestore;
Expand Down Expand Up @@ -215,14 +221,13 @@ export function getFirestore(app: FirebaseApp = getApp()): Firestore {
if (!db._initialized) {
const firestoreEmulatorHost = getDefaultEmulatorHost('firestore');
if (firestoreEmulatorHost) {
const [ host, port ] = firestoreEmulatorHost.split(':');
const [host, port] = firestoreEmulatorHost.split(':');
connectFirestoreEmulator(db, host, parseInt(port, 10));
}
}
return db;
}

export { EmulatorMockTokenOptions } from '@firebase/util';
/**
* Modify this instance to communicate with the Cloud Firestore emulator.
*
Expand Down
3 changes: 2 additions & 1 deletion packages/functions/src/api.ts
Expand Up @@ -53,7 +53,8 @@ export function getFunctions(
});
const functionsEmulatorHost = getDefaultEmulatorHost('functions');
if (functionsEmulatorHost) {
const [ host, port ] = functionsEmulatorHost.split(':');
const [host, port] = functionsEmulatorHost.split(':');
// eslint-disable-next-line no-restricted-globals
connectFunctionsEmulator(functionsInstance, host, parseInt(port, 10));
}
return functionsInstance;
Expand Down
10 changes: 7 additions & 3 deletions packages/storage/src/api.ts
Expand Up @@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// eslint-disable-next-line import/no-extraneous-dependencies
import { _getProvider, FirebaseApp, getApp } from '@firebase/app';

import {
Expand Down Expand Up @@ -51,7 +50,11 @@ import {
getBytesInternal
} from './reference';
import { STORAGE_TYPE } from './constants';
import { EmulatorMockTokenOptions, getModularInstance, getDefaultEmulatorHost } from '@firebase/util';
import {
EmulatorMockTokenOptions,
getModularInstance,
getDefaultEmulatorHost
} from '@firebase/util';
import { StringFormat } from './implementation/string';

export { EmulatorMockTokenOptions } from '@firebase/util';
Expand Down Expand Up @@ -333,7 +336,8 @@ export function getStorage(
});
const storageEmulatorHost = getDefaultEmulatorHost('storage');
if (storageEmulatorHost) {
const [ host, port ] = storageEmulatorHost.split(':');
const [host, port] = storageEmulatorHost.split(':');
// eslint-disable-next-line no-restricted-globals
connectStorageEmulator(storageInstance, host, parseInt(port, 10));
}
return storageInstance;
Expand Down

0 comments on commit e09043c

Please sign in to comment.