mayo-firebase-config 1.0.5
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.
- package/README.md +65 -0
- package/android/src/main/com/rnwritefirestore/FirebaseConfigExtractorModule.java +85 -0
- package/dist/extractFirebaseConfig.js +20 -0
- package/index.d.ts +13 -0
- package/index.ts +1 -0
- package/ios/FirebaseConfigExtractor.m +7 -0
- package/ios/FirebaseConfigExtractor.swift +28 -0
- package/package.json +37 -0
- package/rn-write-firestore.podspec +24 -0
- package/src/extractFirebaseConfig.ts +34 -0
- package/tsconfig.json +21 -0
package/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Description
|
2
|
+
|
3
|
+
__rn-firebase-config__ is a React Native module designed to extract Firebase configuration details from native files (google-services.json for Android and GoogleService-Info.plist for iOS) to be used in JavaScript code.
|
4
|
+
How it Works
|
5
|
+
|
6
|
+
Behind the scenes, mayo-firebase-config employs native modules in both Android and iOS:
|
7
|
+
|
8
|
+
- Android: Reads the google-services.json file from the assets folder, extracts the required Firebase configuration details, and returns them to the React Native JavaScript layer.
|
9
|
+
|
10
|
+
- iOS: Reads the GoogleService-Info.plist file, extracts the required Firebase configuration details, and returns them to the React Native JavaScript layer.
|
11
|
+
|
12
|
+
# How to Use
|
13
|
+
|
14
|
+
Ensure that you have the google-services.json file in the assets folder for Android and the GoogleService-Info.plist in the main bundle for iOS.
|
15
|
+
|
16
|
+
Use the extractFirebaseConfig function in your React Native code as follows:
|
17
|
+
|
18
|
+
```javascript
|
19
|
+
|
20
|
+
import { extractFirebaseConfig } from 'mayo-firebase-config';
|
21
|
+
|
22
|
+
const firebaseConfig = extractFirebaseConfig();
|
23
|
+
console.log(firebaseConfig);
|
24
|
+
|
25
|
+
```
|
26
|
+
|
27
|
+
This function logs the extraction process and returns the extracted configuration. If the extraction is successful, you'll get an object with Firebase details; otherwise, a warning log indicates any issues.
|
28
|
+
Points to Note
|
29
|
+
|
30
|
+
- The module handles errors gracefully and will provide clear logs in case of extraction failures.
|
31
|
+
|
32
|
+
- For security reasons, be cautious about logging the full Firebase config in a production environment as it may expose sensitive information.
|
33
|
+
|
34
|
+
## Dependencies
|
35
|
+
|
36
|
+
React Native
|
37
|
+
|
38
|
+
## Installation
|
39
|
+
|
40
|
+
For the module to work, you need to ensure that the native modules are correctly linked in your React Native project. Follow the standard React Native linking procedures for native modules if not using auto-linking.
|
41
|
+
Contributing
|
42
|
+
|
43
|
+
### We welcome contributions to mayo-firebase-config!
|
44
|
+
|
45
|
+
Here's how you can help:
|
46
|
+
|
47
|
+
- Fork the Repository: Click on the 'Fork' button at the top right corner of this page.
|
48
|
+
|
49
|
+
- Clone Your Forked Repository: git clone https://github.com/YOUR_USERNAME/mayo-firebase-config.git
|
50
|
+
|
51
|
+
- Navigate to the cloned directory: cd mayo-firebase-config
|
52
|
+
|
53
|
+
- Create a New Branch: git checkout -b new-feature-or-bug-fix
|
54
|
+
|
55
|
+
- Make Changes: Implement your new feature or fix a bug and commit the changes.
|
56
|
+
|
57
|
+
- Push to GitHub: git push origin new-feature-or-bug-fix
|
58
|
+
|
59
|
+
- Submit a Pull Request: Go to the mayo-firebase-config GitHub page and click on the 'New Pull Request' button. Select your branch from the dropdown and submit your pull request.
|
60
|
+
|
61
|
+
- Wait for the Review: Maintainers will review your pull request, suggest changes if necessary, and merge it once it's approved.
|
62
|
+
|
63
|
+
### License
|
64
|
+
|
65
|
+
mayo-firebase-config is licensed under the MIT License. Refer to the LICENSE file in the repository for more details.
|
@@ -0,0 +1,85 @@
|
|
1
|
+
package com.yourprojectname;
|
2
|
+
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
4
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
5
|
+
import com.facebook.react.bridge.ReactMethod;
|
6
|
+
import com.facebook.react.bridge.Promise;
|
7
|
+
|
8
|
+
import java.io.BufferedReader;
|
9
|
+
import java.io.IOException;
|
10
|
+
import java.io.InputStream;
|
11
|
+
import java.io.InputStreamReader;
|
12
|
+
import java.util.HashMap;
|
13
|
+
import java.util.Map;
|
14
|
+
|
15
|
+
public class FirebaseConfigExtractorModule extends ReactContextBaseJavaModule {
|
16
|
+
|
17
|
+
public FirebaseConfigExtractorModule(ReactApplicationContext reactContext) {
|
18
|
+
super(reactContext);
|
19
|
+
}
|
20
|
+
|
21
|
+
@Override
|
22
|
+
public String getName() {
|
23
|
+
return "FirebaseConfigExtractor";
|
24
|
+
}
|
25
|
+
|
26
|
+
@ReactMethod
|
27
|
+
public void extractConfig(Promise promise) {
|
28
|
+
try {
|
29
|
+
// Use AssetManager to read the google-services.json file from the assets folder
|
30
|
+
AssetManager assetManager = getReactApplicationContext().getAssets();
|
31
|
+
InputStream input = assetManager.open("google-services.json");
|
32
|
+
|
33
|
+
// Convert InputStream to String
|
34
|
+
String json = convertStreamToString(input);
|
35
|
+
|
36
|
+
// Use JSONObject to parse the JSON string
|
37
|
+
JSONObject jsonObject = new JSONObject(json);
|
38
|
+
JSONArray clientArray = jsonObject.getJSONArray("client");
|
39
|
+
JSONObject clientObject = clientArray.getJSONObject(0);
|
40
|
+
JSONObject projectInfo = jsonObject.getJSONObject("project_info");
|
41
|
+
JSONArray apiKeyArray = clientObject.getJSONArray("api_key");
|
42
|
+
JSONObject apiKeyObject = apiKeyArray.getJSONObject(0);
|
43
|
+
|
44
|
+
// Extract webClientId
|
45
|
+
JSONArray oauthClientArray = clientObject.getJSONArray("oauth_client");
|
46
|
+
String webClientId = "";
|
47
|
+
for (int i = 0; i < oauthClientArray.length(); i++) {
|
48
|
+
JSONObject oauthClientObject = oauthClientArray.getJSONObject(i);
|
49
|
+
if (oauthClientObject.getInt("client_type") == 3) {
|
50
|
+
webClientId = oauthClientObject.getString("client_id");
|
51
|
+
break;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
// Extract the values
|
56
|
+
Map<String, String> config = new HashMap<>();
|
57
|
+
config.put("webClientId", webClientId);
|
58
|
+
config.put("apiKey", apiKeyObject.getString("current_key"));
|
59
|
+
config.put("authDomain", projectInfo.getString("project_id") + ".firebaseapp.com");
|
60
|
+
config.put("projectId", projectInfo.getString("project_id"));
|
61
|
+
config.put("storageBucket", projectInfo.getString("storage_bucket"));
|
62
|
+
config.put("messagingSenderId", projectInfo.getString("project_number"));
|
63
|
+
config.put("appId", clientObject.getJSONObject("client_info").getString("mobilesdk_app_id"));
|
64
|
+
// Add logic for measurement ID if needed
|
65
|
+
config.put("databaseURL", "https://" + projectInfo.getString("project_id") + ".firebaseio.com");
|
66
|
+
|
67
|
+
promise.resolve(config);
|
68
|
+
} catch (Exception e) {
|
69
|
+
promise.reject("ERR_UNEXPECTED_EXCEPTION", "Error extracting Firebase config on Android", e);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
// Helper method to convert InputStream to String
|
74
|
+
private String convertStreamToString(InputStream is) throws IOException {
|
75
|
+
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
76
|
+
StringBuilder sb = new StringBuilder();
|
77
|
+
String line;
|
78
|
+
while ((line = reader.readLine()) != null) {
|
79
|
+
sb.append(line).append("\n");
|
80
|
+
}
|
81
|
+
reader.close();
|
82
|
+
return sb.toString();
|
83
|
+
}
|
84
|
+
|
85
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.extractFirebaseConfig = void 0;
|
4
|
+
const react_native_1 = require("react-native");
|
5
|
+
const rn_logging_1 = require("mayo-logging");
|
6
|
+
const { FirebaseConfigExtractor } = react_native_1.NativeModules;
|
7
|
+
const extractFirebaseConfig = () => {
|
8
|
+
rn_logging_1.Logger.info('Starting Firebase config extraction...', null, { tag: 'mayo-firebase-config-extractor' });
|
9
|
+
const config = FirebaseConfigExtractor.extractConfig();
|
10
|
+
if (config && typeof config === 'object' && Object.keys(config).length > 0) {
|
11
|
+
rn_logging_1.Logger.info('Successfully extracted Firebase config', null, { tag: 'mayo-firebase-config-extractor' });
|
12
|
+
}
|
13
|
+
else {
|
14
|
+
rn_logging_1.Logger.warn('Failed to extract valid Firebase config or the config is empty', null, { tag: 'mayo-firebase-config-extractor' });
|
15
|
+
}
|
16
|
+
// This log may expose sensitive information, so be cautious about using it in a production environment
|
17
|
+
rn_logging_1.Logger.info('Extracted Firebase config:', { config }, { tag: 'mayo-firebase-config-extractor' });
|
18
|
+
return config;
|
19
|
+
};
|
20
|
+
exports.extractFirebaseConfig = extractFirebaseConfig;
|
package/index.d.ts
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
declare module 'mayo-firebase-config/extractor' {
|
2
|
+
export function extractFirebaseConfig(): {
|
3
|
+
apiKey: string;
|
4
|
+
authDomain: string;
|
5
|
+
projectId: string;
|
6
|
+
storageBucket: string;
|
7
|
+
messagingSenderId: string;
|
8
|
+
appId: string;
|
9
|
+
measurementId: string;
|
10
|
+
databaseURL: string;
|
11
|
+
webClientId?: string;
|
12
|
+
};
|
13
|
+
}
|
package/index.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export { extractFirebaseConfig } from './src/extractFirebaseConfig';
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import React
|
2
|
+
|
3
|
+
@objc(FirebaseConfigExtractor)
|
4
|
+
class FirebaseConfigExtractor: NSObject, RCTBridgeModule {
|
5
|
+
static func moduleName() -> String {
|
6
|
+
return "FirebaseConfigExtractor"
|
7
|
+
}
|
8
|
+
|
9
|
+
@objc func extractConfig(_ resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) {
|
10
|
+
if let path = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist"),
|
11
|
+
let plist = NSDictionary(contentsOfFile: path) as? [String: Any] {
|
12
|
+
let config: [String: Any] = [
|
13
|
+
"apiKey": plist["API_KEY"] as? String ?? "",
|
14
|
+
"authDomain": "\(plist["PROJECT_ID"] as? String ?? "").firebaseapp.com",
|
15
|
+
"projectId": plist["PROJECT_ID"] as? String ?? "",
|
16
|
+
"storageBucket": "\(plist["PROJECT_ID"] as? String ?? "").appspot.com",
|
17
|
+
"messagingSenderId": plist["GCM_SENDER_ID"] as? String ?? "",
|
18
|
+
"appId": plist["GOOGLE_APP_ID"] as? String ?? "",
|
19
|
+
"measurementId": "", // Add logic for measurement ID if needed
|
20
|
+
"databaseURL": "https://\(plist["PROJECT_ID"] as? String ?? "").firebaseio.com",
|
21
|
+
"webClientId": plist["WEB_CLIENT_ID"] as? String ?? "" // Add this line
|
22
|
+
]
|
23
|
+
resolver(config)
|
24
|
+
} else {
|
25
|
+
rejecter("ERR_UNEXPECTED_EXCEPTION", "Could not read the GoogleService-Info.plist", nil)
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
package/package.json
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
{
|
2
|
+
"name": "mayo-firebase-config",
|
3
|
+
"version": "1.0.5",
|
4
|
+
"license": "MIT",
|
5
|
+
"author": "Mohamed Bennekrouf",
|
6
|
+
"main": "dist/index.js",
|
7
|
+
"types": "dist/index.d.ts",
|
8
|
+
"scripts": {
|
9
|
+
"semantic-release": "semantic-release"
|
10
|
+
},
|
11
|
+
"husky": {
|
12
|
+
"hooks": {
|
13
|
+
"pre-push": "npm run semantic-release"
|
14
|
+
}
|
15
|
+
},
|
16
|
+
"dependencies": {
|
17
|
+
"mayo-logging": "^1.0.6"
|
18
|
+
},
|
19
|
+
"devDependencies": {
|
20
|
+
"@types/react": "^18.2.21",
|
21
|
+
"@types/react-native": "^0.72.2",
|
22
|
+
"react": "18.2.0",
|
23
|
+
"react-native": "^0.72.5",
|
24
|
+
"typescript": "^5.2.2"
|
25
|
+
},
|
26
|
+
"peerDependencies": {
|
27
|
+
"react-native": "^0.59.0 || ^1000.0.0",
|
28
|
+
"react-native-device-info": "^10.11.0"
|
29
|
+
},
|
30
|
+
"resolutions": {
|
31
|
+
"react": "16.14.0"
|
32
|
+
},
|
33
|
+
"repository": {
|
34
|
+
"type": "git",
|
35
|
+
"url": "git+https://github.com/bennekrouf/mayo-firebase-config.git"
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Pod::Spec.new do |s|
|
2
|
+
s.name = "mayo-firebase-config"
|
3
|
+
s.version = "1.1.1"
|
4
|
+
s.summary = "Firebase config auto extractor."
|
5
|
+
|
6
|
+
s.description = <<-DESC
|
7
|
+
From firebase config we can extract a file that already contains all what is needed to interact with firebase and firestore. So this package is extracting these parameters from these files, to avoid to have to build again a firebaseconfig object or file
|
8
|
+
DESC
|
9
|
+
|
10
|
+
s.homepage = "https://github.com/bennekrouf/mayo-firebase-config"
|
11
|
+
|
12
|
+
s.license = { :type => "MIT", :file => "LICENSE" }
|
13
|
+
|
14
|
+
s.author = { "bennekrouf" => "mb@mayorana.ch" }
|
15
|
+
s.platform = :ios, "9.0"
|
16
|
+
|
17
|
+
s.source = { :git => "https://github.com/bennekrouf/mayo-firebase-config.git", :tag => s.version.to_s }
|
18
|
+
|
19
|
+
s.source_files = "ios/**/*.{h,m,swift}"
|
20
|
+
s.dependency 'React'
|
21
|
+
|
22
|
+
s.swift_version = '5.0'
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { NativeModules } from 'react-native';
|
2
|
+
import { Logger } from 'mayo-logging';
|
3
|
+
|
4
|
+
interface FirebaseConfig {
|
5
|
+
apiKey?: string;
|
6
|
+
authDomain?: string;
|
7
|
+
projectId?: string;
|
8
|
+
storageBucket?: string;
|
9
|
+
messagingSenderId?: string;
|
10
|
+
appId?: string;
|
11
|
+
measurementId?: string;
|
12
|
+
databaseURL?: string;
|
13
|
+
webClientId?: string; // Add this line
|
14
|
+
[key: string]: string | undefined; // To cater for any other properties that might be added
|
15
|
+
}
|
16
|
+
|
17
|
+
const { FirebaseConfigExtractor } = NativeModules;
|
18
|
+
|
19
|
+
export const extractFirebaseConfig = (): FirebaseConfig => {
|
20
|
+
Logger.info('Starting Firebase config extraction...', null, { tag: 'mayo-firebase-config-extractor' });
|
21
|
+
|
22
|
+
const config: FirebaseConfig = FirebaseConfigExtractor.extractConfig();
|
23
|
+
|
24
|
+
if (config && typeof config === 'object' && Object.keys(config).length > 0) {
|
25
|
+
Logger.info('Successfully extracted Firebase config', null, { tag: 'mayo-firebase-config-extractor' });
|
26
|
+
} else {
|
27
|
+
Logger.warn('Failed to extract valid Firebase config or the config is empty', null, { tag: 'mayo-firebase-config-extractor' });
|
28
|
+
}
|
29
|
+
|
30
|
+
// This log may expose sensitive information, so be cautious about using it in a production environment
|
31
|
+
Logger.info('Extracted Firebase config:', { config }, { tag: 'mayo-firebase-config-extractor' });
|
32
|
+
|
33
|
+
return config;
|
34
|
+
};
|
package/tsconfig.json
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"typeRoots": ["./types", "./node_modules/@types"],
|
4
|
+
"jsx": "react",
|
5
|
+
"outDir": "./dist", // specify the output directory
|
6
|
+
"rootDir": "./src", // specify the root directory of source files
|
7
|
+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
8
|
+
"module": "commonjs", /* Specify what module code is generated. */
|
9
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
10
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
11
|
+
|
12
|
+
"strict": true, /* Enable all strict type-checking options. */
|
13
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
14
|
+
},
|
15
|
+
"include": [
|
16
|
+
"src/**/*.ts" // source files to include in the compilation
|
17
|
+
],
|
18
|
+
"exclude": [
|
19
|
+
"node_modules" // dependencies to exclude from compilation
|
20
|
+
]
|
21
|
+
}
|