npm package: @log-drop/react-native
Description: LogDrop React Native SDK
Author: Initial Code
Latest version: 1.0.4

# LogDrop React Native SDK

Official React Native SDK for [LogDrop](https://logdrop.io).
Capture logs, handle push messages, update user info, and send diagnostic data directly from your React Native app to LogDrop.

---

## 📦 Installation

```bash
npm install @log-drop/react-native
# or
yarn add @log-drop/react-native
```

---

## ⚙️ iOS Setup

### 1. Install native dependencies

```bash
cd ios && pod install && cd ..
```

### 2. Initialize LogDrop before your app starts

Add this code **before** `AppRegistry.registerComponent` in your `index.js` or `App.js`:

```ts
import { LogDrop, LogDropConfigBuilder } from '@log-drop/react-native';

const config = new LogDropConfigBuilder()
  .setApiKey('YOUR_API_KEY')
  .setBaseUrl('YOUR_BASE_URL')
  .setLoggingEnabled(true)
  .build();

LogDrop.init(config);
```

> 💡 Make sure to initialize LogDrop **only once** during app startup.

---

## 🤖 Android Setup

### 1. Add the LogDrop Maven repository

In `android/build.gradle`, add inside `allprojects.repositories`:

```gradle
allprojects {
    repositories {
        google()
        maven { url "https://artifactory.logdrop.io/repository/android-logdrop-sdk/" } // Add this line
        maven { url "https://artifactory.logdrop.io/repository/logdrop-gradle-plugin/" } // Add this line
        mavenCentral()
    }
}
```

Then, add the following classpath dependencies to the buildscript section of `android/build.gradle`:

```gradle
classpath("io.logdrop.gradle:plugin:1.0.4")
classpath("io.logdrop.gradle:rnplugin:1.0.1")
```

To enable LogDrop integration, add the following plugins to your `android/app/build.gradle` file:

```gradle
apply plugin: "io.logdrop.gradle.plugin"
apply plugin: "io.logdrop.gradle.plugin.rn"
```

Create a file named logdrop-services.json under the `android/app` directory and add the following content:
```json
{
  "base_url": "https://server.logdrop.io",
  "projects": {
    "com.example.app": {
      "api_key": "YOUR_LOGDROP_API_KEY"
    }
  }
}
```

### 2. Initialize LogDrop in `MainApplication.kt`

```kotlin
override fun onCreate() {
    super.onCreate()
    SoLoader.init(this, OpenSourceMergedSoMapping)

    val config = LogDropReactNativeConfig.Builder(this)
        .apiKey("YOUR_API_KEY")
        .baseUrl("YOUR_BASE_URL")
        .logcatEnabled(true)
        .build()

    LogDropReactNative.initLogDrop(config)
}
```

---

## 🧠 API Reference

### `LogDrop.init(config: LogDropConfig): void`
Initializes the LogDrop SDK with the provided configuration.
- **Required:** Call this before using any other method.
- **iOS only:** This method is used to initialize on iOS (Android handles it natively).

---

### `LogDrop.sendLogs(): void`
Forces the SDK to send any cached logs immediately.

---

### `LogDrop.userUpdate(userId: string): void`
Updates the current user identifier.
Use this when a user logs in or changes identity.

```ts
LogDrop.userUpdate("user_123");
```

---

### Logging Methods

These correspond to standard log levels.

| Method                           | Description | Example                                      |
|----------------------------------|-------------|----------------------------------------------|
| `LogDrop.e(tag, message, flow?)` | Error log   | `LogDrop.e("Auth", "Login failed")`          |
| `LogDrop.w(tag, message, flow?)` | Warning log | `LogDrop.w("Network", "Slow response")`      |
| `LogDrop.i(tag, message, flow?)` | Info log    | `LogDrop.i("Init", "App started")`           |
| `LogDrop.d(tag, message, flow?)` | Debug log   | `LogDrop.d("Cache", "Fetching from memory")` |

> `flow` (optional) is a `LogFlow` instance to track grouped log events.

---

### `LogDrop.onRemoteMessageReceived(message: { [key: string]: string }): void`
Handles incoming push notification payloads.
- **Android only**

```ts
LogDrop.onRemoteMessageReceived(remoteMessage.data);
```

---

### `LogDrop.onNewFcmPushToken(token: string): void`
Registers a new **FCM** (Firebase Cloud Messaging) push token.
- **Android only**

```ts
LogDrop.onNewFcmPushToken(fcmToken);
```

---

### `LogDrop.onNewHmsPushToken(token: string): void`
Registers a new **HMS** (Huawei Mobile Services) push token.
- **Android only**

```ts
LogDrop.onNewHmsPushToken(hmsToken);
```

---

## 🔑 API Keys

You can create and manage your API keys in the LogDrop Dashboard.
Use these in your configuration examples.

---

## 📄 Notes
- Always initialize LogDrop before any other usage.
- Use `userUpdate` after authentication to bind logs to a specific user.