@react-native-firebase/app-check 26.4.0 → 27.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/RNFBAppCheck.podspec +8 -2
  3. package/android/build.gradle +3 -0
  4. package/android/src/main/java/io/invertase/firebase/appcheck/RNFBAppCheckListenerRegistry.kt +72 -0
  5. package/dist/module/index.js +1 -2
  6. package/dist/module/index.js.map +1 -1
  7. package/dist/module/version.js +1 -1
  8. package/dist/typescript/lib/index.d.ts +1 -1
  9. package/dist/typescript/lib/index.d.ts.map +1 -1
  10. package/dist/typescript/lib/version.d.ts +1 -1
  11. package/ios/RNFBAppCheck/RNFBAppCheckHelper.h +61 -0
  12. package/ios/RNFBAppCheck/RNFBAppCheckHelper.m +213 -0
  13. package/ios/RNFBAppCheck/RNFBAppCheckModule.mm +22 -155
  14. package/ios/RNFBAppCheck/RNFBAppCheckRejectCodeMapper.swift +50 -0
  15. package/ios/RNFBAppCheck.xcodeproj/project.pbxproj +14 -0
  16. package/ios/RNFBAppCheckUnitTests/HostStubs/Firebase/FIRAppCheckHostStub.m +109 -0
  17. package/ios/RNFBAppCheckUnitTests/HostStubs/Firebase/Firebase.h +47 -0
  18. package/ios/RNFBAppCheckUnitTests/HostStubs/RNFBApp/RCTConvert+FIRApp.h +13 -0
  19. package/ios/RNFBAppCheckUnitTests/HostStubs/RNFBApp/RCTConvert+FIRAppHostStub.m +27 -0
  20. package/ios/RNFBAppCheckUnitTests/HostStubs/RNFBApp/RNFBSharedUtils.h +18 -0
  21. package/ios/RNFBAppCheckUnitTests/HostStubs/RNFBApp/RNFBSharedUtilsHostStub.m +18 -0
  22. package/ios/RNFBAppCheckUnitTests/HostStubs/RNFBAppCheck/RNFBAppCheckProviderHostStub.m +48 -0
  23. package/ios/RNFBAppCheckUnitTests/HostStubs/React/RCTBridgeModule.h +10 -0
  24. package/ios/RNFBAppCheckUnitTests/RNFBAppCheckHelperHostStubTests.m +197 -0
  25. package/ios/RNFBAppCheckUnitTests/RNFBAppCheckRejectCodeMapperTests.swift +85 -0
  26. package/ios/RNFBAppCheckUnitTests/RNFBAppCheckUnitTests.xcodeproj/project.pbxproj +277 -0
  27. package/ios/RNFBAppCheckUnitTests/RNFBAppCheckUnitTests.xcodeproj/xcshareddata/xcschemes/RNFBAppCheckUnitTests.xcscheme +69 -0
  28. package/lib/index.ts +1 -1
  29. package/lib/version.ts +1 -1
  30. package/package.json +4 -4
  31. package/plugin/build/ios/appDelegate.js +12 -13
  32. package/plugin/src/ios/appDelegate.ts +13 -14
  33. package/android/src/main/java/io/invertase/firebase/appcheck/RNFBAppCheckListenerRegistry.java +0 -76
@@ -112,21 +112,20 @@ function modifySwiftAppDelegate(contents) {
112
112
  if (contents.includes('RNFBAppCheckModule.sharedInstance()')) {
113
113
  return contents;
114
114
  }
115
- // Find the Firebase initialization end line to insert after
116
- const firebaseLine = '// @generated end @react-native-firebase/app-didFinishLaunchingWithOptions';
117
- if (contents.includes(firebaseLine)) {
118
- // Insert right after Firebase initialization
119
- return contents.replace(firebaseLine, `${firebaseLine}
120
- RNFBAppCheckModule.sharedInstance()
121
- FirebaseApp.configure()
122
- `);
123
- }
124
- // If Firebase initialization block not found, register the App Check provider factory
125
- // then call FirebaseApp.configure(). Firebase requires the factory before configure
126
- // (AppCheck-AD-3); do not reverse this order.
115
+ // App plugin (or an earlier pass) already calls configure. The provider factory must
116
+ // run before that call. Do not append a second FirebaseApp.configure().
117
+ const existingConfigure = /^([ \t]*)FirebaseApp\.configure\(\)/m.exec(contents);
118
+ if (existingConfigure) {
119
+ const indent = existingConfigure[1];
120
+ return contents.replace(existingConfigure[0], `${indent}RNFBAppCheckModule.sharedInstance()\n${existingConfigure[0]}`);
121
+ }
122
+ // No configure yet. Register the factory, then configure. Firebase requires the
123
+ // factory before configure (AppCheck-AD-3). Expo 58 scene AppDelegates start
124
+ // React Native from SceneDelegate, so the anchor is the didFinishLaunching return
125
+ // rather than factory.startReactNative.
127
126
  const methodInvocationBlock = `RNFBAppCheckModule.sharedInstance()
128
127
  FirebaseApp.configure()`;
129
- const methodInvocationLineMatcher = /(?:factory\.startReactNative\()/;
128
+ const methodInvocationLineMatcher = /(?:factory\.startReactNative\()|(?:return\s+super\.application\(\s*application\s*,\s*didFinishLaunchingWithOptions:\s*launchOptions\s*\))/;
130
129
  if (!methodInvocationLineMatcher.test(contents)) {
131
130
  config_plugins_1.WarningAggregator.addWarningIOS('@react-native-firebase/app-check', 'Unable to determine correct insertion point in AppDelegate.swift. Skipping App Check addition.');
132
131
  return contents;
@@ -127,27 +127,26 @@ export function modifySwiftAppDelegate(contents: string): string {
127
127
  return contents;
128
128
  }
129
129
 
130
- // Find the Firebase initialization end line to insert after
131
- const firebaseLine = '// @generated end @react-native-firebase/app-didFinishLaunchingWithOptions';
132
-
133
- if (contents.includes(firebaseLine)) {
134
- // Insert right after Firebase initialization
130
+ // App plugin (or an earlier pass) already calls configure. The provider factory must
131
+ // run before that call. Do not append a second FirebaseApp.configure().
132
+ const existingConfigure = /^([ \t]*)FirebaseApp\.configure\(\)/m.exec(contents);
133
+ if (existingConfigure) {
134
+ const indent = existingConfigure[1];
135
135
  return contents.replace(
136
- firebaseLine,
137
- `${firebaseLine}
138
- RNFBAppCheckModule.sharedInstance()
139
- FirebaseApp.configure()
140
- `,
136
+ existingConfigure[0],
137
+ `${indent}RNFBAppCheckModule.sharedInstance()\n${existingConfigure[0]}`,
141
138
  );
142
139
  }
143
140
 
144
- // If Firebase initialization block not found, register the App Check provider factory
145
- // then call FirebaseApp.configure(). Firebase requires the factory before configure
146
- // (AppCheck-AD-3); do not reverse this order.
141
+ // No configure yet. Register the factory, then configure. Firebase requires the
142
+ // factory before configure (AppCheck-AD-3). Expo 58 scene AppDelegates start
143
+ // React Native from SceneDelegate, so the anchor is the didFinishLaunching return
144
+ // rather than factory.startReactNative.
147
145
  const methodInvocationBlock = `RNFBAppCheckModule.sharedInstance()
148
146
  FirebaseApp.configure()`;
149
147
 
150
- const methodInvocationLineMatcher = /(?:factory\.startReactNative\()/;
148
+ const methodInvocationLineMatcher =
149
+ /(?:factory\.startReactNative\()|(?:return\s+super\.application\(\s*application\s*,\s*didFinishLaunchingWithOptions:\s*launchOptions\s*\))/;
151
150
 
152
151
  if (!methodInvocationLineMatcher.test(contents)) {
153
152
  WarningAggregator.addWarningIOS(
@@ -1,76 +0,0 @@
1
- package io.invertase.firebase.appcheck;
2
-
3
- /*
4
- * Copyright (c) 2016-present Invertase Limited & Contributors
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this library except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- *
18
- */
19
-
20
- import io.invertase.firebase.common.RNFBHandleCollisionException;
21
- import io.invertase.firebase.common.RNFBHandleMap;
22
- import java.util.List;
23
-
24
- /**
25
- * App Check token listener map. Unique {@link #put} / {@link #putOrDiscard}; callers {@link #take}
26
- * or {@link #takeAllAndRemove} then {@code remove()} outside the HandleMap lock. Skip-if-registered
27
- * is {@code get(appName) != null}.
28
- */
29
- final class RNFBAppCheckListenerRegistry {
30
- private final RNFBHandleMap<String, AppCheckListenerHandle> map = new RNFBHandleMap<>();
31
-
32
- void put(String appName, AppCheckListenerHandle handle) throws RNFBHandleCollisionException {
33
- map.put(appName, handle);
34
- }
35
-
36
- /**
37
- * Unique put. On collision, {@code remove()} the incoming handle and leave the existing mapping.
38
- *
39
- * @return true if stored
40
- */
41
- boolean putOrDiscard(String appName, AppCheckListenerHandle handle) {
42
- try {
43
- map.put(appName, handle);
44
- return true;
45
- } catch (RNFBHandleCollisionException collision) {
46
- if (handle != null) {
47
- handle.remove();
48
- }
49
- return false;
50
- }
51
- }
52
-
53
- AppCheckListenerHandle get(String appName) {
54
- return map.get(appName);
55
- }
56
-
57
- AppCheckListenerHandle take(String appName) {
58
- return map.take(appName);
59
- }
60
-
61
- void takeAndRemove(String appName) {
62
- AppCheckListenerHandle handle = map.take(appName);
63
- if (handle != null) {
64
- handle.remove();
65
- }
66
- }
67
-
68
- void takeAllAndRemove() {
69
- List<AppCheckListenerHandle> remaining = map.takeAll();
70
- for (AppCheckListenerHandle handle : remaining) {
71
- if (handle != null) {
72
- handle.remove();
73
- }
74
- }
75
- }
76
- }