Skip to content

Commit fc11280

Browse files
Merge branch 'master' into mrschmidt/sharedtests
2 parents bba69f1 + a875bbe commit fc11280

File tree

88 files changed

+2334
-1849
lines changed

Some content is hidden

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

88 files changed

+2334
-1849
lines changed

.changeset/clean-numbers-flow.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@firebase/analytics": minor
3+
"firebase": minor
4+
---
5+
6+
Issue 2393 fix - analytics module
7+
8+
- Added a public method `isSupported` to Analytics module which returns true if current browser context supports initialization of analytics module.
9+
- Added runtime checks to Analytics module that validate if cookie is enabled in current browser and if current browser environment supports indexedDB functionalities.

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3-
"changelog": ["@changesets/changelog-github", { "repo": "firebase/firebase-js-sdk"}],
3+
"changelog": ["../repo-scripts/changelog-generator", { "repo": "firebase/firebase-js-sdk"}],
44
"commit": false,
55
"linked": [],
66
"access": "public",

.changeset/friendly-crews-dream.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

.changeset/gorgeous-beers-build.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

.changeset/late-ladybugs-wash.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

.changeset/nice-deers-suffer.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

.changeset/popular-cups-melt.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

.changeset/rotten-owls-drive.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

.changeset/smart-cars-doubt.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

.changeset/thick-rabbits-guess.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

.changeset/wild-otters-fly.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

integration/browserify/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"test:ci": "node ../../scripts/run_tests_in_ci.js"
99
},
1010
"devDependencies": {
11-
"firebase": "7.16.0",
11+
"firebase": "7.16.1",
1212
"@babel/core": "7.10.4",
1313
"@babel/preset-env": "7.10.4",
1414
"browserify": "16.5.1",

integration/firebase-typings/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"test:ci": "node ../../scripts/run_tests_in_ci.js"
88
},
99
"devDependencies": {
10-
"firebase": "7.16.0",
10+
"firebase": "7.16.1",
1111
"typescript": "3.9.6"
1212
}
1313
}

integration/messaging/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"test:manual": "mocha --exit"
99
},
1010
"devDependencies": {
11-
"firebase": "7.16.0",
11+
"firebase": "7.16.1",
1212
"chai": "4.2.0",
1313
"chromedriver": "83.0.1",
1414
"express": "4.17.1",

integration/typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"test:ci": "node ../../scripts/run_tests_in_ci.js"
88
},
99
"devDependencies": {
10-
"firebase": "7.16.0",
10+
"firebase": "7.16.1",
1111
"@babel/core": "7.10.4",
1212
"@babel/preset-env": "7.10.4",
1313
"@types/chai": "4.2.11",

integration/webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"test:ci": "node ../../scripts/run_tests_in_ci.js"
99
},
1010
"devDependencies": {
11-
"firebase": "7.16.0",
11+
"firebase": "7.16.1",
1212
"@babel/core": "7.10.4",
1313
"@babel/preset-env": "7.10.4",
1414
"chai": "4.2.0",

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"lint": "lerna run --scope @firebase/* --scope rxfire lint",
4949
"size-report": "node scripts/report_binary_size.js",
5050
"api-report": "lerna run --scope @firebase/*-exp api-report",
51-
"docgen:exp": "node scripts/exp/docgen.js"
51+
"docgen:exp": "node scripts/exp/docgen.js",
52+
"postinstall": "yarn --cwd repo-scripts/changelog-generator build"
5253
},
5354
"repository": {
5455
"type": "git",
@@ -57,7 +58,8 @@
5758
"workspaces": [
5859
"packages/*",
5960
"packages-exp/*",
60-
"integration/*"
61+
"integration/*",
62+
"repo-scripts/*"
6163
],
6264
"devDependencies": {
6365
"@changesets/changelog-github": "0.2.6",

packages/analytics/index.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ import {
3232
ComponentContainer
3333
} from '@firebase/component';
3434
import { ERROR_FACTORY, AnalyticsError } from './src/errors';
35-
35+
import {
36+
isIndexedDBAvailable,
37+
validateIndexedDBOpenable,
38+
areCookiesEnabled
39+
} from '@firebase/util';
3640
import { name, version } from './package.json';
3741

3842
declare global {
@@ -45,6 +49,7 @@ declare global {
4549
* Type constant for Firebase Analytics.
4650
*/
4751
const ANALYTICS_TYPE = 'analytics';
52+
4853
export function registerAnalytics(instance: _FirebaseNamespace): void {
4954
instance.INTERNAL.registerComponent(
5055
new Component(
@@ -55,13 +60,13 @@ export function registerAnalytics(instance: _FirebaseNamespace): void {
5560
const installations = container
5661
.getProvider('installations')
5762
.getImmediate();
58-
5963
return factory(app, installations);
6064
},
6165
ComponentType.PUBLIC
6266
).setServiceProps({
6367
settings,
64-
EventName
68+
EventName,
69+
isSupported
6570
})
6671
);
6772

@@ -97,8 +102,31 @@ registerAnalytics(firebase as _FirebaseNamespace);
97102
declare module '@firebase/app-types' {
98103
interface FirebaseNamespace {
99104
analytics(app?: FirebaseApp): FirebaseAnalytics;
105+
isSupported(): Promise<boolean>;
100106
}
101107
interface FirebaseApp {
102108
analytics(): FirebaseAnalytics;
103109
}
104110
}
111+
112+
/**
113+
* this is a public static method provided to users that wraps three different checks:
114+
*
115+
* 1. check if cookie is enabled in current browser.
116+
* 2. check if IndexedDB is supported by the browser environment.
117+
* 3. check if the current browser context is valid for using IndexedDB.
118+
*/
119+
async function isSupported(): Promise<boolean> {
120+
if (!areCookiesEnabled()) {
121+
return false;
122+
}
123+
if (!isIndexedDBAvailable()) {
124+
return false;
125+
}
126+
try {
127+
const isDBOpenable: boolean = await validateIndexedDBOpenable();
128+
return isDBOpenable;
129+
} catch (error) {
130+
return false;
131+
}
132+
}

packages/analytics/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@
5656
],
5757
"reportDir": "./coverage/node"
5858
}
59-
}
59+
}

packages/analytics/src/errors.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export const enum AnalyticsError {
2222
NO_GA_ID = 'no-ga-id',
2323
ALREADY_EXISTS = 'already-exists',
2424
ALREADY_INITIALIZED = 'already-initialized',
25-
INTEROP_COMPONENT_REG_FAILED = 'interop-component-reg-failed'
25+
INTEROP_COMPONENT_REG_FAILED = 'interop-component-reg-failed',
26+
INDEXED_DB_UNSUPPORTED = 'indexedDB-unsupported',
27+
INVALID_INDEXED_DB_CONTEXT = 'invalid-indexedDB-context',
28+
COOKIES_NOT_ENABLED = 'cookies-not-enabled'
2629
}
2730

2831
const ERRORS: ErrorMap<AnalyticsError> = {
@@ -39,12 +42,21 @@ const ERRORS: ErrorMap<AnalyticsError> = {
3942
'settings() must be called before initializing any Analytics instance' +
4043
'or it will have no effect.',
4144
[AnalyticsError.INTEROP_COMPONENT_REG_FAILED]:
42-
'Firebase Analytics Interop Component failed to instantiate'
45+
'Firebase Analytics Interop Component failed to instantiate',
46+
[AnalyticsError.INDEXED_DB_UNSUPPORTED]:
47+
'IndexedDB is not supported by current browswer',
48+
[AnalyticsError.INVALID_INDEXED_DB_CONTEXT]:
49+
"Environment doesn't support IndexedDB: {$errorInfo}. " +
50+
'Wrap initialization of analytics in analytics.isSupported() ' +
51+
'to prevent initialization in unsupported environments',
52+
[AnalyticsError.COOKIES_NOT_ENABLED]:
53+
'Cookies are not enabled in this browser environment. Analytics requires cookies to be enabled.'
4354
};
4455

4556
interface ErrorParams {
4657
[AnalyticsError.ALREADY_EXISTS]: { id: string };
4758
[AnalyticsError.INTEROP_COMPONENT_REG_FAILED]: { reason: Error };
59+
[AnalyticsError.INVALID_INDEXED_DB_CONTEXT]: { errorInfo: string };
4860
}
4961

5062
export const ERROR_FACTORY = new ErrorFactory<AnalyticsError, ErrorParams>(

packages/analytics/src/factory.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ import { ANALYTICS_ID_FIELD } from './constants';
3838
import { AnalyticsError, ERROR_FACTORY } from './errors';
3939
import { FirebaseApp } from '@firebase/app-types';
4040
import { FirebaseInstallations } from '@firebase/installations-types';
41+
import {
42+
isIndexedDBAvailable,
43+
validateIndexedDBOpenable,
44+
areCookiesEnabled
45+
} from '@firebase/util';
4146

4247
/**
4348
* Maps gaId to FID fetch promises.
@@ -117,6 +122,19 @@ export function factory(
117122
app: FirebaseApp,
118123
installations: FirebaseInstallations
119124
): FirebaseAnalytics {
125+
if (!areCookiesEnabled()) {
126+
throw ERROR_FACTORY.create(AnalyticsError.COOKIES_NOT_ENABLED);
127+
}
128+
if (!isIndexedDBAvailable()) {
129+
throw ERROR_FACTORY.create(AnalyticsError.INDEXED_DB_UNSUPPORTED);
130+
}
131+
// Async but non-blocking.
132+
validateIndexedDBOpenable().catch(error => {
133+
throw ERROR_FACTORY.create(AnalyticsError.INVALID_INDEXED_DB_CONTEXT, {
134+
errorInfo: error
135+
});
136+
});
137+
120138
const analyticsId = app.options[ANALYTICS_ID_FIELD];
121139
if (!analyticsId) {
122140
throw ERROR_FACTORY.create(AnalyticsError.NO_GA_ID);

packages/analytics/src/helpers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import {
3232
} from './constants';
3333
import { FirebaseInstallations } from '@firebase/installations-types';
3434
import { logger } from './logger';
35-
3635
/**
3736
* Initialize the analytics instance in gtag.js by calling config command with fid.
3837
*

packages/auth/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# @firebase/auth
22

3-
## 0.14.8
3+
## 0.14.9
4+
45
### Patch Changes
56

7+
- [`b6145466`](https://github.com/firebase/firebase-js-sdk/commit/b6145466835e22495b94d2bcfc45813e81496085) [#3401](https://github.com/firebase/firebase-js-sdk/pull/3401) Thanks [@Feiyang1](https://github.com/Feiyang1)! - Add browser field in package.json
68

9+
## 0.14.8
10+
11+
### Patch Changes
712

813
- [`a754645e`](https://github.com/firebase/firebase-js-sdk/commit/a754645ec2be1b8c205f25f510196eee298b0d6e) [#3297](https://github.com/firebase/firebase-js-sdk/pull/3297) Thanks [@renovate](https://github.com/apps/renovate)! - Update dependency typescript to v3.9.5

packages/auth/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "@firebase/auth",
3-
"version": "0.14.8",
3+
"version": "0.14.9",
44
"main": "dist/auth.js",
5+
"browser": "dist/auth.js",
56
"module": "dist/auth.esm.js",
67
"description": "Javascript library for Firebase Auth SDK",
78
"author": "Firebase <[email protected]> (https://firebase.google.com/)",

packages/database/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Unreleased
22

3+
## 0.6.8
4+
5+
### Patch Changes
6+
7+
- [`c2b737b2`](https://github.com/firebase/firebase-js-sdk/commit/c2b737b2187cb525af4d926ca477102db7835420) [#3228](https://github.com/firebase/firebase-js-sdk/pull/3228) Thanks [@schmidt-sebastian](https://github.com/schmidt-sebastian)! - [fix] Instead of using production auth, the SDK will use test credentials
8+
to connect to the Emulator when the RTDB SDK is used via the Firebase
9+
Admin SDK.
10+
311
## 0.6.7
412

513
### Patch Changes

packages/database/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@firebase/database",
3-
"version": "0.6.7",
3+
"version": "0.6.8",
44
"description": "",
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"main": "dist/index.node.cjs.js",

packages/database/src/core/AuthTokenProvider.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@ import { Provider } from '@firebase/component';
2424
import { log, warn } from './util/util';
2525
import { FirebaseApp } from '@firebase/app-types';
2626

27+
export interface AuthTokenProvider {
28+
getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData>;
29+
addTokenChangeListener(listener: (token: string | null) => void): void;
30+
removeTokenChangeListener(listener: (token: string | null) => void): void;
31+
notifyForInvalidToken(): void;
32+
}
33+
2734
/**
2835
* Abstraction around FirebaseApp's token fetching capabilities.
2936
*/
30-
export class AuthTokenProvider {
37+
export class FirebaseAuthTokenProvider implements AuthTokenProvider {
3138
private auth_: FirebaseAuthInternal | null = null;
3239
constructor(
3340
private app_: FirebaseApp,
@@ -60,7 +67,7 @@ export class AuthTokenProvider {
6067
});
6168
}
6269

63-
addTokenChangeListener(listener: (token: string | null) => void) {
70+
addTokenChangeListener(listener: (token: string | null) => void): void {
6471
// TODO: We might want to wrap the listener and call it with no args to
6572
// avoid a leaky abstraction, but that makes removing the listener harder.
6673
if (this.auth_) {
@@ -73,13 +80,13 @@ export class AuthTokenProvider {
7380
}
7481
}
7582

76-
removeTokenChangeListener(listener: (token: string | null) => void) {
83+
removeTokenChangeListener(listener: (token: string | null) => void): void {
7784
this.authProvider_
7885
.get()
7986
.then(auth => auth.removeAuthTokenListener(listener));
8087
}
8188

82-
notifyForInvalidToken() {
89+
notifyForInvalidToken(): void {
8390
let errorMessage =
8491
'Provided authentication credentials for the app named "' +
8592
this.app_.name +
@@ -104,3 +111,24 @@ export class AuthTokenProvider {
104111
warn(errorMessage);
105112
}
106113
}
114+
115+
/* Auth token provider that the Admin SDK uses to connect to the Emulator. */
116+
export class EmulatorAdminTokenProvider implements AuthTokenProvider {
117+
private static EMULATOR_AUTH_TOKEN = 'owner';
118+
119+
getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData> {
120+
return Promise.resolve({
121+
accessToken: EmulatorAdminTokenProvider.EMULATOR_AUTH_TOKEN
122+
});
123+
}
124+
125+
addTokenChangeListener(listener: (token: string | null) => void): void {
126+
// Invoke the listener immediately to match the behavior in Firebase Auth
127+
// (see packages/auth/src/auth.js#L1807)
128+
listener(EmulatorAdminTokenProvider.EMULATOR_AUTH_TOKEN);
129+
}
130+
131+
removeTokenChangeListener(listener: (token: string | null) => void): void {}
132+
133+
notifyForInvalidToken(): void {}
134+
}

0 commit comments

Comments
 (0)