react-native-encore-mock
v0.1.0
Published
Mock-first integration kit for the Encore React Native SDK — develop and demo retention offers, brand-sponsored partner trials, and entitlements with zero native dependencies. This is NOT the real SDK.
Maintainers
Readme
react-native-encore-mock
Mock-first integration kit for the Encore React Native SDK.
⚠️ This is not the real SDK. It's an in-memory mock that mirrors Encore's production API surface so you can build, demo, and test retention offers, brand-sponsored partner trials (Disney+, Netflix, Spotify…), and the entitlement flow with zero native dependencies — then switch to the real
@tryencorekit/react-nativeby flipping one constant.
Why
The real Encore SDK is a native module — it needs a dev-client/native build and real campaigns. This kit lets your whole team develop the offer flow without any of that, and keeps going-live a one-line change.
Install
npm install react-native-encore-mock
# peer deps: react >=18, react-native >=0.70Usage
Create one client and pass it to both the provider and your call sites:
// encore.ts — the single indirection in YOUR app
import { createMockEncore } from 'react-native-encore-mock';
// import realEncore from '@tryencorekit/react-native';
export const USE_MOCK = true;
export const Encore = USE_MOCK ? createMockEncore() : realEncore;// App.tsx
import { MockEncoreProvider, useEncoreCallbacks } from 'react-native-encore-mock';
import { Encore } from './encore';
import { billing } from './billing';
function Root() {
useEncoreCallbacks(Encore, {
purchase: (productId) => billing.purchase(productId), // YOUR billing
onResume: (placementId) => {/* resume original action */},
});
return <YourApp />;
}
export default function App() {
return (
<MockEncoreProvider client={Encore} apiKey="pk_your_api_key_here" logLevel="debug">
<Root />
</MockEncoreProvider>
);
}// anywhere — present an offer and react to the result
import { isGranted } from 'react-native-encore-mock';
import { Encore } from './encore';
const result = await Encore.placement('cancellation_flow').show();
if (isGranted(result)) {
// 'granted' (paid) or 'completed' (brand-sponsored) → entitle the user
}Offer types
The mock presents the two kinds Encore serves (configurable via createMockEncore({ offers })):
retention— a paid offer. Accepting runs your billing throughonPurchaseRequest→completePurchaseRequest→status: 'granted'.sponsored— Encore's Brand-Sponsored Premium Trials: a carousel of partner brands. Accepting charges nothing through your billing — it resolves tostatus: 'completed'(the brand sponsors it).
PlacementResult.status ∈ 'granted' | 'completed' | 'not_granted' | 'dismissed' | 'no_offers'.
Customize offers/partners:
import { createMockEncore, DEFAULT_PARTNERS } from 'react-native-encore-mock';
const Encore = createMockEncore({
offers: {
cancellation_flow: {
type: 'sponsored',
placementId: 'cancellation_flow',
campaignId: 'winback_2026',
entitlement: 'subscription',
title: 'Wait — a gift before you go',
subtitle: 'A partner brand will sponsor your next months.',
partners: DEFAULT_PARTNERS,
dismissLabel: 'No thanks',
},
},
});Going live
npm install @tryencorekit/react-native(the real native SDK) + rebuild your native app / dev client.- Set
USE_MOCK = falseand supply a realpk_key. - The real SDK renders the partner carousel natively; this kit is no longer used.
Your screen code (placement().show(), isGranted, callbacks) is identical in
both modes.
API
createMockEncore(config?)→MockEncoreClientMockEncoreProvider—{ client, apiKey, logLevel?, children }useEncoreMockContext()→{ apiKey, isReady }useEncoreCallbacks(encore, { purchase, onResume?, onPurchaseComplete? })isGranted(result)→ booleanDEFAULT_OFFERS,DEFAULT_PARTNERS- Types:
EncoreClient,PlacementResult,MockOffer,PartnerTrial, …
License
MIT
