Skip to content

Commit ee27660

Browse files
authored
Merge branch 'master' into ys/webdriver-strict
2 parents f7962ef + 5ec9c83 commit ee27660

File tree

45 files changed

+1616
-793
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1616
-793
lines changed

.changeset/clever-apricots-look.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@firebase/component": minor
3+
"@firebase/database": patch
4+
"@firebase/firestore": patch
5+
"@firebase/functions": patch
6+
"@firebase/remote-config": patch
7+
"@firebase/storage": patch
8+
---
9+
10+
Component facotry now takes an options object. And added `Provider.initialize()` that can be used to pass an options object to the component factory.

.changeset/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@firebase/installations-compat",
2525
"@firebase/messaging-exp",
2626
"@firebase/performance-exp",
27+
"@firebase/performance-compat",
2728
"@firebase/remote-config-exp",
2829
"@firebase/remote-config-compat",
2930
"firebase-exp",

packages-exp/analytics-compat/src/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,13 @@ declare module '@firebase/component' {
4141
}
4242

4343
const factory: InstanceFactory<'analytics-compat'> = (
44-
container: ComponentContainer,
45-
regionOrCustomDomain?: string
44+
container: ComponentContainer
4645
) => {
4746
// Dependencies
4847
const app = container.getProvider('app-compat').getImmediate();
4948
const analyticsServiceExp = container
5049
.getProvider('analytics-exp')
51-
.getImmediate({
52-
identifier: regionOrCustomDomain
53-
});
50+
.getImmediate();
5451

5552
return new AnalyticsService(app as FirebaseApp, analyticsServiceExp);
5653
};

packages-exp/app-compat/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ registerCoreComponents();
4747
export default firebase;
4848

4949
export { _FirebaseNamespace, _FirebaseService } from './types';
50-
export { FirebaseApp } from './public-types';
50+
export { FirebaseApp, FirebaseNamespace } from './public-types';

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
InstantiationMode
2525
} from '@firebase/component';
2626

27+
import { FirebaseAuth } from '@firebase/auth-types';
2728
import { version } from './package.json';
2829
import { Auth } from './src/auth';
2930
import { Persistence } from './src/persistence';
@@ -33,6 +34,23 @@ import { RecaptchaVerifier } from './src/recaptcha_verifier';
3334

3435
const AUTH_TYPE = 'auth';
3536

37+
declare module '@firebase/component' {
38+
interface NameServiceMapping {
39+
'auth-compat': FirebaseAuth;
40+
}
41+
}
42+
43+
declare module '@firebase/app-compat' {
44+
interface FirebaseNamespace {
45+
auth: {
46+
(app?: FirebaseApp): FirebaseAuth;
47+
};
48+
}
49+
interface FirebaseApp {
50+
auth?(): FirebaseAuth;
51+
}
52+
}
53+
3654
// Create auth components to register with firebase.
3755
// Provides Auth public APIs.
3856
function registerAuthCompat(instance: _FirebaseNamespace): void {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ export function initializeAuth(app: FirebaseApp, deps?: Dependencies): Auth {
3434
_fail(auth, AuthErrorCode.ALREADY_INITIALIZED);
3535
}
3636

37-
const auth = provider.getImmediate() as AuthImpl;
38-
_initializeAuthInstance(auth, deps);
37+
const auth = provider.initialize({ options: deps }) as AuthImpl;
3938

4039
return auth;
4140
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { _assert } from '../util/assert';
2525
import { _getClientVersion, ClientPlatform } from '../util/version';
2626
import { _castAuth, AuthImpl, DefaultConfig } from './auth_impl';
2727
import { AuthInterop } from './firebase_internal';
28+
import { Dependencies } from '../../model/auth';
29+
import { _initializeAuthInstance } from './initialize';
2830

2931
export const enum _ComponentName {
3032
AUTH = 'auth-exp',
@@ -53,7 +55,7 @@ export function registerAuth(clientPlatform: ClientPlatform): void {
5355
_registerComponent(
5456
new Component(
5557
_ComponentName.AUTH,
56-
container => {
58+
(container, { options: deps }: { options?: Dependencies }) => {
5759
const app = container.getProvider('app-exp').getImmediate()!;
5860
const { apiKey, authDomain } = app.options;
5961
return (app => {
@@ -66,7 +68,11 @@ export function registerAuth(clientPlatform: ClientPlatform): void {
6668
apiScheme: DefaultConfig.API_SCHEME,
6769
sdkClientVersion: _getClientVersion(clientPlatform)
6870
};
69-
return new AuthImpl(app, config);
71+
72+
const authInstance = new AuthImpl(app, config);
73+
_initializeAuthInstance(authInstance, deps);
74+
75+
return authInstance;
7076
})(app);
7177
},
7278
ComponentType.PUBLIC

packages-exp/auth-exp/src/core/persistence/persistence_user_manager.test.ts

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ import * as sinonChai from 'sinon-chai';
2323
import { testAuth, testUser, TestAuth } from '../../../test/helpers/mock_auth';
2424
import { UserImpl } from '../user/user_impl';
2525
import { _getInstance } from '../util/instantiator';
26-
import { PersistenceInternal, PersistenceType, StorageEventListener } from './';
26+
import {
27+
PersistenceInternal,
28+
PersistenceType,
29+
PersistenceValue,
30+
StorageEventListener
31+
} from './';
2732
import { inMemoryPersistence } from './in_memory';
2833
import { KeyName, PersistenceUserManager } from './persistence_user_manager';
2934

@@ -64,19 +69,78 @@ describe('core/persistence/persistence_user_manager', () => {
6469
expect(manager.persistence).to.eq(_getInstance(inMemoryPersistence));
6570
});
6671

67-
it('searches in order for a user', async () => {
72+
it('chooses the first one available', async () => {
6873
const a = makePersistence();
6974
const b = makePersistence();
7075
const c = makePersistence();
7176
const search = [a.persistence, b.persistence, c.persistence];
7277
const auth = await testAuth();
73-
b.stub._get.returns(Promise.resolve(testUser(auth, 'uid').toJSON()));
78+
a.stub._isAvailable.resolves(false);
79+
a.stub._get.onFirstCall().resolves(testUser(auth, 'uid').toJSON());
80+
b.stub._isAvailable.resolves(true);
7481

7582
const out = await PersistenceUserManager.create(auth, search);
83+
expect(a.stub._isAvailable).to.have.been.calledOnce;
84+
expect(b.stub._isAvailable).to.have.been.calledOnce;
85+
expect(c.stub._isAvailable).to.not.have.been.called;
86+
87+
// a should not be chosen since it is not available (despite having a user).
7688
expect(out.persistence).to.eq(b.persistence);
89+
});
90+
91+
it('searches in order for a user', async () => {
92+
const a = makePersistence();
93+
const b = makePersistence();
94+
const c = makePersistence();
95+
const search = [a.persistence, b.persistence, c.persistence];
96+
const auth = await testAuth();
97+
const user = testUser(auth, 'uid');
98+
a.stub._isAvailable.resolves(true);
99+
a.stub._get.resolves(user.toJSON());
100+
b.stub._get.resolves(testUser(auth, 'wrong-uid').toJSON());
101+
102+
const out = await PersistenceUserManager.create(auth, search);
77103
expect(a.stub._get).to.have.been.calledOnce;
78-
expect(b.stub._get).to.have.been.calledOnce;
104+
expect(b.stub._get).not.to.have.been.called;
79105
expect(c.stub._get).not.to.have.been.called;
106+
107+
expect(out.persistence).to.eq(a.persistence);
108+
expect((await out.getCurrentUser())!.uid).to.eq(user.uid);
109+
});
110+
111+
it('migrate found user to the selected persistence and clear others', async () => {
112+
const a = makePersistence();
113+
const b = makePersistence();
114+
const c = makePersistence();
115+
const search = [a.persistence, b.persistence, c.persistence];
116+
const auth = await testAuth();
117+
const user = testUser(auth, 'uid');
118+
a.stub._isAvailable.resolves(true);
119+
b.stub._get.resolves(user.toJSON());
120+
c.stub._get.resolves(testUser(auth, 'wrong-uid').toJSON());
121+
122+
let persistedUserInA: PersistenceValue | null = null;
123+
a.stub._set.callsFake(async (_, value) => {
124+
persistedUserInA = value;
125+
});
126+
a.stub._get.callsFake(async () => persistedUserInA);
127+
128+
const out = await PersistenceUserManager.create(auth, search);
129+
expect(a.stub._set).to.have.been.calledOnceWith(
130+
'firebase:authUser:test-api-key:test-app',
131+
user.toJSON()
132+
);
133+
expect(b.stub._set).to.not.have.been.called;
134+
expect(c.stub._set).to.not.have.been.called;
135+
expect(b.stub._remove).to.have.been.calledOnceWith(
136+
'firebase:authUser:test-api-key:test-app'
137+
);
138+
expect(c.stub._remove).to.have.been.calledOnceWith(
139+
'firebase:authUser:test-api-key:test-app'
140+
);
141+
142+
expect(out.persistence).to.eq(a.persistence);
143+
expect((await out.getCurrentUser())!.uid).to.eq(user.uid);
80144
});
81145

82146
it('uses default user key if none provided', async () => {
@@ -99,13 +163,17 @@ describe('core/persistence/persistence_user_manager', () => {
99163
);
100164
});
101165

102-
it('returns zeroth persistence if all else fails', async () => {
166+
it('returns in-memory persistence if all else fails', async () => {
103167
const a = makePersistence();
104168
const b = makePersistence();
105169
const c = makePersistence();
106170
const search = [a.persistence, b.persistence, c.persistence];
171+
a.stub._isAvailable.resolves(false);
172+
b.stub._isAvailable.resolves(false);
173+
c.stub._isAvailable.resolves(false);
174+
107175
const out = await PersistenceUserManager.create(auth, search);
108-
expect(out.persistence).to.eq(a.persistence);
176+
expect(out.persistence).to.eq(_getInstance(inMemoryPersistence));
109177
expect(a.stub._get).to.have.been.calledOnce;
110178
expect(b.stub._get).to.have.been.calledOnce;
111179
expect(c.stub._get).to.have.been.called;
@@ -118,6 +186,7 @@ describe('core/persistence/persistence_user_manager', () => {
118186

119187
beforeEach(async () => {
120188
const { persistence, stub } = makePersistence(PersistenceType.SESSION);
189+
stub._isAvailable.resolves(true);
121190
persistenceStub = stub;
122191
manager = await PersistenceUserManager.create(auth, [persistence]);
123192
});

packages-exp/functions-exp/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const DEFAULT_REGION = 'us-central1';
3030
export function registerFunctions(fetchImpl: typeof fetch): void {
3131
const factory: InstanceFactory<'functions'> = (
3232
container: ComponentContainer,
33-
regionOrCustomDomain?: string
33+
{ instanceIdentifier: regionOrCustomDomain }
3434
) => {
3535
// Dependencies
3636
const app = container.getProvider('app-exp').getImmediate();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
module.exports = {
19+
extends: '../../config/.eslintrc.js',
20+
parserOptions: {
21+
project: 'tsconfig.json',
22+
// to make vscode-eslint work with monorepo
23+
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
24+
tsconfigRootDir: __dirname
25+
}
26+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# @firebase/performance-compat
2+
3+
This is the compat package that recreates the v8 APIs.
4+
5+
**This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.**
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
const karmaBase = require('../../config/karma.base');
19+
20+
const files = ['test/**/*', 'src/**/*.test.ts'];
21+
22+
module.exports = function (config) {
23+
const karmaConfig = Object.assign({}, karmaBase, {
24+
// files to load into karma
25+
files: files,
26+
// frameworks to use
27+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
28+
preprocessors: { '**/*.ts': ['webpack', 'sourcemap'] },
29+
frameworks: ['mocha']
30+
});
31+
32+
config.set(karmaConfig);
33+
};
34+
35+
module.exports.files = files;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"name": "@firebase/performance-compat",
3+
"version": "0.0.900",
4+
"description": "The compatibility package of Firebase Performance",
5+
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
6+
"private": true,
7+
"main": "dist/index.cjs.js",
8+
"browser": "dist/index.esm5.js",
9+
"module": "dist/index.esm5.js",
10+
"esm2017": "dist/index.esm2017.js",
11+
"files": ["dist"],
12+
"scripts": {
13+
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
14+
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
15+
"build": "rollup -c",
16+
"build:release": "rollup -c rollup.config.release.js",
17+
"build:deps": "lerna run --scope @firebase/performance-compat --include-dependencies build",
18+
"dev": "rollup -c -w",
19+
"test": "run-p lint test:all",
20+
"test:all": "run-p test:browser",
21+
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all",
22+
"test:browser": "karma start --single-run",
23+
"test:browser:debug": "karma start --browsers Chrome --auto-watch",
24+
"prettier": "prettier --write '{src,test}/**/*.{js,ts}'"
25+
},
26+
"license": "Apache-2.0",
27+
"peerDependencies": {
28+
"@firebase/app-compat": "0.x",
29+
"@firebase/app-types": "0.x"
30+
},
31+
"dependencies": {
32+
"@firebase/performance-exp": "0.0.900",
33+
"@firebase/util": "0.4.0",
34+
"@firebase/logger": "0.2.6",
35+
"@firebase/component": "0.2.1",
36+
"tslib": "^2.0.0"
37+
},
38+
"devDependencies": {
39+
"rollup": "2.35.1",
40+
"@rollup/plugin-json": "4.1.0",
41+
"rollup-plugin-replace": "2.2.0",
42+
"rollup-plugin-typescript2": "0.29.0",
43+
"typescript": "4.2.2",
44+
"@firebase/app-compat": "0.0.900"
45+
},
46+
"repository": {
47+
"directory": "packages-exp/performance-compat",
48+
"type": "git",
49+
"url": "https://github.com/firebase/firebase-js-sdk.git"
50+
},
51+
"bugs": {
52+
"url": "https://github.com/firebase/firebase-js-sdk/issues"
53+
},
54+
"typings": "dist/src/index.d.ts",
55+
"nyc": {
56+
"extension": [
57+
".ts"
58+
],
59+
"reportDir": "./coverage/node"
60+
}
61+
}

0 commit comments

Comments
 (0)