mayo-firebase-config 1.2.16 → 1.2.18

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.
@@ -1,4 +1,5 @@
1
1
  apply plugin: 'com.android.library'
2
+ apply plugin: 'kotlin-android'
2
3
 
3
4
  android {
4
5
  compileSdkVersion 33
@@ -15,13 +16,14 @@ android {
15
16
  lintOptions {
16
17
  abortOnError false
17
18
  }
19
+
20
+ buildTypes {
21
+ release {
22
+ minifyEnabled false
23
+ }
24
+ }
18
25
  }
19
26
  dependencies {
27
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.10"
20
28
  implementation 'com.facebook.react:react-native:+'
21
- }
22
-
23
- // Ensure this is set to 'library'
24
- apply plugin: 'maven-publish'
25
- publishing {
26
- // publication details here
27
29
  }
@@ -1 +1,2 @@
1
1
  # Add any specific gradle properties here
2
+ android.disableAutomaticComponentCreation=true
@@ -1,4 +1,4 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
- package="com.mayofirebaseconfig">
3
-
2
+ package="com.mayo.firebaseconfig">
3
+ <application />
4
4
  </manifest>
@@ -0,0 +1,55 @@
1
+ package com.mayo.firebaseconfig
2
+
3
+ import android.content.Context
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
6
+ import com.facebook.react.bridge.ReactMethod
7
+ import com.facebook.react.bridge.Promise
8
+ import org.json.JSONObject
9
+
10
+ class FirebaseConfigModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
11
+
12
+ override fun getName(): String {
13
+ return "FirebaseConfigExtractor"
14
+ }
15
+
16
+ @ReactMethod
17
+ fun extractConfig(promise: Promise) {
18
+ try {
19
+ val context: Context = reactApplicationContext
20
+ val assetManager = context.assets
21
+ val inputStream = assetManager.open("google-services.json")
22
+ val size = inputStream.available()
23
+ val buffer = ByteArray(size)
24
+ inputStream.read(buffer)
25
+ inputStream.close()
26
+
27
+ val jsonStr = String(buffer, Charsets.UTF_8)
28
+ val jsonObject = JSONObject(jsonStr)
29
+
30
+ val configData = parseFirebaseConfig(jsonObject)
31
+ promise.resolve(configData.toString())
32
+ } catch (e: Exception) {
33
+ promise.reject("Firebase Config Error", e.message)
34
+ }
35
+ }
36
+
37
+ private fun parseFirebaseConfig(jsonObject: JSONObject): JSONObject {
38
+ val projectInfo = jsonObject.getJSONObject("project_info")
39
+ val client = jsonObject.getJSONArray("client").getJSONObject(0)
40
+ val apiKey = client.getJSONArray("api_key").getJSONObject(0).getString("current_key")
41
+ val mobilesdkAppId = client.getJSONObject("client_info").getString("mobilesdk_app_id")
42
+
43
+ val config = JSONObject()
44
+ config.put("apiKey", apiKey)
45
+ config.put("projectId", projectInfo.getString("project_id"))
46
+ config.put("authDomain", "${projectInfo.getString("project_id")}.firebaseapp.com")
47
+ config.put("storageBucket", projectInfo.getString("storage_bucket"))
48
+ config.put("messagingSenderId", projectInfo.getString("project_number"))
49
+ config.put("appId", mobilesdkAppId)
50
+
51
+ // Add more fields if necessary
52
+
53
+ return config
54
+ }
55
+ }
@@ -0,0 +1,16 @@
1
+ package com.mayo.firebaseconfig
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+
8
+ class FirebaseConfigPackage : ReactPackage {
9
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
10
+ return listOf(FirebaseConfigModule(reactContext))
11
+ }
12
+
13
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
14
+ return emptyList()
15
+ }
16
+ }
@@ -1,6 +1,6 @@
1
1
  Pod::Spec.new do |s|
2
2
  s.name = "mayo-firebase-config"
3
- s.version = "1.1.1"
3
+ s.version = "1.2.17 "
4
4
  s.summary = "Firebase config auto extractor."
5
5
 
6
6
  s.description = <<-DESC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mayo-firebase-config",
3
- "version": "1.2.16",
3
+ "version": "1.2.18",
4
4
  "license": "MIT",
5
5
  "author": "Mohamed Bennekrouf",
6
6
  "main": "dist/index.js",
@@ -18,7 +18,7 @@
18
18
  "mayo-logger": "^1.0.8"
19
19
  },
20
20
  "devDependencies": {
21
- "@types/react": "^18.2.21",
21
+ "@types/react": "^18.2.27",
22
22
  "@types/react-native": "^0.72.2",
23
23
  "typescript": "^5.2.2"
24
24
  },
@@ -3,6 +3,7 @@ module.exports = {
3
3
  platforms: {
4
4
  android: {
5
5
  sourceDir: './android',
6
+ packageInstance: "new FirebaseConfigPackage()"
6
7
  // packageInstance: 'new FirebaseConfigExtractorModule(reactContext)'
7
8
  },
8
9
  },
@@ -1,108 +0,0 @@
1
- package com.mayofirebaseconfig;
2
-
3
- import android.util.Log;
4
-
5
- import com.facebook.react.bridge.ReactApplicationContext;
6
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
7
- import com.facebook.react.bridge.ReactMethod;
8
- import com.facebook.react.bridge.Promise;
9
- import com.facebook.react.module.annotations.ReactModule;
10
-
11
- import android.content.res.AssetManager;
12
- import org.json.JSONArray;
13
- import org.json.JSONObject;
14
-
15
- import java.io.BufferedReader;
16
- import java.io.IOException;
17
- import java.io.InputStream;
18
- import java.io.InputStreamReader;
19
- import java.util.HashMap;
20
- import java.util.Map;
21
-
22
- @ReactModule(name = FirebaseConfigExtractorModule.NAME)
23
- public class FirebaseConfigExtractorModule extends ReactContextBaseJavaModule {
24
- public static final String NAME = "FirebaseConfigExtractor";
25
-
26
- public FirebaseConfigExtractorModule(ReactApplicationContext reactContext) {
27
- super(reactContext);
28
- }
29
-
30
- @Override
31
- public String getName() {
32
- return NAME;
33
- }
34
-
35
- @ReactMethod
36
- public void extractConfig(Promise promise) {
37
- Log.d(NAME, "Starting to extract Firebase config.");
38
- try {
39
- // Use AssetManager to read the google-services.json file from the assets folder
40
- AssetManager assetManager = getReactApplicationContext().getAssets();
41
- Log.d(NAME, "Attempting to open google-services.json file.");
42
- InputStream input = assetManager.open("google-services.json");
43
- Log.d(NAME, "google-services.json file opened successfully.");
44
-
45
- // Convert InputStream to String
46
- String json = convertStreamToString(input);
47
-
48
- // Log raw JSON string
49
- Log.d(NAME, "JSON string: " + json);
50
-
51
- // Use JSONObject to parse the JSON string
52
- JSONObject jsonObject = new JSONObject(json);
53
- JSONArray clientArray = jsonObject.getJSONArray("client");
54
- JSONObject clientObject = clientArray.getJSONObject(0);
55
- JSONObject projectInfo = jsonObject.getJSONObject("project_info");
56
- JSONArray apiKeyArray = clientObject.getJSONArray("api_key");
57
- JSONObject apiKeyObject = apiKeyArray.getJSONObject(0);
58
-
59
- // Log parsed objects
60
- Log.d(NAME, "Parsed projectInfo: " + projectInfo.toString());
61
- Log.d(NAME, "Parsed apiKeyObject: " + apiKeyObject.toString());
62
-
63
- // Extract webClientId
64
- JSONArray oauthClientArray = clientObject.getJSONArray("oauth_client");
65
- String webClientId = "";
66
- for (int i = 0; i < oauthClientArray.length(); i++) {
67
- JSONObject oauthClientObject = oauthClientArray.getJSONObject(i);
68
- if (oauthClientObject.getInt("client_type") == 3) {
69
- webClientId = oauthClientObject.getString("client_id");
70
- break;
71
- }
72
- }
73
-
74
- // Extract the values
75
- Map<String, String> config = new HashMap<>();
76
- config.put("webClientId", webClientId);
77
- config.put("apiKey", apiKeyObject.getString("current_key"));
78
- config.put("authDomain", projectInfo.getString("project_id") + ".firebaseapp.com");
79
- config.put("projectId", projectInfo.getString("project_id"));
80
- config.put("storageBucket", projectInfo.getString("storage_bucket"));
81
- config.put("messagingSenderId", projectInfo.getString("project_number"));
82
- config.put("appId", clientObject.getJSONObject("client_info").getString("mobilesdk_app_id"));
83
- // Add logic for measurement ID if needed
84
- config.put("databaseURL", "https://" + projectInfo.getString("project_id") + ".firebaseio.com");
85
-
86
- promise.resolve(config);
87
- } catch (IOException e) {
88
- Log.e(NAME, "Error reading Firebase config file", e);
89
- promise.reject("ERR_IO_EXCEPTION", "Error reading Firebase config file", e);
90
- } catch (Exception e) {
91
- Log.e(NAME, "Error extracting Firebase config on Android", e);
92
- promise.reject("ERR_UNEXPECTED_EXCEPTION", "Error extracting Firebase config on Android", e);
93
- }
94
- }
95
-
96
- // Helper method to convert InputStream to String
97
- private String convertStreamToString(InputStream is) throws IOException {
98
- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
99
- StringBuilder sb = new StringBuilder();
100
- String line;
101
- while ((line = reader.readLine()) != null) {
102
- sb.append(line).append("\n");
103
- }
104
- reader.close();
105
- return sb.toString();
106
- }
107
-
108
- }
@@ -1,30 +0,0 @@
1
- package com.mayofirebaseconfig;
2
-
3
- import androidx.annotation.NonNull;
4
-
5
- import com.facebook.react.ReactPackage;
6
- import com.facebook.react.bridge.NativeModule;
7
- import com.facebook.react.bridge.ReactApplicationContext;
8
- import com.facebook.react.uimanager.ViewManager;
9
-
10
- import java.util.ArrayList;
11
- import java.util.Collections;
12
- import java.util.List;
13
-
14
- public class FirebaseConfigExtractorPackage implements ReactPackage {
15
-
16
- @NonNull
17
- @Override
18
- public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
19
- List<NativeModule> modules = new ArrayList<>();
20
- modules.add(new FirebaseConfigExtractorModule(reactContext));
21
- return modules;
22
- }
23
-
24
- @NonNull
25
- @Override
26
- public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
27
- // Return an empty list if you are not using any view managers
28
- return Collections.emptyList();
29
- }
30
- }