Skip to content

Commit 2357f74

Browse files
committed
Refactor project structure to support node
1 parent 3fa6502 commit 2357f74

30 files changed

+335
-252
lines changed

packages-exp/auth-exp/index.node.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
* just use index.browser.ts
2323
*/
2424

25+
import 'isomorphic-fetch';
26+
27+
import { registerVersion } from '@firebase/app-exp';
28+
import { name, version } from './package.json';
2529
import { _initializeAuthForClientPlatform } from './src/core/auth/auth_impl';
2630
import { ClientPlatform } from './src/core/util/version';
2731

@@ -31,3 +35,5 @@ export * from './src';
3135
export const initializeAuth = _initializeAuthForClientPlatform(
3236
ClientPlatform.NODE
3337
);
38+
39+
registerVersion(name, version, 'node');

packages-exp/auth-exp/index.rn.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
* just use index.ts
2323
*/
2424

25+
import { registerVersion } from '@firebase/app-exp';
2526
import { AsyncStorage } from 'react-native';
27+
import { name, version } from './package.json';
2628
import { _initializeAuthForClientPlatform } from './src/core/auth/auth_impl';
27-
import { getReactNativePersistence } from './src/core/persistence/react_native';
29+
import { getReactNativePersistence } from './src/platform_react_native/persistence/react_native';
2830
import { ClientPlatform } from './src/core/util/version';
2931

3032
// Core functionality shared by all clients
@@ -37,3 +39,5 @@ export const reactNativeLocalPersistence = getReactNativePersistence(
3739
export const initializeAuth = _initializeAuthForClientPlatform(
3840
ClientPlatform.REACT_NATIVE
3941
);
42+
43+
registerVersion(name, version, 'rn');

packages-exp/auth-exp/index.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { registerVersion } from '@firebase/app-exp';
19+
import { name, version } from './package.json';
1820
import { _initializeAuthForClientPlatform } from './src/core/auth/auth_impl';
1921
import { ClientPlatform } from './src/core/util/version';
2022

@@ -23,35 +25,42 @@ export * from './src';
2325

2426
// Additional DOM dependend functionality
2527

26-
// core/persistence
28+
// persistence
2729
export {
2830
browserLocalPersistence,
2931
browserSessionPersistence
30-
} from './src/core/persistence/browser';
32+
} from './src/platform_browser/persistence/browser';
3133

32-
// core/strategies
34+
// providers
35+
export { PhoneAuthProvider } from './src/platform_browser/providers/phone';
36+
37+
// strategies
3338
export {
3439
signInWithPhoneNumber,
3540
linkWithPhoneNumber,
3641
reauthenticateWithPhoneNumber,
3742
updatePhoneNumber
38-
} from './src/core/strategies/phone';
43+
} from './src/platform_browser/strategies/phone';
3944
export {
4045
signInWithPopup,
4146
linkWithPopup,
4247
reauthenticateWithPopup
43-
} from './src/core/strategies/popup';
48+
} from './src/platform_browser/strategies/popup';
4449
export {
4550
signInWithRedirect,
4651
linkWithRedirect,
4752
reauthenticateWithRedirect,
4853
getRedirectResult
49-
} from './src/core/strategies/redirect';
54+
} from './src/platform_browser/strategies/redirect';
5055

51-
// platform_browser
5256
export { RecaptchaVerifier } from './src/platform_browser/recaptcha/recaptcha_verifier';
5357
export { browserPopupRedirectResolver } from './src/platform_browser/popup_redirect';
5458

59+
// MFA
60+
export { PhoneMultiFactorGenerator } from './src/platform_browser/mfa/assertions/phone';
61+
5562
export const initializeAuth = _initializeAuthForClientPlatform(
5663
ClientPlatform.BROWSER
5764
);
65+
66+
registerVersion(name, version);

packages-exp/auth-exp/index.webworker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { registerVersion } from '@firebase/app-exp';
19+
import { name, version } from './package.json';
1820
import { _initializeAuthForClientPlatform } from './src/core/auth/auth_impl';
1921
import { ClientPlatform } from './src/core/util/version';
2022

@@ -24,3 +26,5 @@ export * from './src';
2426
export const initializeAuth = _initializeAuthForClientPlatform(
2527
ClientPlatform.WORKER
2628
);
29+
30+
registerVersion(name, version, 'webworker');

packages-exp/auth-exp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"test:browser:unit": "karma start --single-run --unit",
2828
"test:browser:integration": "karma start --single-run --integration",
2929
"test:browser:debug": "karma start --auto-watch",
30-
"test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha src/**/*.test.* --opts ../../config/mocha.node.opts",
30+
"test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'src/!(platform_browser|platform_react_native)/**/*.test.ts' --file index.node.ts --config ../../config/mocharc.node.js",
3131
"type-check": "tsc -p . --noEmit",
3232
"prepare": "yarn build",
3333
"typings:public": "node ./use_typings.js --public",

packages-exp/auth-exp/rollup.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import strip from '@rollup/plugin-strip';
1919
import typescriptPlugin from 'rollup-plugin-typescript2';
20+
import json from 'rollup-plugin-json';
2021
import typescript from 'typescript';
2122
import pkg from './package.json';
2223

@@ -28,6 +29,7 @@ const deps = Object.keys(
2829
* Common plugins for all builds
2930
*/
3031
const commonPlugins = [
32+
json(),
3133
strip({
3234
functions: ['debugAssert.*']
3335
})

packages-exp/auth-exp/src/core/auth/auth_impl.test.ts

Lines changed: 1 addition & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { Persistence } from '../persistence';
3232
import {
3333
browserLocalPersistence,
3434
browserSessionPersistence
35-
} from '../persistence/browser';
35+
} from '../../platform_browser/persistence/browser';
3636
import { inMemoryPersistence } from '../persistence/in_memory';
3737
import { PersistenceUserManager } from '../persistence/persistence_user_manager';
3838
import * as reload from '../user/reload';
@@ -288,172 +288,3 @@ describe('core/auth/auth_impl', () => {
288288
});
289289
});
290290

291-
describe('core/auth/initializeAuth', () => {
292-
afterEach(sinon.restore);
293-
294-
it('throws an API error if key not provided', () => {
295-
expect(() =>
296-
initializeAuth({
297-
...FAKE_APP,
298-
options: {} // apiKey is missing
299-
})
300-
).to.throw(
301-
FirebaseError,
302-
'Firebase: Your API key is invalid, please check you have copied it correctly. (auth/invalid-api-key).'
303-
);
304-
});
305-
306-
describe('persistence manager creation', () => {
307-
let createManagerStub: sinon.SinonSpy;
308-
let reloadStub: sinon.SinonStub;
309-
310-
beforeEach(() => {
311-
createManagerStub = sinon.spy(PersistenceUserManager, 'create');
312-
reloadStub = sinon
313-
.stub(reload, '_reloadWithoutSaving')
314-
.returns(Promise.resolve());
315-
});
316-
317-
async function initAndWait(
318-
persistence: externs.Persistence | externs.Persistence[],
319-
popupRedirectResolver?: externs.PopupRedirectResolver
320-
): Promise<externs.Auth> {
321-
const auth = initializeAuth(FAKE_APP, {
322-
persistence,
323-
popupRedirectResolver
324-
});
325-
// Auth initializes async. We can make sure the initialization is
326-
// flushed by awaiting a method on the queue.
327-
await auth.setPersistence(inMemoryPersistence);
328-
return auth;
329-
}
330-
331-
it('converts single persistence to array', async () => {
332-
const auth = await initAndWait(inMemoryPersistence);
333-
expect(createManagerStub).to.have.been.calledWith(auth, [
334-
_getInstance(inMemoryPersistence)
335-
]);
336-
});
337-
338-
it('pulls the user from storage', async () => {
339-
sinon
340-
.stub(_getInstance<Persistence>(inMemoryPersistence), 'get')
341-
.returns(Promise.resolve(testUser({}, 'uid').toPlainObject()));
342-
const auth = await initAndWait(inMemoryPersistence);
343-
expect(auth.currentUser!.uid).to.eq('uid');
344-
});
345-
346-
it('calls create with the persistence in order', async () => {
347-
const auth = await initAndWait([
348-
inMemoryPersistence,
349-
browserLocalPersistence
350-
]);
351-
expect(createManagerStub).to.have.been.calledWith(auth, [
352-
_getInstance(inMemoryPersistence),
353-
_getInstance(browserLocalPersistence)
354-
]);
355-
});
356-
357-
it('does not reload redirect users', async () => {
358-
const user = testUser({}, 'uid');
359-
user._redirectEventId = 'event-id';
360-
sinon
361-
.stub(_getInstance<Persistence>(inMemoryPersistence), 'get')
362-
.returns(Promise.resolve(user.toPlainObject()));
363-
sinon
364-
.stub(_getInstance<Persistence>(browserSessionPersistence), 'get')
365-
.returns(Promise.resolve(user.toPlainObject()));
366-
await initAndWait(inMemoryPersistence);
367-
expect(reload._reloadWithoutSaving).not.to.have.been.called;
368-
});
369-
370-
it('reloads non-redirect users', async () => {
371-
sinon
372-
.stub(_getInstance<Persistence>(inMemoryPersistence), 'get')
373-
.returns(Promise.resolve(testUser({}, 'uid').toPlainObject()));
374-
sinon
375-
.stub(_getInstance<Persistence>(browserSessionPersistence), 'get')
376-
.returns(Promise.resolve(null));
377-
378-
await initAndWait(inMemoryPersistence);
379-
expect(reload._reloadWithoutSaving).to.have.been.called;
380-
});
381-
382-
it('Does not reload if the event ids match', async () => {
383-
const user = testUser({}, 'uid');
384-
user._redirectEventId = 'event-id';
385-
386-
sinon
387-
.stub(_getInstance<Persistence>(inMemoryPersistence), 'get')
388-
.returns(Promise.resolve(user.toPlainObject()));
389-
sinon
390-
.stub(_getInstance<Persistence>(browserSessionPersistence), 'get')
391-
.returns(Promise.resolve(user.toPlainObject()));
392-
393-
await initAndWait(inMemoryPersistence, browserPopupRedirectResolver);
394-
expect(reload._reloadWithoutSaving).not.to.have.been.called;
395-
});
396-
397-
it('Reloads if the event ids do not match', async () => {
398-
const user = testUser({}, 'uid');
399-
user._redirectEventId = 'event-id';
400-
401-
sinon
402-
.stub(_getInstance<Persistence>(inMemoryPersistence), 'get')
403-
.returns(Promise.resolve(user.toPlainObject()));
404-
405-
user._redirectEventId = 'some-other-id';
406-
sinon
407-
.stub(_getInstance<Persistence>(browserSessionPersistence), 'get')
408-
.returns(Promise.resolve(user.toPlainObject()));
409-
410-
await initAndWait(inMemoryPersistence, browserPopupRedirectResolver);
411-
expect(reload._reloadWithoutSaving).to.have.been.called;
412-
});
413-
414-
it('Nulls out the current user if reload fails', async () => {
415-
const stub = sinon.stub(_getInstance<Persistence>(inMemoryPersistence));
416-
stub.get.returns(Promise.resolve(testUser({}, 'uid').toPlainObject()));
417-
stub.remove.returns(Promise.resolve());
418-
reloadStub.returns(
419-
Promise.reject(
420-
AUTH_ERROR_FACTORY.create(AuthErrorCode.TOKEN_EXPIRED, {
421-
appName: 'app'
422-
})
423-
)
424-
);
425-
426-
await initAndWait(inMemoryPersistence);
427-
expect(stub.remove).to.have.been.called;
428-
});
429-
430-
it('Keeps current user if reload fails with network error', async () => {
431-
const stub = sinon.stub(_getInstance<Persistence>(inMemoryPersistence));
432-
stub.get.returns(Promise.resolve(testUser({}, 'uid').toPlainObject()));
433-
stub.remove.returns(Promise.resolve());
434-
reloadStub.returns(
435-
Promise.reject(
436-
AUTH_ERROR_FACTORY.create(AuthErrorCode.NETWORK_REQUEST_FAILED, {
437-
appName: 'app'
438-
})
439-
)
440-
);
441-
442-
await initAndWait(inMemoryPersistence);
443-
expect(stub.remove).not.to.have.been.called;
444-
});
445-
446-
it('sets auth name and config', async () => {
447-
const auth = await initAndWait(inMemoryPersistence);
448-
expect(auth.name).to.eq(FAKE_APP.name);
449-
expect(auth.config).to.eql({
450-
apiKey: FAKE_APP.options.apiKey,
451-
authDomain: FAKE_APP.options.authDomain,
452-
apiHost: DEFAULT_API_HOST,
453-
apiScheme: DEFAULT_API_SCHEME,
454-
tokenApiHost: DEFAULT_TOKEN_API_HOST,
455-
sdkClientVersion: _getClientVersion(ClientPlatform.BROWSER)
456-
});
457-
});
458-
});
459-
});

packages-exp/auth-exp/src/core/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export { FacebookAuthProvider } from './providers/facebook';
6767
export { GoogleAuthProvider } from './providers/google';
6868
export { GithubAuthProvider } from './providers/github';
6969
export { OAuthProvider } from './providers/oauth';
70-
export { PhoneAuthProvider } from './providers/phone';
7170
export { TwitterAuthProvider } from './providers/twitter';
7271

7372
// strategies

packages-exp/auth-exp/src/mfa/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@
1515
* limitations under the License.
1616
*/
1717

18-
export { PhoneMultiFactorGenerator } from './assertions/phone';
1918
export { getMultiFactorResolver } from './mfa_resolver';
2019
export { multiFactor } from './mfa_user';

packages-exp/auth-exp/src/mfa/mfa_resolver.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { AUTH_ERROR_FACTORY, AuthErrorCode } from '../core/errors';
3232
import { EmailAuthProvider } from '../core/providers/email';
3333
import { User, UserCredential } from '../model/user';
3434
import { MultiFactorAssertion } from './assertions';
35-
import { PhoneMultiFactorAssertion } from './assertions/phone';
35+
import { PhoneMultiFactorAssertion } from '../platform_browser/mfa/assertions/phone';
3636
import { MultiFactorError } from './mfa_error';
3737
import { getMultiFactorResolver, MultiFactorResolver } from './mfa_resolver';
3838

packages-exp/auth-exp/src/mfa/mfa_user.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import { Endpoint } from '../api';
2727
import { APIUserInfo } from '../api/account_management/account';
2828
import { FinalizeMfaResponse } from '../api/authentication/mfa';
2929
import { ServerError } from '../api/errors';
30-
import { PhoneAuthProvider } from '../core/providers/phone';
30+
import { PhoneAuthProvider } from '../platform_browser/providers/phone';
3131
import { User } from '../model/user';
32-
import { PhoneMultiFactorAssertion } from './assertions/phone';
32+
import { PhoneMultiFactorAssertion } from '../platform_browser/mfa/assertions/phone';
3333
import { MultiFactorInfo } from './mfa_info';
3434
import { MultiFactorSession, MultiFactorSessionType } from './mfa_session';
3535
import { multiFactor, MultiFactorUser } from './mfa_user';

0 commit comments

Comments
 (0)