Skip to content

Further refactoring of auth types. Add public exports to src/index.ts #3078

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 19, 2020
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
4 changes: 0 additions & 4 deletions packages-exp/auth-exp/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,3 @@
* implementation that mandates having a separate entrypoint. Otherwise you can
* just use index.ts
*/

import { testFxn } from './src';

testFxn();
20 changes: 0 additions & 20 deletions packages-exp/auth-exp/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages-exp/auth-exp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"license": "Apache-2.0",
"devDependencies": {
"@rollup/plugin-strip": "^1.3.2",
"@firebase/app-exp": "0.x",
"rollup": "1.32.1",
"rollup-plugin-json": "4.0.0",
"rollup-plugin-replace": "2.2.0",
Expand Down
4 changes: 2 additions & 2 deletions packages-exp/auth-exp/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const es5Builds = [
* Browser Builds
*/
{
input: 'index.ts',
input: 'src/index.ts',
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
Expand Down Expand Up @@ -84,7 +84,7 @@ const es2017Builds = [
* Browser Builds
*/
{
input: 'index.ts',
input: 'src/index.ts',
output: {
file: pkg.esm2017,
format: 'es',
Expand Down
6 changes: 4 additions & 2 deletions packages-exp/auth-exp/src/core/action_code_url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
* limitations under the License.
*/

import { AuthErrorCode, AUTH_ERROR_FACTORY } from './errors';
import * as externs from '@firebase/auth-types-exp';

import { Operation } from '../model/action_code_info';
import { Auth } from '../model/auth';
import { AUTH_ERROR_FACTORY, AuthErrorCode } from './errors';

/**
* Enums for fields in URL query string.
Expand Down Expand Up @@ -64,7 +66,7 @@ function parseDeepLink(url: string): string {
return iOSDoubleDeepLink || iOSDeepLink || doubleDeepLink || link || url;
}

export class ActionCodeURL {
export class ActionCodeURL implements externs.ActionCodeURL {
readonly apiKey: string;
readonly code: string;
readonly continueUrl: string | null;
Expand Down
18 changes: 8 additions & 10 deletions packages-exp/auth-exp/src/core/auth/auth_impl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as sinon from 'sinon';
import * as sinonChai from 'sinon-chai';

import { FirebaseApp } from '@firebase/app-types-exp';
import * as externs from '@firebase/auth-types-exp';
import { FirebaseError } from '@firebase/util';

import { testUser } from '../../../test/mock_auth';
Expand All @@ -31,10 +32,7 @@ import { inMemoryPersistence } from '../persistence/in_memory';
import { PersistenceUserManager } from '../persistence/persistence_user_manager';
import { _getClientVersion, ClientPlatform } from '../util/version';
import {
DEFAULT_API_HOST,
DEFAULT_API_SCHEME,
DEFAULT_TOKEN_API_HOST,
initializeAuth
DEFAULT_API_HOST, DEFAULT_API_SCHEME, DEFAULT_TOKEN_API_HOST, initializeAuth
} from './auth_impl';

use(sinonChai);
Expand All @@ -53,8 +51,8 @@ describe('core/auth/auth_impl', () => {
let persistenceStub: sinon.SinonStubbedInstance<Persistence>;

beforeEach(() => {
persistenceStub = sinon.stub(inMemoryPersistence);
auth = initializeAuth(FAKE_APP, { persistence: inMemoryPersistence });
persistenceStub = sinon.stub(inMemoryPersistence as Persistence);
auth = initializeAuth(FAKE_APP, { persistence: inMemoryPersistence }) as Auth;
});

afterEach(sinon.restore);
Expand Down Expand Up @@ -104,7 +102,7 @@ describe('core/auth/auth_impl', () => {

describe('#setPersistence', () => {
it('swaps underlying persistence', async () => {
const newPersistence = browserLocalPersistence;
const newPersistence = browserLocalPersistence as Persistence;
const newStub = sinon.stub(newPersistence);
persistenceStub.get.returns(
Promise.resolve(testUser('test').toPlainObject())
Expand Down Expand Up @@ -276,13 +274,13 @@ describe('core/auth/initializeAuth', () => {
});

async function initAndWait(
persistence: Persistence | Persistence[]
persistence: externs.Persistence | externs.Persistence[]
): Promise<Auth> {
const auth = initializeAuth(FAKE_APP, { persistence });
// Auth initializes async. We can make sure the initialization is
// flushed by awaiting a method on the queue.
await auth.setPersistence(inMemoryPersistence);
return auth;
return auth as Auth;
}

it('converts single persistence to array', async () => {
Expand All @@ -294,7 +292,7 @@ describe('core/auth/initializeAuth', () => {

it('pulls the user from storage', async () => {
sinon
.stub(inMemoryPersistence, 'get')
.stub(inMemoryPersistence as Persistence, 'get')
.returns(Promise.resolve(testUser('uid').toPlainObject()));
const auth = await initAndWait(inMemoryPersistence);
expect(auth.currentUser!.uid).to.eq('uid');
Expand Down
18 changes: 6 additions & 12 deletions packages-exp/auth-exp/src/core/auth/auth_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@ import { getApp } from '@firebase/app-exp';
import { FirebaseApp } from '@firebase/app-types-exp';
import * as externs from '@firebase/auth-types-exp';
import {
CompleteFn,
createSubscribe,
ErrorFn,
NextFn,
Observer,
Subscribe,
Unsubscribe
CompleteFn, createSubscribe, ErrorFn, NextFn, Observer, Subscribe, Unsubscribe
} from '@firebase/util';

import { Auth, Config, Dependencies, NextOrObserver } from '../../model/auth';
import { Auth, Dependencies, NextOrObserver } from '../../model/auth';
import { User } from '../../model/user';
import { AuthErrorCode } from '../errors';
import { Persistence } from '../persistence';
Expand Down Expand Up @@ -58,7 +52,7 @@ class AuthImpl implements Auth {

constructor(
public readonly name: string,
public readonly config: Config,
public readonly config: externs.Config,
persistenceHierarchy: Persistence[]
) {
// This promise is intended to float; auth initialization happens in the
Expand Down Expand Up @@ -197,14 +191,14 @@ class AuthImpl implements Auth {
export function initializeAuth(
app: FirebaseApp = getApp(),
deps?: Dependencies
): Auth {
): externs.Auth {
const persistence = deps?.persistence || [];
const hierarchy = Array.isArray(persistence) ? persistence : [persistence];
const { apiKey, authDomain } = app.options;

// TODO: platform needs to be determined using heuristics
assert(apiKey, app.name, AuthErrorCode.INVALID_API_KEY);
const config: Config = {
const config: externs.Config = {
apiKey,
authDomain,
apiHost: DEFAULT_API_HOST,
Expand All @@ -213,7 +207,7 @@ export function initializeAuth(
sdkClientVersion: _getClientVersion(ClientPlatform.BROWSER)
};

return new AuthImpl(app.name, config, hierarchy);
return new AuthImpl(app.name, config, hierarchy as Persistence[]);
}

/** Helper class to wrap subscriber logic */
Expand Down
6 changes: 3 additions & 3 deletions packages-exp/auth-exp/src/core/persistence/browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { expect } from 'chai';
import * as sinon from 'sinon';

import { testUser } from '../../../test/mock_auth';
import { PersistedBlob, PersistenceType } from './';
import { PersistedBlob, Persistence, PersistenceType } from './';
import { browserLocalPersistence, browserSessionPersistence } from './browser';

describe('core/persistence/browser', () => {
Expand All @@ -31,7 +31,7 @@ describe('core/persistence/browser', () => {
afterEach(() => sinon.restore());

describe('browserLocalPersistence', () => {
const persistence = browserLocalPersistence;
const persistence: Persistence = browserLocalPersistence as Persistence;

it('should work with persistence type', async () => {
const key = 'my-super-special-persistence-type';
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('core/persistence/browser', () => {
});

describe('browserSessionPersistence', () => {
const persistence = browserSessionPersistence;
const persistence = browserSessionPersistence as Persistence;

it('should work with persistence type', async () => {
const key = 'my-super-special-persistence-type';
Expand Down
13 changes: 5 additions & 8 deletions packages-exp/auth-exp/src/core/persistence/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
* limitations under the License.
*/

import {
Persistence,
PersistenceType,
PersistenceValue,
STORAGE_AVAILABLE_KEY
} from './';
import * as externs from '@firebase/auth-types-exp';

import { Persistence, PersistenceType, PersistenceValue, STORAGE_AVAILABLE_KEY } from './';

class BrowserPersistence implements Persistence {
type: PersistenceType = PersistenceType.LOCAL;
Expand Down Expand Up @@ -54,9 +51,9 @@ class BrowserPersistence implements Persistence {
}
}

export const browserLocalPersistence: Persistence = new BrowserPersistence(
export const browserLocalPersistence: externs.Persistence = new BrowserPersistence(
localStorage
);
export const browserSessionPersistence: Persistence = new BrowserPersistence(
export const browserSessionPersistence: externs.Persistence = new BrowserPersistence(
sessionStorage
);
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import { expect } from 'chai';

import { testUser } from '../../../test/mock_auth';
import { PersistenceType } from './';
import { inMemoryPersistence as persistence } from './in_memory';
import { Persistence, PersistenceType } from './';
import { inMemoryPersistence } from './in_memory';

const persistence = inMemoryPersistence as Persistence;

describe('core/persistence/in_memory', () => {
it('should work with persistence type', async () => {
Expand Down
4 changes: 3 additions & 1 deletion packages-exp/auth-exp/src/core/persistence/in_memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

import * as externs from '@firebase/auth-types-exp';

import { Persistence, PersistenceType, PersistenceValue } from '../persistence';

class InMemoryPersistence implements Persistence {
Expand All @@ -41,4 +43,4 @@ class InMemoryPersistence implements Persistence {
}
}

export const inMemoryPersistence: Persistence = new InMemoryPersistence();
export const inMemoryPersistence: externs.Persistence = new InMemoryPersistence();
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import { expect } from 'chai';
import * as sinon from 'sinon';

import { testUser } from '../../../test/mock_auth';
import { PersistenceType } from './';
import { indexedDBLocalPersistence as persistence } from './indexed_db';
import { Persistence, PersistenceType } from './';
import { indexedDBLocalPersistence } from './indexed_db';

const persistence = indexedDBLocalPersistence as Persistence;

describe('core/persistence/indexed_db', () => {
afterEach(sinon.restore);
Expand Down
10 changes: 4 additions & 6 deletions packages-exp/auth-exp/src/core/persistence/indexed_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
* limitations under the License.
*/

import * as externs from '@firebase/auth-types-exp';

import {
PersistedBlob,
Persistence,
PersistenceType,
PersistenceValue,
STORAGE_AVAILABLE_KEY
PersistedBlob, Persistence, PersistenceType, PersistenceValue, STORAGE_AVAILABLE_KEY
} from './';

export const DB_NAME = 'firebaseLocalStorageDb';
Expand Down Expand Up @@ -175,4 +173,4 @@ class IndexedDBLocalPersistence implements Persistence {
}
}

export const indexedDBLocalPersistence: Persistence = new IndexedDBLocalPersistence();
export const indexedDBLocalPersistence: externs.Persistence = new IndexedDBLocalPersistence();
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class PersistenceUserManager {
userKey = _AUTH_USER_KEY_NAME
): Promise<PersistenceUserManager> {
if (!persistenceHierarchy.length) {
return new PersistenceUserManager(inMemoryPersistence, auth, userKey);
return new PersistenceUserManager(inMemoryPersistence as Persistence, auth, userKey);
}

const key = _persistenceKeyName(userKey, auth.config.apiKey, auth.name);
Expand Down
8 changes: 2 additions & 6 deletions packages-exp/auth-exp/src/core/persistence/react_native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@
* limitations under the License.
*/

import {
Persistence,
PersistenceType,
PersistenceValue,
STORAGE_AVAILABLE_KEY
} from './';
import { ReactNativeAsyncStorage } from '@firebase/auth-types-exp';

import { Persistence, PersistenceType, PersistenceValue, STORAGE_AVAILABLE_KEY } from './';

/**
* Persistence class that wraps AsyncStorage imported from `react-native` or `@react-native-community/async-storage`.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,9 @@
* limitations under the License.
*/

import { GetOobCodeRequest } from '../api/authentication/email_and_password';
import { ActionCodeSettings } from '@firebase/auth-types-exp';

export interface ActionCodeSettings {
android?: {
installApp?: boolean;
minimumVersion?: string;
packageName: string;
};
handleCodeInApp?: boolean;
iOS?: {
bundleId: string;
appStoreId: string;
};
url: string;
dynamicLinkDomain?: string;
}
import { GetOobCodeRequest } from '../../api/authentication/email_and_password';

export function setActionCodeSettingsOnRequest(
request: GetOobCodeRequest,
Expand Down
11 changes: 3 additions & 8 deletions packages-exp/auth-exp/src/core/strategies/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@
*/

import * as externs from '@firebase/auth-types-exp';
import { ActionCodeSettings } from '@firebase/auth-types-exp';

import {
createAuthUri,
CreateAuthUriRequest
} from '../../api/authentication/create_auth_uri';
import { createAuthUri, CreateAuthUriRequest } from '../../api/authentication/create_auth_uri';
import * as api from '../../api/authentication/email_and_password';
import { Operation } from '../../model/action_code_info';
import {
ActionCodeSettings,
setActionCodeSettingsOnRequest
} from '../../model/action_code_settings';
import { Auth } from '../../model/auth';
import { User } from '../../model/user';
import { _getCurrentUrl, _isHttpOrHttps } from '../util/location';
import { setActionCodeSettingsOnRequest } from './action_code_settings';

export async function fetchSignInMethodsForEmail(
auth: externs.Auth,
Expand Down
Loading