Skip to content

Commit bca9ce7

Browse files
committed
Merge branch 'master' into ch-delegate
2 parents d127fa6 + fdadf71 commit bca9ce7

File tree

165 files changed

+2290
-2683
lines changed

Some content is hidden

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

165 files changed

+2290
-2683
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
export * from './index';
2525
import { FetchProvider } from '@firebase/auth-exp/internal';
2626
import * as fetchImpl from 'node-fetch';
27+
import './index';
2728

2829
FetchProvider.initialize(
2930
(fetchImpl.default as unknown) as typeof fetch,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ function registerAuthCompat(instance: _FirebaseNamespace): void {
9898
container => {
9999
// getImmediate for FirebaseApp will always succeed
100100
const app = container.getProvider('app-compat').getImmediate();
101-
const auth = container.getProvider('auth-exp').getImmediate();
102-
return new Auth(app, auth as impl.AuthImpl);
101+
const authProvider = container.getProvider('auth-exp');
102+
return new Auth(app, authProvider);
103103
},
104104
ComponentType.PUBLIC
105105
)
@@ -136,7 +136,7 @@ function registerAuthCompat(instance: _FirebaseNamespace): void {
136136
.setMultipleInstances(false)
137137
);
138138

139-
instance.registerVersion('auth', version);
139+
instance.registerVersion('auth-compat', version);
140140
}
141141

142142
registerAuthCompat(firebase as _FirebaseNamespace);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function getEs5Builds(additionalTypescriptPlugins = {}) {
6565
plugins: es5BuildPlugins,
6666
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
6767
treeshake: {
68-
moduleSideEffects: false
68+
moduleSideEffects: true
6969
}
7070
},
7171
/**

packages-exp/auth-compat-exp/src/auth.test.ts

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

1818
import { FirebaseApp } from '@firebase/app-compat';
1919
import * as exp from '@firebase/auth-exp/internal';
20+
import { Provider } from '@firebase/component';
2021
import { expect, use } from 'chai';
2122
import * as sinon from 'sinon';
2223
import * as sinonChai from 'sinon-chai';
@@ -31,12 +32,16 @@ describe('auth compat', () => {
3132
context('redirect persistence key storage', () => {
3233
let underlyingAuth: exp.AuthImpl;
3334
let app: FirebaseApp;
35+
let providerStub: sinon.SinonStubbedInstance<Provider<'auth-exp'>>;
36+
3437
beforeEach(() => {
3538
app = { options: { apiKey: 'api-key' } } as FirebaseApp;
3639
underlyingAuth = new exp.AuthImpl(app, {
3740
apiKey: 'api-key'
3841
} as exp.Config);
3942
sinon.stub(underlyingAuth, '_initializeWithPersistence');
43+
44+
providerStub = sinon.createStubInstance(Provider);
4045
});
4146

4247
afterEach(() => {
@@ -56,7 +61,12 @@ describe('auth compat', () => {
5661
),
5762
'_openRedirect'
5863
);
59-
const authCompat = new Auth(app, underlyingAuth);
64+
providerStub.isInitialized.returns(true);
65+
providerStub.getImmediate.returns(underlyingAuth);
66+
const authCompat = new Auth(
67+
app,
68+
(providerStub as unknown) as Provider<'auth-exp'>
69+
);
6070
// eslint-disable-next-line @typescript-eslint/no-floating-promises
6171
await authCompat.signInWithRedirect(new exp.GoogleAuthProvider());
6272
expect(
@@ -71,18 +81,20 @@ describe('auth compat', () => {
7181
'firebase:persistence:api-key:undefined',
7282
'none'
7383
);
74-
new Auth(app, underlyingAuth);
84+
providerStub.isInitialized.returns(false);
85+
providerStub.initialize.returns(underlyingAuth);
86+
new Auth(app, (providerStub as unknown) as Provider<'auth-exp'>);
7587
// eslint-disable-next-line @typescript-eslint/no-floating-promises
76-
expect(
77-
underlyingAuth._initializeWithPersistence
78-
).to.have.been.calledWith(
79-
[
80-
exp._getInstance(exp.inMemoryPersistence),
81-
exp._getInstance(exp.indexedDBLocalPersistence),
82-
exp._getInstance(exp.browserLocalPersistence)
83-
],
84-
CompatPopupRedirectResolver
85-
);
88+
expect(providerStub.initialize).to.have.been.calledWith({
89+
options: {
90+
popupRedirectResolver: CompatPopupRedirectResolver,
91+
persistence: [
92+
exp.inMemoryPersistence,
93+
exp.indexedDBLocalPersistence,
94+
exp.browserLocalPersistence
95+
]
96+
}
97+
});
8698
}
8799
});
88100
});

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

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import { FirebaseApp, _FirebaseService } from '@firebase/app-compat';
1919
import * as exp from '@firebase/auth-exp/internal';
2020
import * as compat from '@firebase/auth-types';
21+
import { Provider } from '@firebase/component';
2122
import { ErrorFn, Observer, Unsubscribe } from '@firebase/util';
2223

2324
import {
@@ -37,47 +38,55 @@ import {
3738
const _assert: typeof exp._assert = exp._assert;
3839

3940
export class Auth implements compat.FirebaseAuth, _FirebaseService {
40-
// private readonly auth: impl.AuthImpl;
41+
readonly _delegate: exp.AuthImpl;
4142

42-
constructor(readonly app: FirebaseApp, readonly _delegate: exp.AuthImpl) {
43-
const { apiKey } = app.options;
44-
if (this._delegate._deleted) {
43+
constructor(readonly app: FirebaseApp, provider: Provider<'auth-exp'>) {
44+
if (provider.isInitialized()) {
45+
this._delegate = provider.getImmediate() as exp.AuthImpl;
4546
return;
4647
}
4748

48-
// Note this is slightly different behavior: in this case, the stored
49-
// persistence is checked *first* rather than last. This is because we want
50-
// to prefer stored persistence type in the hierarchy.
51-
const persistences = _getPersistencesFromRedirect(this._delegate);
49+
const { apiKey } = app.options;
50+
// TODO: platform needs to be determined using heuristics
51+
_assert(apiKey, exp.AuthErrorCode.INVALID_API_KEY, {
52+
appName: app.name
53+
});
54+
55+
let persistences: exp.Persistence[] = [exp.inMemoryPersistence];
5256

53-
for (const persistence of [
54-
exp.indexedDBLocalPersistence,
55-
exp.browserLocalPersistence
56-
]) {
57-
if (!persistences.includes(persistence)) {
58-
persistences.push(persistence);
57+
// Only deal with persistences in web environments
58+
if (typeof window !== 'undefined') {
59+
// Note this is slightly different behavior: in this case, the stored
60+
// persistence is checked *first* rather than last. This is because we want
61+
// to prefer stored persistence type in the hierarchy.
62+
persistences = _getPersistencesFromRedirect(apiKey, app.name);
63+
64+
for (const persistence of [
65+
exp.indexedDBLocalPersistence,
66+
exp.browserLocalPersistence
67+
]) {
68+
if (!persistences.includes(persistence)) {
69+
persistences.push(persistence);
70+
}
5971
}
6072
}
6173

62-
const hierarchy = persistences.map<exp.PersistenceInternal>(
63-
exp._getInstance
64-
);
65-
6674
// TODO: platform needs to be determined using heuristics
6775
_assert(apiKey, exp.AuthErrorCode.INVALID_API_KEY, {
6876
appName: app.name
6977
});
7078

71-
this._delegate._updateErrorMap(exp.debugErrorMap);
72-
7379
// Only use a popup/redirect resolver in browser environments
7480
const resolver =
7581
typeof window !== 'undefined' ? CompatPopupRedirectResolver : undefined;
82+
this._delegate = provider.initialize({
83+
options: {
84+
persistence: persistences,
85+
popupRedirectResolver: resolver
86+
}
87+
}) as exp.AuthImpl;
7688

77-
// This promise is intended to float; auth initialization happens in the
78-
// background, meanwhile the auth object may be used by the app.
79-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
80-
this._delegate._initializeWithPersistence(hierarchy, resolver);
89+
this._delegate._updateErrorMap(exp.debugErrorMap);
8190
}
8291

8392
get emulatorConfig(): compat.EmulatorConfig | null {

packages-exp/auth-compat-exp/src/persistence.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,15 @@ export async function _savePersistenceForRedirect(
9797
}
9898

9999
export function _getPersistencesFromRedirect(
100-
auth: exp.AuthInternal
100+
apiKey: string,
101+
appName: string
101102
): exp.Persistence[] {
102103
const win = getSelfWindow();
103104
if (!win?.sessionStorage) {
104105
return [];
105106
}
106107

107-
const key = exp._persistenceKeyName(
108-
PERSISTENCE_KEY,
109-
auth.config.apiKey,
110-
auth.name
111-
);
108+
const key = exp._persistenceKeyName(PERSISTENCE_KEY, apiKey, appName);
112109
const persistence = win.sessionStorage.getItem(key);
113110

114111
switch (persistence) {

packages-exp/auth-compat-exp/test/integration/flows/anonymous.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import { expect, use } from 'chai';
1919
import * as chaiAsPromised from 'chai-as-promised';
2020

2121
import firebase from '@firebase/app-compat';
22-
// eslint-disable-next-line import/no-extraneous-dependencies
23-
import '@firebase/auth-compat';
2422
import { FirebaseError } from '@firebase/util';
2523
import {
2624
cleanUpTestInstance,

packages/database/.eslintrc.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,22 @@ module.exports = {
3030
'no-restricted-properties': 'off',
3131
'no-restricted-globals': 'off',
3232
'no-throw-literal': 'off',
33-
'id-blacklist': 'off'
33+
'id-blacklist': 'off',
34+
'import/order': [
35+
'error',
36+
{
37+
'groups': [
38+
'builtin',
39+
'external',
40+
'internal',
41+
'parent',
42+
'sibling',
43+
'index'
44+
],
45+
'newlines-between': 'always',
46+
'alphabetize': { 'order': 'asc', 'caseInsensitive': true }
47+
}
48+
]
3449
},
3550
overrides: [
3651
{

packages/database/index.node.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717

1818
import { FirebaseApp, FirebaseNamespace } from '@firebase/app-types';
1919
import { _FirebaseNamespace } from '@firebase/app-types/private';
20+
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
21+
import { Component, ComponentType } from '@firebase/component';
22+
import * as types from '@firebase/database-types';
23+
import { CONSTANTS, isNodeSdk } from '@firebase/util';
24+
import { Client } from 'faye-websocket';
25+
26+
import { name, version } from './package.json';
2027
import { Database, repoManagerDatabaseFromApp } from './src/api/Database';
2128
import { DataSnapshot } from './src/api/DataSnapshot';
29+
import * as INTERNAL from './src/api/internal';
2230
import { Query } from './src/api/Query';
2331
import { Reference } from './src/api/Reference';
24-
import { enableLogging } from './src/core/util/util';
25-
import * as INTERNAL from './src/api/internal';
2632
import * as TEST_ACCESS from './src/api/test_access';
27-
import * as types from '@firebase/database-types';
33+
import { enableLogging } from './src/core/util/util';
2834
import { setSDKVersion } from './src/core/version';
29-
import { CONSTANTS, isNodeSdk } from '@firebase/util';
3035
import { setWebSocketImpl } from './src/realtime/WebSocketConnection';
31-
import { Client } from 'faye-websocket';
32-
import { Component, ComponentType } from '@firebase/component';
33-
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
34-
35-
import { name, version } from './package.json';
3636

3737
setWebSocketImpl(Client);
3838

packages/database/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919
import firebase from '@firebase/app';
2020
import { FirebaseNamespace } from '@firebase/app-types';
2121
import { _FirebaseNamespace } from '@firebase/app-types/private';
22+
import { Component, ComponentType } from '@firebase/component';
23+
import * as types from '@firebase/database-types';
24+
import { isNodeSdk } from '@firebase/util';
25+
26+
import { name, version } from './package.json';
2227
import { Database, repoManagerDatabaseFromApp } from './src/api/Database';
2328
import { DataSnapshot } from './src/api/DataSnapshot';
29+
import * as INTERNAL from './src/api/internal';
2430
import { Query } from './src/api/Query';
2531
import { Reference } from './src/api/Reference';
26-
import { enableLogging } from './src/core/util/util';
27-
import * as INTERNAL from './src/api/internal';
2832
import * as TEST_ACCESS from './src/api/test_access';
29-
import { isNodeSdk } from '@firebase/util';
30-
import * as types from '@firebase/database-types';
33+
import { enableLogging } from './src/core/util/util';
3134
import { setSDKVersion } from './src/core/version';
32-
import { Component, ComponentType } from '@firebase/component';
33-
34-
import { name, version } from './package.json';
3535

3636
const ServerValue = Database.ServerValue;
3737

packages/database/src/api/DataSnapshot.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
*/
1717

1818
import { validateArgCount, validateCallback } from '@firebase/util';
19-
import { validatePathString } from '../core/util/validation';
20-
import { Path } from '../core/util/Path';
19+
20+
import { ChildrenNode } from '../core/snap/ChildrenNode';
21+
import { Index } from '../core/snap/indexes/Index';
2122
import { PRIORITY_INDEX } from '../core/snap/indexes/PriorityIndex';
2223
import { Node } from '../core/snap/Node';
24+
import { Path } from '../core/util/Path';
25+
import { validatePathString } from '../core/util/validation';
26+
2327
import { Reference } from './Reference';
24-
import { Index } from '../core/snap/indexes/Index';
25-
import { ChildrenNode } from '../core/snap/ChildrenNode';
2628

2729
/**
2830
* Class representing a firebase data snapshot. It wraps a SnapshotNode and

packages/database/src/api/Database.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,27 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
import { FirebaseApp } from '@firebase/app-types';
1817
// eslint-disable-next-line import/no-extraneous-dependencies
1918
import { FirebaseApp as FirebaseAppExp } from '@firebase/app-exp';
20-
import { safeGet, validateArgCount } from '@firebase/util';
21-
import { fatal, log } from '../core/util/util';
22-
import { parseRepoInfo } from '../core/util/libs/parser';
19+
import { FirebaseApp } from '@firebase/app-types';
20+
import { FirebaseService } from '@firebase/app-types/private';
2321
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
2422
import { Provider } from '@firebase/component';
25-
import { pathIsEmpty, newEmptyPath } from '../core/util/Path';
26-
import { Reference } from './Reference';
27-
import { Repo, repoInterrupt, repoResume, repoStart } from '../core/Repo';
28-
import { validateUrl } from '../core/util/validation';
29-
import { FirebaseService } from '@firebase/app-types/private';
30-
import { RepoInfo } from '../core/RepoInfo';
23+
import { safeGet, validateArgCount } from '@firebase/util';
24+
3125
import {
3226
AuthTokenProvider,
3327
EmulatorAdminTokenProvider,
3428
FirebaseAuthTokenProvider
3529
} from '../core/AuthTokenProvider';
30+
import { Repo, repoInterrupt, repoResume, repoStart } from '../core/Repo';
31+
import { RepoInfo } from '../core/RepoInfo';
32+
import { parseRepoInfo } from '../core/util/libs/parser';
33+
import { pathIsEmpty, newEmptyPath } from '../core/util/Path';
34+
import { fatal, log } from '../core/util/util';
35+
import { validateUrl } from '../core/util/validation';
36+
37+
import { Reference } from './Reference';
3638

3739
/**
3840
* This variable is also defined in the firebase node.js admin SDK. Before

0 commit comments

Comments
 (0)