Skip to content

Commit 4b417af

Browse files
EhespkolotumjorgeronceroLyokoneSalakar
authored
feat(web): upgrade to support v9.8.1 Firebase JS SDK (#8235)
Co-authored-by: Elliot Hesp <[email protected]> Co-authored-by: Benjamin Koch <[email protected]> Co-authored-by: Jorge Roncero <[email protected]> Co-authored-by: Guillaume Bernos <[email protected]> Co-authored-by: Mike Diarmid <[email protected]> Co-authored-by: Nils Reichardt <[email protected]> Co-authored-by: Russell Wheatley <[email protected]>
1 parent c70e66a commit 4b417af

File tree

65 files changed

+1584
-1107
lines changed

Some content is hidden

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

65 files changed

+1584
-1107
lines changed

packages/cloud_firestore/cloud_firestore/example/test_driver/cloud_firestore_e2e.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'timestamp_e2e.dart';
2020
import 'transaction_e2e.dart';
2121
import 'write_batch_e2e.dart';
2222
import 'load_bundle_e2e.dart';
23+
import 'second_app_e2e.dart';
2324

2425
bool kUseFirestoreEmulator = true;
2526

@@ -45,6 +46,7 @@ void testsMain() {
4546
runTransactionTests();
4647
runWriteBatchTests();
4748
runLoadBundleTests();
49+
runSecondAppTests();
4850
}
4951

5052
void main() => drive.main(testsMain);
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// File generated by FlutterFire CLI.
2+
// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members
3+
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
4+
import 'package:flutter/foundation.dart'
5+
show defaultTargetPlatform, kIsWeb, TargetPlatform;
6+
7+
/// Default [FirebaseOptions] for use with your Firebase apps.
8+
///
9+
/// Example:
10+
/// ```dart
11+
/// import 'firebase_options_secondary.dart';
12+
/// // ...
13+
/// await Firebase.initializeApp(
14+
/// options: DefaultFirebaseOptions.currentPlatform,
15+
/// );
16+
/// ```
17+
class DefaultFirebaseOptions {
18+
static FirebaseOptions get currentPlatform {
19+
if (kIsWeb) {
20+
return web;
21+
}
22+
switch (defaultTargetPlatform) {
23+
case TargetPlatform.android:
24+
return android;
25+
case TargetPlatform.iOS:
26+
return ios;
27+
case TargetPlatform.macOS:
28+
return macos;
29+
default:
30+
throw UnsupportedError(
31+
'DefaultFirebaseOptions are not supported for this platform.',
32+
);
33+
}
34+
}
35+
36+
static const FirebaseOptions web = FirebaseOptions(
37+
apiKey: 'AIzaSyAFh7c37C6MyAVwRJylz7EwvzZSECqmcus',
38+
appId: '1:866672724757:web:3a0fad9cba4848ea19f71c',
39+
messagingSenderId: '866672724757',
40+
projectId: 'flutterfire-e2e-tests-2',
41+
authDomain: 'flutterfire-e2e-tests-2.firebaseapp.com',
42+
storageBucket: 'flutterfire-e2e-tests-2.appspot.com',
43+
);
44+
45+
static const FirebaseOptions android = FirebaseOptions(
46+
apiKey: 'AIzaSyAMoRmAcD_NW0DVoO40ThJO1zDF2vDB7Rs',
47+
appId: '1:866672724757:android:d069b410181b65cf19f71c',
48+
messagingSenderId: '866672724757',
49+
projectId: 'flutterfire-e2e-tests-2',
50+
storageBucket: 'flutterfire-e2e-tests-2.appspot.com',
51+
);
52+
53+
static const FirebaseOptions ios = FirebaseOptions(
54+
apiKey: 'AIzaSyDfWh055gUcnS6_Gqd_Jjwy7boVm5_E8oI',
55+
appId: '1:866672724757:ios:142139d84dda4ed419f71c',
56+
messagingSenderId: '866672724757',
57+
projectId: 'flutterfire-e2e-tests-2',
58+
storageBucket: 'flutterfire-e2e-tests-2.appspot.com',
59+
iosClientId:
60+
'866672724757-rncbdu3qrn0j423e1tfk2jg7jdvrhd8i.apps.googleusercontent.com',
61+
iosBundleId: 'io.flutter.plugins.firebase.firestoreExample',
62+
);
63+
64+
static const FirebaseOptions macos = FirebaseOptions(
65+
apiKey: 'AIzaSyDfWh055gUcnS6_Gqd_Jjwy7boVm5_E8oI',
66+
appId: '1:866672724757:ios:3e35357fc677cc5719f71c',
67+
messagingSenderId: '866672724757',
68+
projectId: 'flutterfire-e2e-tests-2',
69+
storageBucket: 'flutterfire-e2e-tests-2.appspot.com',
70+
iosClientId:
71+
'866672724757-fup6o8riklmmc7mbo3b1jolbeadbb84m.apps.googleusercontent.com',
72+
iosBundleId: 'io.flutter.plugins.firebase.firestore.example',
73+
);
74+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2020, the Chromium project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:cloud_firestore/cloud_firestore.dart';
6+
import 'package:firebase_core/firebase_core.dart';
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
import 'firebase_options_secondary.dart';
10+
11+
void runSecondAppTests() {
12+
group('$FirebaseFirestore', () {
13+
late FirebaseFirestore firestore;
14+
late FirebaseFirestore secondFirestoreProject;
15+
16+
setUpAll(() async {
17+
firestore = FirebaseFirestore.instance;
18+
FirebaseApp secondApp = await Firebase.initializeApp(
19+
name: 'secondApp',
20+
options: DefaultFirebaseOptions.currentPlatform,
21+
);
22+
secondFirestoreProject = FirebaseFirestore.instanceFor(
23+
app: secondApp,
24+
);
25+
});
26+
27+
group('Secondary app Firestore instance', () {
28+
test(
29+
'Second Firestore instance should fail due to firestore.rules forbidding data writes',
30+
() async {
31+
// successful write on default app instance
32+
await firestore
33+
.collection('flutter-tests/banned/doc')
34+
.add({'foo': 'bar'});
35+
36+
// permission denied on second app with Firebase that denies database writes
37+
await expectLater(
38+
secondFirestoreProject
39+
.collection('flutter-tests/banned/doc')
40+
.add({'foo': 'bar'}),
41+
throwsA(
42+
isA<FirebaseException>()
43+
.having((e) => e.code, 'code', 'permission-denied'),
44+
),
45+
);
46+
});
47+
});
48+
});
49+
}

packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/settings.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Use of this source code is governed by a BSD-style license that can be
44
// found in the LICENSE file.
55

6-
import 'package:flutter/material.dart';
6+
import 'package:flutter/foundation.dart';
77

88
/// Specifies custom configurations for your Cloud Firestore instance.
99
///
@@ -16,6 +16,7 @@ class Settings {
1616
this.host,
1717
this.sslEnabled,
1818
this.cacheSizeBytes,
19+
this.ignoreUndefinedProperties = false,
1920
});
2021

2122
/// Constant used to indicate the LRU garbage collection should be disabled.
@@ -44,13 +45,21 @@ class Settings {
4445
/// and can be set to [Settings.CACHE_SIZE_UNLIMITED] to disable garbage collection.
4546
final int? cacheSizeBytes;
4647

48+
/// Whether to skip nested properties that are set to undefined during object serialization.
49+
///
50+
/// If set to true, these properties are skipped and not written to Firestore. If set to false
51+
/// or omitted, the SDK throws an exception when it encounters properties of type undefined.
52+
/// Web only.
53+
final bool ignoreUndefinedProperties;
54+
4755
/// Returns the settings as a [Map]
4856
Map<String, dynamic> get asMap {
4957
return {
5058
'persistenceEnabled': persistenceEnabled,
5159
'host': host,
5260
'sslEnabled': sslEnabled,
53-
'cacheSizeBytes': cacheSizeBytes
61+
'cacheSizeBytes': cacheSizeBytes,
62+
if (kIsWeb) 'ignoreUndefinedProperties': ignoreUndefinedProperties,
5463
};
5564
}
5665

@@ -59,12 +68,15 @@ class Settings {
5968
String? host,
6069
bool? sslEnabled,
6170
int? cacheSizeBytes,
71+
bool? ignoreUndefinedProperties,
6272
}) =>
6373
Settings(
6474
persistenceEnabled: persistenceEnabled ?? this.persistenceEnabled,
6575
host: host ?? this.host,
6676
sslEnabled: sslEnabled ?? this.sslEnabled,
6777
cacheSizeBytes: cacheSizeBytes ?? this.cacheSizeBytes,
78+
ignoreUndefinedProperties:
79+
ignoreUndefinedProperties ?? this.ignoreUndefinedProperties,
6880
);
6981

7082
@override
@@ -74,7 +86,8 @@ class Settings {
7486
other.persistenceEnabled == persistenceEnabled &&
7587
other.host == host &&
7688
other.sslEnabled == sslEnabled &&
77-
other.cacheSizeBytes == cacheSizeBytes;
89+
other.cacheSizeBytes == cacheSizeBytes &&
90+
other.ignoreUndefinedProperties == ignoreUndefinedProperties;
7891

7992
@override
8093
int get hashCode => Object.hash(
@@ -83,6 +96,7 @@ class Settings {
8396
host,
8497
sslEnabled,
8598
cacheSizeBytes,
99+
ignoreUndefinedProperties,
86100
);
87101

88102
@override

packages/cloud_firestore/cloud_firestore_web/lib/cloud_firestore_web.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ class FirebaseFirestoreWeb extends FirebaseFirestorePlatform {
2929
/// instance of Analytics from the web plugin
3030
firestore_interop.Firestore? _webFirestore;
3131

32+
firestore_interop.Settings? _settings;
33+
3234
/// Lazily initialize [_webFirestore] on first method call
3335
firestore_interop.Firestore get _delegate {
34-
return _webFirestore ??=
35-
firestore_interop.getFirestoreInstance(core_interop.app(app.name));
36+
return _webFirestore ??= firestore_interop.getFirestoreInstance(
37+
core_interop.app(app.name), _settings);
3638
}
3739

3840
/// Called by PluginRegistry to register this plugin for Flutter Web
@@ -120,7 +122,6 @@ class FirebaseFirestoreWeb extends FirebaseFirestorePlatform {
120122
@override
121123
set settings(Settings settings) {
122124
int? cacheSizeBytes;
123-
124125
if (settings.cacheSizeBytes == null) {
125126
cacheSizeBytes = 40000000;
126127
} else if (settings.cacheSizeBytes == Settings.CACHE_SIZE_UNLIMITED) {
@@ -131,13 +132,17 @@ class FirebaseFirestoreWeb extends FirebaseFirestorePlatform {
131132
}
132133

133134
if (settings.host != null && settings.sslEnabled != null) {
134-
_delegate.settings(firestore_interop.Settings(
135-
cacheSizeBytes: cacheSizeBytes,
136-
host: settings.host,
137-
ssl: settings.sslEnabled));
135+
_settings = firestore_interop.Settings(
136+
cacheSizeBytes: cacheSizeBytes,
137+
host: settings.host,
138+
ssl: settings.sslEnabled,
139+
ignoreUndefinedProperties: settings.ignoreUndefinedProperties,
140+
);
138141
} else {
139-
_delegate
140-
.settings(firestore_interop.Settings(cacheSizeBytes: cacheSizeBytes));
142+
_settings = firestore_interop.Settings(
143+
cacheSizeBytes: cacheSizeBytes,
144+
ignoreUndefinedProperties: settings.ignoreUndefinedProperties,
145+
);
141146
}
142147
}
143148

packages/cloud_firestore/cloud_firestore_web/lib/src/interop/firebase_interop.dart

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

0 commit comments

Comments
 (0)