# react-native-consumet

React Native library providing access to entertainment media information (anime, movies, manga, etc.) from multiple sources, adapting the [Consumet](https://github.com/consumet/consumet.ts) Node Package for mobile applications.

<a href="https://www.npmjs.com/package/react-native-consumet">
  <img src="https://img.shields.io/npm/v/react-native-consumet" alt="npm version" />
</a>
<a href="https://github.com/uwumilabs/react-native-consumet/blob/main/LICENSE">
  <img src="https://img.shields.io/github/license/uwumilabs/react-native-consumet" alt="license" />
</a>
<a href="https://github.com/uwumilabs/react-native-consumet/actions/workflows/ci.yml">
  <img
    src="https://img.shields.io/github/actions/workflow/status/uwumilabs/react-native-consumet/ci.yml?label=ci"
    alt="CI Workflow Status"
  />
</a>
<a href="https://discord.gg/n7xVPxbG4R">
  <img
    src="https://img.shields.io/discord/1387063063223599265?color=7289da&label=discord&logo=discord&logoColor=7289d"
    alt="discord"
  />
</a>

## 📚 Documentation

**New to React Native Consumet?** Start here:

- **[📖 Getting Started Guide](./docs/guides/getting-started.md)** - Complete setup and basic usage
- **[🔧 Extension Integration](./docs/extension-integration.md)** - Using the powerful extension system (Recommended)
- **[📋 Full Documentation](./docs/README.md)** - Complete documentation index

### Provider-Specific Guides

- **[🎬 Anime Providers](./docs/guides/anime.md)** - Anime streaming providers
- **[🎥 Movie Providers](./docs/guides/movies.md)** - Movie and TV show providers
- **[📚 Manga Providers](./docs/guides/manga.md)** - Manga reading providers
- **[📖 Light Novel Providers](./docs/guides/light-novels.md)** - Light novel providers
- **[🔍 Meta Providers](./docs/guides/meta.md)** - Metadata and search providers
- **[🔒 Security Model](./docs/security.md)** - How dynamic code execution is protected
- **[⬆️ Upgrading](./docs/migrations/README.md)** - Breaking and behaviour changes since 1.6.0, with migration notes

## Installation

```sh
npm install react-native-consumet react-native-get-random-values
# or yarn add react-native-consumet react-native-get-random-values
```

`react-native-get-random-values` is a peer dependency: it ships native code, and React Native autolinking only links packages your app depends on directly. Install it in your app (in Expo apps, `npx expo install react-native-get-random-values` picks a compatible version), then rebuild the native app, e.g. `cd ios && pod install` for bare iOS projects. Versions 1.8.0 and later 1.x, and 2.x, are supported. The library imports it from its entry point to polyfill `crypto.getRandomValues`, so you don't import it yourself.

> [!IMPORTANT]  
> This library has been primarily tested on Android devices. iOS testing is currently limited due to lack of MacBook access, so some providers may not work correctly on iOS. Contributions from developers with iOS testing capabilities are greatly appreciated!

> [!NOTE]
> This library is actively maintained but may occasionally lag behind the latest Consumet API changes. The project is in early development and some features may be incomplete or require refinement. If you encounter any issues or have suggestions, please open an issue on GitHub.

## Quick Start

```tsx
import React, { useState } from 'react';
import { Button } from 'react-native';
import { ProviderManager, ExtensionRegistry, type IAnimeResult } from 'react-native-consumet';

// One manager for the app, built from the bundled registry (or one your app downloads)
const manager = new ProviderManager(ExtensionRegistry);

// Example usage in a component
const MyAnimeComponent = () => {
  const [animeList, setAnimeList] = useState<IAnimeResult[]>([]);

  const fetchAnime = async () => {
    try {
      // Load a provider by its registry id; its code is downloaded once and hash-checked
      const animepahe = await manager.getAnimeProvider('animepahe');
      const results = await animepahe.search('one piece');
      setAnimeList(results.results);
    } catch (error) {
      console.error('Error fetching anime:', error);
    }
  };

  // Your component JSX: render animeList
  return <Button title={`Search (${animeList.length} results)`} onPress={fetchAnime} />;
};
```

> **💡 Want more examples?** Check out our [📖 Getting Started Guide](./docs/guides/getting-started.md) for detailed examples and best practices!

> **🚀 Using Extensions?** We recommend the [Extension System](./docs/extension-integration.md) for better performance and unified API access.

## ✨ Features

- **🎬 Multi-Provider Support**: Anime, Movies, Manga, Light Novels, and more
- **🔧 Extension System**: Dynamic provider loading with unified API
- **📱 React Native Optimized**: Built specifically for mobile applications
- **🔍 Cross-Provider Search**: Search across multiple providers simultaneously
- **📚 Comprehensive Documentation**: Detailed guides for every use case
- **🤝 Active Community**: Open source with regular updates

## 🔒 Security

Provider and extractor code is fetched at runtime and executed via `new Function()`. The library protects against CDN compromise and MITM attacks using **SHA-256 subresource integrity** — every entry in `extension-registry.json` carries a hash of its compiled JS file, verified before execution. `factoryName` values are also validated as bare identifiers before being interpolated into the function template, and an invalid registry is rejected with a `RegistryError` instead of being used.

Apps that download the registry instead of using the bundled one should check its **ed25519 signature** with `parseSignedRegistry`: CI signs the registry on `main` and publishes the signature next to it. Verification fails closed, and until a release bundles a signing key it rejects every downloaded registry, so keep the bundled one until then (see [Downloaded Registries and Signatures](./docs/extension-integration.md#downloaded-registries-and-signatures)).

See [docs/security.md](./docs/security.md) for the full threat model and guidance for custom registry consumers.

## 🤝 Contributing

We welcome contributions! Please check out:

- **[🤝 Contributing Guide](CONTRIBUTING.md)** - Detailed contribution guidelines
- **[➕ Adding a New Provider](./docs/guides/adding-new-provider.md)** - How to add new providers
- **[📁 Provider Documentation](./docs/providers/)** - Per-provider API pages

## 📄 License

Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
