|
| 1 | +# @ripstop/react-native |
| 2 | + |
| 3 | +**Force update, kill switch, maintenance mode and remote config for React Native.** |
| 4 | +Decided at the edge, verified on device. |
| 5 | + |
| 6 | +[](https://www.npmjs.com/package/@ripstop/react-native) |
| 7 | +[](https://github.com/ripstop-dev/ripstop-react-native/actions/workflows/ci.yaml) |
| 8 | +[](LICENSE) |
| 9 | + |
| 10 | +## Install |
| 11 | + |
| 12 | +```bash |
| 13 | +npm install @ripstop/react-native |
| 14 | +``` |
| 15 | + |
| 16 | +No native modules, no pod install, no config plugin. It is JavaScript. |
| 17 | + |
| 18 | +## Quickstart |
| 19 | + |
| 20 | +```tsx |
| 21 | +import { RipstopProvider } from '@ripstop/react-native'; |
| 22 | +import AsyncStorage from '@react-native-async-storage/async-storage'; |
| 23 | +import { asyncStorageAdapter } from '@ripstop/react-native'; |
| 24 | + |
| 25 | +export default function App() { |
| 26 | + return ( |
| 27 | + <RipstopProvider |
| 28 | + apiKey="rs_pub_your_key" |
| 29 | + appVersion={DeviceInfo.getVersion()} |
| 30 | + storage={asyncStorageAdapter(AsyncStorage)} |
| 31 | + > |
| 32 | + <MyApp /> |
| 33 | + </RipstopProvider> |
| 34 | + ); |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +That's the whole integration. The provider renders your app until a decision |
| 39 | +says otherwise, then shows the right wall. |
| 40 | + |
| 41 | +## Or draw your own |
| 42 | + |
| 43 | +```tsx |
| 44 | +const { decision, values, snooze, loading } = useRipstop(); |
| 45 | + |
| 46 | +if (decision.type === 'force') return <MyUpdateScreen {...decision} />; |
| 47 | +``` |
| 48 | + |
| 49 | +Pass `walls={false}` to the provider and nothing is rendered for you. |
| 50 | + |
| 51 | +## Storage |
| 52 | + |
| 53 | +The cache is in-memory unless you give it somewhere to live. AsyncStorage is a |
| 54 | +separate package and the SDK will not add it to your app on your behalf — pass |
| 55 | +your existing instance through `asyncStorageAdapter` and the cache survives |
| 56 | +restarts. |
| 57 | + |
| 58 | +## What it does when things break |
| 59 | + |
| 60 | +| Situation | What your app does | |
| 61 | +| --- | --- | |
| 62 | +| No network | Uses the last **signed** payload | |
| 63 | +| No network, no cache | `none` — your app runs, unrestricted | |
| 64 | +| Server returns 500, or times out | Cache, then normal | |
| 65 | +| Signature doesn't verify | Discarded. A forged payload can never kill your app | |
| 66 | +| Cache tampered with | Re-verified on read, so it grants nothing | |
| 67 | +| Kill switch on, then network lost | The kill **stays**, until a fresh signed payload clears it | |
| 68 | + |
| 69 | +## About `crypto.subtle` |
| 70 | + |
| 71 | +React Native doesn't have it. `@noble/ed25519` backs its SHA-512 with WebCrypto |
| 72 | +by default, so a naive integration verifies fine in every test and throws on the |
| 73 | +first real device. This package wires SHA-512 explicitly from `@noble/hashes`, |
| 74 | +and has a test that deletes `crypto.subtle` before importing anything — because |
| 75 | +a test that runs on Node's fallback would pass whether or not the fix was there. |
| 76 | + |
| 77 | +## Conformance |
| 78 | + |
| 79 | +Every Ripstop SDK runs the same `vectors.json` — version ordering, evaluation |
| 80 | +order, snooze accounting, the fail-open state machine. `npm test` runs it here. |
| 81 | + |
| 82 | +Full docs: **[ripstop.dev/docs/react-native](https://ripstop.dev/docs/react-native)** |
| 83 | + |
| 84 | +## License |
| 85 | + |
| 86 | +MIT |
0 commit comments