@react-native-firebase/app-check 25.0.1 → 26.0.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 (67) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/RNFBAppCheck.podspec +18 -6
  3. package/android/build.gradle +19 -0
  4. package/android/src/main/java/io/invertase/firebase/appcheck/{ReactNativeFirebaseAppCheckModule.java → NativeRNFBTurboAppCheck.java} +46 -34
  5. package/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckPackage.java +1 -1
  6. package/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckProvider.java +9 -0
  7. package/android/src/main/java/io/invertase/firebase/appcheck/generated/java/com/facebook/fbreact/specs/NativeRNFBTurboAppCheckSpec.java +67 -0
  8. package/android/src/main/java/io/invertase/firebase/appcheck/generated/jni/CMakeLists.txt +36 -0
  9. package/android/src/main/java/io/invertase/firebase/appcheck/generated/jni/RNFBAppCheckTurboModules-generated.cpp +74 -0
  10. package/android/src/main/java/io/invertase/firebase/appcheck/generated/jni/RNFBAppCheckTurboModules.h +31 -0
  11. package/android/src/main/java/io/invertase/firebase/appcheck/generated/jni/react/renderer/components/RNFBAppCheckTurboModules/RNFBAppCheckTurboModulesJSI-generated.cpp +85 -0
  12. package/android/src/main/java/io/invertase/firebase/appcheck/generated/jni/react/renderer/components/RNFBAppCheckTurboModules/RNFBAppCheckTurboModulesJSI.h +174 -0
  13. package/app.plugin.js +1 -1
  14. package/dist/module/index.js +210 -6
  15. package/dist/module/index.js.map +1 -1
  16. package/dist/module/version.js +1 -1
  17. package/dist/typescript/lib/index.d.ts +19 -4
  18. package/dist/typescript/lib/index.d.ts.map +1 -1
  19. package/dist/typescript/lib/types/appcheck.d.ts +5 -0
  20. package/dist/typescript/lib/types/appcheck.d.ts.map +1 -1
  21. package/dist/typescript/lib/types/internal.d.ts +1 -1
  22. package/dist/typescript/lib/types/internal.d.ts.map +1 -1
  23. package/dist/typescript/lib/version.d.ts +1 -1
  24. package/ios/RNFBAppCheck/RNFBAppCheckModule.h +3 -8
  25. package/ios/RNFBAppCheck/{RNFBAppCheckModule.m → RNFBAppCheckModule.mm} +66 -43
  26. package/ios/RNFBAppCheck/RNFBAppCheckProvider.m +11 -1
  27. package/ios/RNFBAppCheck.xcodeproj/project.pbxproj +8 -8
  28. package/ios/generated/RCTAppDependencyProvider.h +25 -0
  29. package/ios/generated/RCTAppDependencyProvider.mm +55 -0
  30. package/ios/generated/RCTModulesConformingToProtocolsProvider.h +18 -0
  31. package/ios/generated/RCTModulesConformingToProtocolsProvider.mm +33 -0
  32. package/ios/generated/RCTThirdPartyComponentsProvider.h +16 -0
  33. package/ios/generated/RCTThirdPartyComponentsProvider.mm +23 -0
  34. package/ios/generated/RNFBAppCheckTurboModules/RNFBAppCheckTurboModules-generated.mm +88 -0
  35. package/ios/generated/RNFBAppCheckTurboModules/RNFBAppCheckTurboModules.h +85 -0
  36. package/ios/generated/RNFBAppCheckTurboModulesJSI-generated.cpp +85 -0
  37. package/ios/generated/RNFBAppCheckTurboModulesJSI.h +174 -0
  38. package/ios/generated/ReactAppDependencyProvider.podspec +34 -0
  39. package/lib/index.ts +335 -8
  40. package/lib/types/appcheck.ts +6 -0
  41. package/lib/types/internal.ts +1 -1
  42. package/lib/version.ts +1 -1
  43. package/package.json +30 -5
  44. package/plugin/build/app.plugin.d.ts +2 -0
  45. package/plugin/build/app.plugin.js +6 -0
  46. package/plugin/build/ios/appDelegate.js +18 -4
  47. package/plugin/src/app.plugin.ts +3 -0
  48. package/plugin/src/ios/appDelegate.ts +23 -4
  49. package/plugin/tsconfig.tsbuildinfo +1 -1
  50. package/react-native.config.js +10 -0
  51. package/specs/NativeRNFBTurboAppCheck.ts +27 -0
  52. package/typedoc.json +1 -1
  53. package/dist/module/modular.js +0 -93
  54. package/dist/module/modular.js.map +0 -1
  55. package/dist/module/namespaced.js +0 -194
  56. package/dist/module/namespaced.js.map +0 -1
  57. package/dist/module/types/namespaced.js +0 -60
  58. package/dist/module/types/namespaced.js.map +0 -1
  59. package/dist/typescript/lib/modular.d.ts +0 -56
  60. package/dist/typescript/lib/modular.d.ts.map +0 -1
  61. package/dist/typescript/lib/namespaced.d.ts +0 -12
  62. package/dist/typescript/lib/namespaced.d.ts.map +0 -1
  63. package/dist/typescript/lib/types/namespaced.d.ts +0 -358
  64. package/dist/typescript/lib/types/namespaced.d.ts.map +0 -1
  65. package/lib/modular.ts +0 -157
  66. package/lib/namespaced.ts +0 -286
  67. package/lib/types/namespaced.ts +0 -422
package/lib/namespaced.ts DELETED
@@ -1,286 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-present Invertase Limited & Contributors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this library except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- import {
19
- isBoolean,
20
- isIOS,
21
- isString,
22
- isObject,
23
- isUndefined,
24
- isOther,
25
- parseListenerOrObserver,
26
- } from '@react-native-firebase/app/dist/module/common';
27
- import {
28
- createModuleNamespace,
29
- FirebaseModule,
30
- getFirebaseRoot,
31
- } from '@react-native-firebase/app/dist/module/internal';
32
- import type { ModuleConfig } from '@react-native-firebase/app/dist/module/internal';
33
- import { Platform } from 'react-native';
34
- import { setReactNativeModule } from '@react-native-firebase/app/dist/module/internal/nativeModule';
35
- import fallBackModule from './web/RNFBAppCheckModule';
36
- import { version } from './version';
37
- import type {
38
- AppCheckOptions,
39
- AppCheckProvider,
40
- AppCheckTokenResult,
41
- PartialObserver,
42
- } from './types/appcheck';
43
- import type { ProviderWithOptions } from './types/internal';
44
- import type { FirebaseAppCheckTypes } from './types/namespaced';
45
- import type { ReactNativeFirebase } from '@react-native-firebase/app';
46
- import { CustomProvider, ReactNativeFirebaseAppCheckProvider } from './providers';
47
-
48
- const namespace = 'appCheck';
49
-
50
- const nativeModuleName = 'RNFBAppCheckModule';
51
-
52
- const statics = {
53
- CustomProvider,
54
- };
55
-
56
- /**
57
- * Type guard to check if a provider has providerOptions.
58
- * This provides proper type narrowing for providers that support platform-specific configuration.
59
- */
60
- function hasProviderOptions(
61
- provider: AppCheckOptions['provider'],
62
- ): provider is ProviderWithOptions {
63
- return (
64
- provider !== undefined &&
65
- 'providerOptions' in provider &&
66
- provider.providerOptions !== undefined
67
- );
68
- }
69
-
70
- class FirebaseAppCheckModule extends FirebaseModule<typeof nativeModuleName> {
71
- _listenerCount: number;
72
-
73
- constructor(
74
- app: ReactNativeFirebase.FirebaseAppBase,
75
- config: ModuleConfig,
76
- customUrlOrRegion?: string | null,
77
- ) {
78
- super(app, config, customUrlOrRegion);
79
-
80
- this.emitter.addListener(this.eventNameForApp('appCheck_token_changed'), event => {
81
- this.emitter.emit(this.eventNameForApp('onAppCheckTokenChanged'), event);
82
- });
83
-
84
- this._listenerCount = 0;
85
- }
86
-
87
- getIsTokenRefreshEnabledDefault(): boolean | undefined {
88
- // no default to start
89
- let isTokenAutoRefreshEnabled: boolean | undefined = undefined;
90
-
91
- return isTokenAutoRefreshEnabled;
92
- }
93
-
94
- newReactNativeFirebaseAppCheckProvider(): ReactNativeFirebaseAppCheckProvider {
95
- return new ReactNativeFirebaseAppCheckProvider();
96
- }
97
-
98
- initializeAppCheck(options: AppCheckOptions): Promise<void> {
99
- if (isOther) {
100
- if (!isObject(options)) {
101
- throw new Error('Invalid configuration: no options defined.');
102
- }
103
- if (isUndefined(options.provider)) {
104
- throw new Error('Invalid configuration: no provider defined.');
105
- }
106
- return this.native.initializeAppCheck(options);
107
- }
108
- // determine token refresh setting, if not specified
109
- if (!isBoolean(options.isTokenAutoRefreshEnabled)) {
110
- const tokenRefresh = this.firebaseJson.app_check_token_auto_refresh;
111
- if (isBoolean(tokenRefresh)) {
112
- options.isTokenAutoRefreshEnabled = tokenRefresh;
113
- }
114
- }
115
-
116
- // If that was not defined, attempt to use app-wide data collection setting per docs:
117
- if (!isBoolean(options.isTokenAutoRefreshEnabled)) {
118
- const dataCollection = this.firebaseJson.app_data_collection_default_enabled;
119
- if (isBoolean(dataCollection)) {
120
- options.isTokenAutoRefreshEnabled = dataCollection;
121
- }
122
- }
123
-
124
- // If that also was not defined, the default is documented as true.
125
- if (!isBoolean(options.isTokenAutoRefreshEnabled)) {
126
- options.isTokenAutoRefreshEnabled = true;
127
- }
128
- this.native.setTokenAutoRefreshEnabled(options.isTokenAutoRefreshEnabled);
129
-
130
- if (!hasProviderOptions(options.provider)) {
131
- throw new Error('Invalid configuration: no provider or no provider options defined.');
132
- }
133
- const provider = options.provider;
134
- if (Platform.OS === 'android') {
135
- if (!isString(provider.providerOptions?.android?.provider)) {
136
- throw new Error(
137
- 'Invalid configuration: no android provider configured while on android platform.',
138
- );
139
- }
140
- return this.native.configureProvider(
141
- provider.providerOptions.android.provider,
142
- provider.providerOptions.android.debugToken,
143
- );
144
- }
145
- if (Platform.OS === 'ios' || Platform.OS === 'macos') {
146
- if (!isString(provider.providerOptions?.apple?.provider)) {
147
- throw new Error(
148
- 'Invalid configuration: no apple provider configured while on apple platform.',
149
- );
150
- }
151
- return this.native.configureProvider(
152
- provider.providerOptions.apple.provider,
153
- provider.providerOptions.apple.debugToken,
154
- );
155
- }
156
- throw new Error('Unsupported platform: ' + Platform.OS);
157
- }
158
-
159
- activate(
160
- siteKeyOrProvider: string | AppCheckProvider,
161
- isTokenAutoRefreshEnabled?: boolean,
162
- ): Promise<void> {
163
- if (isOther) {
164
- throw new Error('firebase.appCheck().activate(*) is not supported on other platforms');
165
- }
166
- if (!isString(siteKeyOrProvider)) {
167
- throw new Error('siteKeyOrProvider must be a string value to match firebase-js-sdk API');
168
- }
169
-
170
- // We wrap our new flexible interface, with compatible defaults
171
- const rnfbProvider = new ReactNativeFirebaseAppCheckProvider();
172
- rnfbProvider.configure({
173
- android: {
174
- provider: 'playIntegrity',
175
- },
176
- apple: {
177
- provider: 'deviceCheck',
178
- },
179
- web: {
180
- provider: 'reCaptchaV3',
181
- siteKey: 'none',
182
- },
183
- });
184
-
185
- return this.initializeAppCheck({ provider: rnfbProvider, isTokenAutoRefreshEnabled });
186
- }
187
-
188
- // TODO this is an async call
189
- setTokenAutoRefreshEnabled(isTokenAutoRefreshEnabled: boolean): void {
190
- this.native.setTokenAutoRefreshEnabled(isTokenAutoRefreshEnabled);
191
- }
192
-
193
- getToken(forceRefresh?: boolean): Promise<AppCheckTokenResult> {
194
- if (!forceRefresh) {
195
- return this.native.getToken(false);
196
- } else {
197
- return this.native.getToken(true);
198
- }
199
- }
200
-
201
- getLimitedUseToken(): Promise<AppCheckTokenResult> {
202
- return this.native.getLimitedUseToken();
203
- }
204
-
205
- onTokenChanged(
206
- onNextOrObserver:
207
- | PartialObserver<FirebaseAppCheckTypes.AppCheckListenerResult>
208
- | ((tokenResult: FirebaseAppCheckTypes.AppCheckListenerResult) => void),
209
- _onError?: (error: Error) => void,
210
- _onCompletion?: () => void,
211
- ): () => void {
212
- // iOS does not provide any native listening feature
213
- if (isIOS) {
214
- // eslint-disable-next-line no-console
215
- console.warn('onTokenChanged is not implemented on IOS, only for Android');
216
- return () => {};
217
- }
218
- const nextFn = parseListenerOrObserver(
219
- onNextOrObserver as
220
- | ((value: FirebaseAppCheckTypes.AppCheckListenerResult) => void)
221
- | { next: (value: FirebaseAppCheckTypes.AppCheckListenerResult) => void },
222
- );
223
- // let errorFn = function () { };
224
- // if (onNextOrObserver.error != null) {
225
- // errorFn = onNextOrObserver.error.bind(onNextOrObserver);
226
- // }
227
- // else if (onError) {
228
- // errorFn = onError;
229
- // }
230
- const subscription = this.emitter.addListener(
231
- this.eventNameForApp('onAppCheckTokenChanged'),
232
- nextFn,
233
- );
234
- if (this._listenerCount === 0) this.native.addAppCheckListener();
235
-
236
- this._listenerCount++;
237
- return () => {
238
- subscription.remove();
239
- this._listenerCount--;
240
- if (this._listenerCount === 0) this.native.removeAppCheckListener();
241
- };
242
- }
243
- }
244
-
245
- export const SDK_VERSION = version;
246
-
247
- const appCheckNamespace = createModuleNamespace({
248
- statics,
249
- version,
250
- namespace,
251
- nativeModuleName,
252
- nativeEvents: ['appCheck_token_changed'],
253
- hasMultiAppSupport: true,
254
- hasCustomUrlOrRegionSupport: false,
255
- ModuleClass: FirebaseAppCheckModule,
256
- });
257
-
258
- type AppCheckNamespace = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<
259
- FirebaseAppCheckTypes.Module,
260
- FirebaseAppCheckTypes.Statics
261
- > & {
262
- appCheck: ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<
263
- FirebaseAppCheckTypes.Module,
264
- FirebaseAppCheckTypes.Statics
265
- >;
266
- firebase: ReactNativeFirebase.Module;
267
- app(name?: string): ReactNativeFirebase.FirebaseApp;
268
- };
269
-
270
- // import appCheck from '@react-native-firebase/app-check';
271
- // appCheck().X(...);
272
- export default appCheckNamespace as unknown as AppCheckNamespace;
273
-
274
- // import appCheck, { firebase } from '@react-native-firebase/app-check';
275
- // appCheck().X(...);
276
- // firebase.appCheck().X(...);
277
- export const firebase =
278
- getFirebaseRoot() as unknown as ReactNativeFirebase.FirebaseNamespacedExport<
279
- 'appCheck',
280
- FirebaseAppCheckTypes.Module,
281
- FirebaseAppCheckTypes.Statics,
282
- false
283
- >;
284
-
285
- // Register the interop module for non-native platforms.
286
- setReactNativeModule(nativeModuleName, fallBackModule as unknown as Record<string, unknown>);