@coinflowlabs/react-native-fraud

中文文档
0.1.2发布于 2026/10/27Apache-2.0TypeScriptCommonJS零依赖近 30 天下载 6.7万

Coinflow fraud protection for React Native — one opaque header, backed by Coinflow's native iOS and Android fraud SDKs.

原始使用文档
文档目录5 节
  1. Install
  2. Usage
  3. Native setup
  4. Example app
  5. Layout

@coinflowlabs/react-native-fraud

Coinflow fraud protection for React Native. A thin bridge over Coinflow's native iOS and Android fraud SDKs that returns a single opaque header to attach to Coinflow API calls.

Install

npm install @coinflowlabs/react-native-fraud

Usage

Wrap your app root so protection boots once:

import {CoinflowProtectionProvider} from '@coinflowlabs/react-native-fraud';

export default function App() {
  return (
    <CoinflowProtectionProvider merchantId={merchantId} env="prod"> {/* 'prod' | 'sandbox' */}
      <RootNavigator />
    </CoinflowProtectionProvider>
  );
}

At charge time, attach the single opaque header:

import {useCoinflowFraudHeaders} from '@coinflowlabs/react-native-fraud';

const getFraudHeaders = useCoinflowFraudHeaders();
const res = await fetch(chargeUrl, {headers: {...(await getFraudHeaders()), ...auth}});
// => {'x-device-id': '<opaque value>'}

Or imperatively via CoinflowFraud.initialize({merchantId, env}) and CoinflowFraud.getPurchaseHeaders().

Changing merchantId or env on CoinflowProtectionProvider re-initializes with the new config. When you call the API imperatively, switch config with CoinflowFraud.initialize({merchantId, env, force: true}). A non-forced call with a different config is ignored.

Neither call ever throws. When the native module isn't linked (Expo Go, web), getPurchaseHeaders() returns {}.

Native setup

The package autolinks a native module that wraps the native SDKs: the CoinflowFraud pod on iOS and cash.coinflow:coinflow-fraud on Android.

  • Expo: add "@coinflowlabs/react-native-fraud" to plugins in your app config. The plugin makes these changes:
    • It points your Podfile at the iOS SDK, which isn't on CocoaPods trunk.
    • It lifts the session provider's pods to iOS 15.1, because they declare 14.0, which current Xcode rejects.
    • On Android, it adds the signal SDKs' Maven repos to your app's android/build.gradle. npx expo run:android needs this because it builds with --configure-on-demand.
  • Bare React Native (iOS): add this line to your Podfile target:
    pod 'CoinflowFraud', :git => 'https://github.com/coinflow-labs-us/coinflow-swift-fraud.git', :tag => 'v0.2.1'
    
    Then add this at the top of your post_install do |installer| block:
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |build_config|
        next unless build_config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 15.1
        build_config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.1'
      end
    end
    
    iOS builds need Xcode 26 or later.
  • Android: usually nothing to configure, because the module adds the signal SDKs' Maven repos itself. Apps that centralize repositories in settings.gradle through dependencyResolutionManagement { repositoriesMode … } are the exception. With FAIL_ON_PROJECT_REPOS the build fails, and with PREFER_SETTINGS the repos are ignored. Those apps add Coinflow's cash.coinflow.fraud.repositories settings plugin to the existing pluginManagement and plugins blocks in android/settings.gradle. It adds the repos in settings, and the module then declares no repositories of its own, so both modes build. The plugin is on Maven Central, so pluginManagement must list mavenCentral():
    pluginManagement {
      repositories {
        gradlePluginPortal()
        mavenCentral()
      }
    }
    
    plugins {
      id("cash.coinflow.fraud.repositories") version "0.1.1"
    }
    

Example app

example/ is a minimal Expo app that wraps its root in CoinflowProtectionProvider and attaches the x-device-id header to a request. It installs this package from npm.

cd example
cp example.env .env
npm install
npx expo run:ios   # or: npx expo run:android

Layout

  • src/ is the JS API, a fail-open wrapper around the native module.
  • ios/ is the Swift bridge to the CoinflowFraud pod (lib/swift-fraud).
  • android/ is the Kotlin bridge to cash.coinflow:coinflow-fraud (lib/android-fraud).
  • app.plugin.js is the Expo config plugin. Inside the Coinflow monorepo, the testbench passes {"localSdkRoot": "../../.."}. With it, iOS builds the pod from lib/swift-fraud and Android resolves the SDK from mavenLocal(), so first run ./gradlew publishToMavenLocal in lib/android-fraud.

版本与发布记录

@coinflowlabs/react-native-fraud 共发布 4 个版本,首次发布于 2026/10/14;过去 12 个月发布了 4 个版本。

版本发布日期距今
0.1.2latest2026/10/2714 天前
0.1.12026/10/1525 天前
0.1.02026/10/1426 天前
0.0.0-stage2026/10/1426 天前

关于 @coinflowlabs/react-native-fraud 的常见问题

@coinflowlabs/react-native-fraud 是什么?

Coinflow fraud protection for React Native — one opaque header, backed by Coinflow's native iOS and Android fraud SDKs.

如何安装 @coinflowlabs/react-native-fraud?

在项目目录运行 npm install @coinflowlabs/react-native-fraud,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16)、react-native(>=0.66.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@coinflowlabs/react-native-fraud 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@coinflowlabs/react-native-fraud 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@coinflowlabs/react-native-fraud 可以商用吗?

@coinflowlabs/react-native-fraud 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@coinflowlabs/react-native-fraud 的下载量有多少?

根据 npm 官方下载统计,@coinflowlabs/react-native-fraud 在 2026/10/11 – 2026/11/09 这 30 天内被下载 66,938 次,日均约 2,231 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@coinflowlabs/react-native-fraud 还在维护吗?

最新版本 0.1.2 发布于 2026/10/27(14 天前);至今共发布 4 个版本,其中过去 12 个月发布了 4 个;首次发布于 2026/10/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。