npm package: @ravin007/ota-kit
Description: General-purpose OTA toolkit for React Native apps.
Latest version: 0.2.2

# ota-kit-library

General-purpose OTA toolkit for React Native apps.

This project contains:
- A client SDK (`OtaClient`) for update checks
- A React Native state store (`AsyncStorageStateStore`)
- A simple publisher CLI (`ota-kit-publish`) to generate OTA manifests
- A full workflow CLI (`ota-kit-workflow`) for build + manifest + backend publish
- A backend template (`backend-template/`) with APIs, DB migration, rollout, and rollback

## 1) Install in your app

```bash
yarn add @ravin007/ota-kit
yarn add @react-native-async-storage/async-storage
```

or

```bash
npm i @ravin007/ota-kit @react-native-async-storage/async-storage
```

## 2) App-side usage

```ts
import AsyncStorage from "@react-native-async-storage/async-storage";
import * as FileSystem from "expo-file-system";
import { AsyncStorageStateStore, createExpoLikeUpdates } from "@ravin007/ota-kit";

const store = new AsyncStorageStateStore(AsyncStorage);
const OtaUpdates = createExpoLikeUpdates(
  {
    checkUrl: "https://api.example.com/ota/check",
    appId: "com.example.app",
    branch: "main",
    platform: "android",
    nativeVersion: "3.0.1",
    runtimeVersion: "3.0.1"
  }, store, {
    fileSystem: FileSystem,
    storage: AsyncStorage
  }, {
    verifySignature: async (manifest) => {
      // Plug your public-key verification here.
      // Return false to reject tampered manifests.
      return Boolean(manifest.signature);
    }
  }
);

const update = await OtaUpdates.checkForUpdateAsync();
if (update.isAvailable) {
  await OtaUpdates.fetchUpdateAsync();
}
```

## 3) Generate manifest in CI/CD

```bash
ota-kit-publish \
  --appId com.example.app \
  --branch main \
  --runtimeVersion 3.0.1 \
  --minNativeVersion 3.0.1 \
  --bundle ./build/index.android.bundle \
  --baseUrl https://cdn.example.com/ota/main/3.0.2 \
  --out ./build/manifest.json
```

Upload bundle + manifest to your storage/CDN, then your backend `ota/check` endpoint returns this manifest to eligible clients.

## 4) Full workflow from app repo (expo-like terminal flow)

From your app project root (the one containing `app.json`):

```bash
npx ota-kit-workflow production "New design and bug fixes"
```

Other commands:

```bash
npx ota-kit-workflow preview "QA release"
npx ota-kit-workflow status
npx ota-kit-workflow rollback
```

`ota-kit-workflow` reads OTA endpoints from `app.json -> expo.extra.ota`.
By default it tries `react-native bundle`, and if build deps are missing it automatically falls back to `expo export`.
By default it uses a temporary working directory and cleans artifacts after publish.

Optional config in `app.json -> expo.extra.ota`:
- `bundleStrategy`: `auto` (default), `react-native`, or `expo`
- `keepArtifacts`: `true` to keep local artifacts (default: `false`)

## Backend template

Use `backend-template/` for production backend bootstrap:
- SQL migration with all OTA tables
- Public APIs: `/ota/check`, `/ota/health`
- Admin APIs: publish/rollout/rollback/releases/status
- Auto rollback thresholds
- Optional manifest signature generation

## 5) Publish this library to npm

```bash
npm login
npm run build
npm publish --access public
```

## 6) GitHub Actions example

See `.github/workflows/release.yml` for publish automation.

## Notes

- This package handles update check contracts and state.
- Loading downloaded JS bundle at native startup still requires iOS/Android integration in each app.
- Native module changes are not OTA-safe; ship those via app store builds.