Skip to content

Commit 0f481dc

Browse files
Merge
2 parents 68a413a + 82e793f commit 0f481dc

File tree

149 files changed

+3609
-2889
lines changed

Some content is hidden

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

149 files changed

+3609
-2889
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/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/strange-lions-dress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/storage": patch
3+
---
4+
5+
Error messages for backend errors now include the backend's reponse message.

.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
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
import * as firebase from 'firebase/app';
19+
import 'firebase/firestore';
20+
21+
// This file replaces "packages/firestore/test/integration/util/firebase_export"
22+
// and depends on the minified sources.
23+
24+
let appCount = 0;
25+
26+
export function newTestFirestore(
27+
projectId: string,
28+
nameOrApp?: string | firebase.app.App,
29+
settings?: firebase.firestore.Settings
30+
): firebase.firestore.Firestore {
31+
if (nameOrApp === undefined) {
32+
nameOrApp = 'test-app-' + appCount++;
33+
}
34+
const app =
35+
typeof nameOrApp === 'string'
36+
? firebase.initializeApp({ apiKey: 'fake-api-key', projectId }, nameOrApp)
37+
: nameOrApp;
38+
39+
const firestore = firebase.firestore(app);
40+
if (settings) {
41+
firestore.settings(settings);
42+
}
43+
return firestore;
44+
}
45+
46+
export function usesFunctionalApi(): false {
47+
return false;
48+
}
49+
50+
const Firestore = firebase.firestore.Firestore;
51+
const FieldPath = firebase.firestore.FieldPath;
52+
const Timestamp = firebase.firestore.Timestamp;
53+
const GeoPoint = firebase.firestore.GeoPoint;
54+
const FieldValue = firebase.firestore.FieldValue;
55+
const Blob = firebase.firestore.Blob;
56+
57+
export { Firestore, FieldValue, FieldPath, Timestamp, Blob, GeoPoint };
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
import * as firebase from 'firebase/app';
19+
import 'firebase/firestore/memory';
20+
21+
// This file replaces "packages/firestore/test/integration/util/firebase_export"
22+
// and depends on the minified sources.
23+
24+
let appCount = 0;
25+
26+
export function newTestFirestore(
27+
projectId: string,
28+
nameOrApp?: string | firebase.app.App,
29+
settings?: firebase.firestore.Settings
30+
): firebase.firestore.Firestore {
31+
if (nameOrApp === undefined) {
32+
nameOrApp = 'test-app-' + appCount++;
33+
}
34+
const app =
35+
typeof nameOrApp === 'string'
36+
? firebase.initializeApp({ apiKey: 'fake-api-key', projectId }, nameOrApp)
37+
: nameOrApp;
38+
39+
const firestore = firebase.firestore(app);
40+
if (settings) {
41+
firestore.settings(settings);
42+
}
43+
return firestore;
44+
}
45+
46+
export function usesFunctionalApi(): false {
47+
return false;
48+
}
49+
50+
const Firestore = firebase.firestore.Firestore;
51+
const FieldPath = firebase.firestore.FieldPath;
52+
const Timestamp = firebase.firestore.Timestamp;
53+
const GeoPoint = firebase.firestore.GeoPoint;
54+
const FieldValue = firebase.firestore.FieldValue;
55+
const Blob = firebase.firestore.Blob;
56+
57+
export { Firestore, FieldValue, FieldPath, Timestamp, Blob, GeoPoint };

integration/firestore/gulpfile.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ function copyTests() {
3838
* Therefore these tests and helpers cannot have any src/ dependencies.
3939
*/
4040
const testBase = resolve(__dirname, '../../packages/firestore/test');
41-
const firebaseAppSdk = 'firebase/app/dist/index.esm.js';
42-
const firebaseFirestoreSdk = resolve(
43-
__dirname,
44-
isPersistenceEnabled()
45-
? '../../packages/firestore/dist/index.esm.js'
46-
: '../../packages/firestore/dist/index.memory.esm.js'
47-
);
4841
return gulp
4942
.src(
5043
[
@@ -63,21 +56,24 @@ function copyTests() {
6356
* This regex is designed to match the following statement used in our
6457
* firestore integration test suites:
6558
*
66-
* import firebase from '../../util/firebase_export';
59+
* import * as firebaseExport from '../../util/firebase_export';
6760
*
6861
* It will handle variations in whitespace, single/double quote
6962
* differences, as well as different paths to a valid firebase_export
7063
*/
71-
/import\s+firebase\s+from\s+('|")[^\1]+firebase_export\1;?/,
72-
`import firebase from '${firebaseAppSdk}';
73-
import '${firebaseFirestoreSdk}';
74-
64+
/import\s+\* as firebaseExport\s+from\s+('|")[^\1]+firebase_export\1;?/,
65+
`import * as firebaseExport from '${resolve(
66+
__dirname,
67+
isPersistenceEnabled()
68+
? './firebase_export'
69+
: './firebase_export_memory'
70+
)}';
71+
7572
if (typeof process === 'undefined') {
7673
process = { env: { INCLUDE_FIRESTORE_PERSISTENCE: '${isPersistenceEnabled()}' } } as any;
7774
} else {
7875
process.env.INCLUDE_FIRESTORE_PERSISTENCE = '${isPersistenceEnabled()}';
79-
}
80-
`
76+
}`
8177
)
8278
)
8379
.pipe(

integration/firestore/package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
{
22
"name": "firebase-firestore-integration-test",
33
"version": "1.0.1",
4-
"private": true,
4+
"private": true,
55
"scripts": {
6-
"build:deps": "cd ../../packages/firestore ; yarn build",
6+
"build:deps": "lerna run --scope @firebase/'{app,firestore}' --include-dependencies build",
77
"build:persistence": "INCLUDE_FIRESTORE_PERSISTENCE=true gulp compile-tests",
88
"build:memory": "INCLUDE_FIRESTORE_PERSISTENCE=false gulp compile-tests",
99
"test": "yarn build:memory; karma start --single-run; yarn build:persistence; karma start --single-run;",
1010
"test:ci": "node ../../scripts/run_tests_in_ci.js",
1111
"test:persistence": " yarn build:persistence; karma start --single-run",
12+
"test:persistence:debug:": "yarn build:persistence; karma start --auto-watch --browsers Chrome",
1213
"test:memory": "yarn build:memory; karma start --single-run",
13-
"test:debug:persistence": "yarn build:deps; yarn build:persistence; karma start --auto-watch --browsers Chrome",
14-
"test:debug:memory": "yarn build:deps; yarn build:memory; karma start --single-run"
14+
"test:memory:debug": "yarn build:memory; karma start --auto-watch --browsers Chrome"
15+
},
16+
"peerDependencies": {
17+
"@firebase/app": "0.x",
18+
"@firebase/firestore": "0.x"
1519
},
1620
"devDependencies": {
1721
"@types/mocha": "7.0.2",

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-exp/app-exp/src/api.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,11 @@ export async function deleteApp(app: FirebaseApp): Promise<void> {
213213
const name = app.name;
214214
if (_apps.has(name)) {
215215
_apps.delete(name);
216-
await (app as _FirebaseAppInternal).container
217-
.getProviders()
218-
.map(provider => provider.delete());
216+
await Promise.all(
217+
(app as _FirebaseAppInternal).container
218+
.getProviders()
219+
.map(provider => provider.delete())
220+
);
219221
(app as _FirebaseAppInternal).isDeleted = true;
220222
}
221223
}

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+
}

0 commit comments

Comments
 (0)