@react-native-firebase/app-check 19.0.1 → 19.1.1

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.
@@ -0,0 +1,92 @@
1
+ import { ConfigPlugin, IOSConfig, WarningAggregator, withDangerousMod } from '@expo/config-plugins';
2
+ import { AppDelegateProjectFile } from '@expo/config-plugins/build/ios/Paths';
3
+ import { mergeContents } from '@expo/config-plugins/build/utils/generateCode';
4
+ import fs from 'fs';
5
+
6
+ const methodInvocationBlock = `[RNFBAppCheckModule sharedInstance];`;
7
+ // https://regex101.com/r/mPgaq6/1
8
+ const methodInvocationLineMatcher =
9
+ /(?:self\.moduleName\s*=\s*@\"([^"]*)\";)|(?:(self\.|_)(\w+)\s?=\s?\[\[UMModuleRegistryAdapter alloc\])|(?:RCTBridge\s?\*\s?(\w+)\s?=\s?\[(\[RCTBridge alloc\]|self\.reactDelegate))/g;
10
+
11
+ // https://regex101.com/r/nHrTa9/1/
12
+ // if the above regex fails, we can use this one as a fallback:
13
+ const fallbackInvocationLineMatcher =
14
+ /-\s*\(BOOL\)\s*application:\s*\(UIApplication\s*\*\s*\)\s*\w+\s+didFinishLaunchingWithOptions:/g;
15
+
16
+ export function modifyObjcAppDelegate(contents: string): string {
17
+ // Add import
18
+ if (!contents.includes('#import <RNFBAppCheckModule.h>')) {
19
+ contents = contents.replace(
20
+ /#import "AppDelegate.h"/g,
21
+ `#import "AppDelegate.h"
22
+ #import <RNFBAppCheckModule.h>`,
23
+ );
24
+ }
25
+
26
+ // To avoid potential issues with existing changes from older plugin versions
27
+ if (contents.includes(methodInvocationBlock)) {
28
+ return contents;
29
+ }
30
+
31
+ if (
32
+ !methodInvocationLineMatcher.test(contents) &&
33
+ !fallbackInvocationLineMatcher.test(contents)
34
+ ) {
35
+ WarningAggregator.addWarningIOS(
36
+ '@react-native-firebase/app-check',
37
+ 'Unable to determine correct Firebase insertion point in AppDelegate.m. Skipping Firebase addition.',
38
+ );
39
+ return contents;
40
+ }
41
+
42
+ // Add invocation
43
+ try {
44
+ return mergeContents({
45
+ tag: '@react-native-firebase/app-check-didFinishLaunchingWithOptions',
46
+ src: contents,
47
+ newSrc: methodInvocationBlock,
48
+ anchor: methodInvocationLineMatcher,
49
+ offset: 0, // new line will be inserted right above matched anchor
50
+ comment: '//',
51
+ }).contents;
52
+ } catch (e: any) {
53
+ // tests if the opening `{` is in the new line
54
+ const multilineMatcher = new RegExp(fallbackInvocationLineMatcher.source + '.+\\n*{');
55
+ const isHeaderMultiline = multilineMatcher.test(contents);
56
+
57
+ // we fallback to another regex if the first one fails
58
+ return mergeContents({
59
+ tag: '@react-native-firebase/app-didFinishLaunchingWithOptions-fallback',
60
+ src: contents,
61
+ newSrc: methodInvocationBlock,
62
+ anchor: fallbackInvocationLineMatcher,
63
+ // new line will be inserted right below matched anchor
64
+ // or two lines, if the `{` is in the new line
65
+ offset: isHeaderMultiline ? 2 : 1,
66
+ comment: '//',
67
+ }).contents;
68
+ }
69
+ }
70
+
71
+ export async function modifyAppDelegateAsync(appDelegateFileInfo: AppDelegateProjectFile) {
72
+ const { language, path, contents } = appDelegateFileInfo;
73
+
74
+ if (['objc', 'objcpp'].includes(language)) {
75
+ const newContents = modifyObjcAppDelegate(contents);
76
+ await fs.promises.writeFile(path, newContents);
77
+ } else {
78
+ // TODO: Support Swift
79
+ throw new Error(`Cannot add Firebase code to AppDelegate of language "${language}"`);
80
+ }
81
+ }
82
+
83
+ export const withFirebaseAppDelegate: ConfigPlugin = config => {
84
+ return withDangerousMod(config, [
85
+ 'ios',
86
+ async config => {
87
+ const fileInfo = IOSConfig.Paths.getAppDelegate(config.modRequest.projectRoot);
88
+ await modifyAppDelegateAsync(fileInfo);
89
+ return config;
90
+ },
91
+ ]);
92
+ };
@@ -0,0 +1,3 @@
1
+ import { withFirebaseAppDelegate } from './appDelegate';
2
+
3
+ export { withFirebaseAppDelegate };
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@tsconfig/node-lts/tsconfig",
3
+ "compilerOptions": {
4
+ "outDir": "build",
5
+ "rootDir": "src",
6
+ "declaration": true
7
+ },
8
+ "include": ["./src"]
9
+ }