@outerjoyn/react-native 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -0
- package/package.json +57 -0
- package/src/NativeSDK.ts +164 -0
- package/src/OuterJoynProvider.tsx +828 -0
- package/src/OuterJoynSDK.ts +261 -0
- package/src/OuterJoynSheet.tsx +218 -0
- package/src/PromotionsView.tsx +76 -0
- package/src/components/BalanceSummary.tsx +267 -0
- package/src/components/CheckoutPointsApply.tsx +787 -0
- package/src/components/LoyaltyBanner.tsx +281 -0
- package/src/components/LoyaltyProfileSection.tsx +273 -0
- package/src/components/PostCheckoutSavePrompt.tsx +369 -0
- package/src/components/index.ts +30 -0
- package/src/core/ErrorBoundary.tsx +51 -0
- package/src/core/analytics.ts +264 -0
- package/src/core/api-client.ts +253 -0
- package/src/core/colors.ts +20 -0
- package/src/core/event-stream.ts +229 -0
- package/src/core/i18n.ts +666 -0
- package/src/core/offline.ts +148 -0
- package/src/core/types.ts +214 -0
- package/src/core/version.ts +2 -0
- package/src/html.ts +154 -0
- package/src/index.ts +102 -0
- package/src/screens/AccountScreen.tsx +701 -0
- package/src/screens/ConnectScreen.tsx +1499 -0
- package/src/screens/ExchangeScreen.tsx +706 -0
- package/src/screens/RedeemScreen.tsx +683 -0
- package/src/screens/index.ts +21 -0
- package/src/types.ts +116 -0
- package/src/useOuterJoyn.ts +45 -0
- package/src/widgets.tsx +226 -0
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# @outerjoyn/react-native
|
|
2
|
+
|
|
3
|
+
Drop-in loyalty SDK for React Native. Let your customers pay with loyalty points at checkout.
|
|
4
|
+
|
|
5
|
+
**Works in Expo Go** — no native modules, no config plugins, no ejecting.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @outerjoyn/react-native
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
That's it. No `pod install`, no Gradle changes, no Expo config plugins.
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
### 1. Server-side: Create a session token
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
// Your backend
|
|
21
|
+
const outerjoyn = new OuterJoyn('oj_live_YOUR_API_KEY');
|
|
22
|
+
|
|
23
|
+
app.post('/api/loyalty-session', async (req, res) => {
|
|
24
|
+
const session = await outerjoyn.sessions.create({
|
|
25
|
+
partner_member_id: req.user.id,
|
|
26
|
+
scopes: ['link', 'balance:read', 'pay'],
|
|
27
|
+
});
|
|
28
|
+
res.json({ token: session.token });
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### 2. Client-side: Wrap your app
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { OuterJoynProvider } from '@outerjoyn/react-native';
|
|
36
|
+
|
|
37
|
+
export default function App() {
|
|
38
|
+
const [token, setToken] = useState(null);
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
fetch('https://yourapi.com/api/loyalty-session', { method: 'POST' })
|
|
42
|
+
.then(r => r.json())
|
|
43
|
+
.then(d => setToken(d.token));
|
|
44
|
+
}, []);
|
|
45
|
+
|
|
46
|
+
if (!token) return <ActivityIndicator />;
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<OuterJoynProvider sessionToken={token}>
|
|
50
|
+
<Navigation />
|
|
51
|
+
</OuterJoynProvider>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 3. Add components
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
import { LoyaltyBanner, useOuterJoyn } from '@outerjoyn/react-native';
|
|
60
|
+
|
|
61
|
+
function HomeScreen() {
|
|
62
|
+
return <LoyaltyBanner />;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function CheckoutScreen() {
|
|
66
|
+
const { openPay } = useOuterJoyn();
|
|
67
|
+
return (
|
|
68
|
+
<Button title="Pay with Points" onPress={() => openPay({ orderTotalCents: 4999 })} />
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**~20 lines of code.** Theme, field visibility, and availability come from platform config automatically.
|
|
74
|
+
|
|
75
|
+
## Components
|
|
76
|
+
|
|
77
|
+
### Provider + Hook
|
|
78
|
+
|
|
79
|
+
| Export | Description |
|
|
80
|
+
|--------|-------------|
|
|
81
|
+
| `<OuterJoynProvider>` | Wraps your app. Session lifecycle, balance state, demo fallback. |
|
|
82
|
+
| `useOuterJoyn()` | Hook: `linkedPrograms`, `openPay()`, `openConnect()`, `t()`, etc. |
|
|
83
|
+
|
|
84
|
+
### Inline Components (pure RN, no WebView)
|
|
85
|
+
|
|
86
|
+
| Component | Description |
|
|
87
|
+
|-----------|-------------|
|
|
88
|
+
| `<LoyaltyBanner>` | Home/product page banner. Brand logos + balance. |
|
|
89
|
+
| `<BalanceSummary>` | Balance display: `compact`, `card`, or `inline` layout. |
|
|
90
|
+
| `<CheckoutPointsApply>` | Per-program sliders at checkout. Brand-colored tracks. |
|
|
91
|
+
| `<LoyaltyProfileSection>` | Profile card with linked programs + unlink. |
|
|
92
|
+
| `<PostCheckoutSavePrompt>` | Post-checkout phone OTP to save programs. |
|
|
93
|
+
|
|
94
|
+
### Full-Screen Widgets (pure RN)
|
|
95
|
+
|
|
96
|
+
| Component | Description |
|
|
97
|
+
|-----------|-------------|
|
|
98
|
+
| `<ConnectScreen>` | Brand picker + OAuth consent + account linking. |
|
|
99
|
+
| `<ExchangeScreen>` | Exchange points between programs. |
|
|
100
|
+
| `<RedeemScreen>` | Browse and redeem rewards. |
|
|
101
|
+
| `<AccountScreen>` | Profile, connected brands, activity. |
|
|
102
|
+
|
|
103
|
+
## Test Mode
|
|
104
|
+
|
|
105
|
+
Automatic based on API key prefix:
|
|
106
|
+
- `oj_test_...` → sandbox (test data)
|
|
107
|
+
- `oj_live_...` → production (real transactions)
|
|
108
|
+
|
|
109
|
+
## Demo Mode
|
|
110
|
+
|
|
111
|
+
If the API is unreachable, the SDK auto-falls back to demo mode with sample data. All mutation actions disabled. No crashes.
|
|
112
|
+
|
|
113
|
+
## Theming
|
|
114
|
+
|
|
115
|
+
Configured in OuterJoyn platform (app.outerjoyn.com → SDK Settings). Override with `appearance` prop:
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
<OuterJoynProvider sessionToken={token} appearance={{ colors: { primary: '#FF6B35' } }} />
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Localization
|
|
122
|
+
|
|
123
|
+
Auto-detects device locale. 6 languages: EN, ES, FR, PT, DE, JA. Override any string.
|
|
124
|
+
|
|
125
|
+
## Real-Time Updates
|
|
126
|
+
|
|
127
|
+
`npm install react-native-sse` — auto-detected, balances update live.
|
|
128
|
+
|
|
129
|
+
## Requirements
|
|
130
|
+
|
|
131
|
+
- React Native 0.72+ / Expo SDK 49+
|
|
132
|
+
- Works in Expo Go
|
|
133
|
+
- iOS 14+ / Android API 24+
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@outerjoyn/react-native",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Drop-in loyalty SDK for React Native. Works in Expo Go.",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"react-native": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"src",
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"typecheck": "tsc --noEmit"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"outerjoyn",
|
|
18
|
+
"loyalty",
|
|
19
|
+
"react-native",
|
|
20
|
+
"sdk",
|
|
21
|
+
"mobile",
|
|
22
|
+
"points",
|
|
23
|
+
"rewards",
|
|
24
|
+
"expo"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": ">=18.0.0",
|
|
29
|
+
"react-native": ">=0.72.0",
|
|
30
|
+
"@react-native-community/slider": ">=4.0.0",
|
|
31
|
+
"@react-native-async-storage/async-storage": ">=1.19.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependenciesMeta": {
|
|
34
|
+
"@react-native-async-storage/async-storage": {
|
|
35
|
+
"optional": true
|
|
36
|
+
},
|
|
37
|
+
"react-native-webview": {
|
|
38
|
+
"optional": true
|
|
39
|
+
},
|
|
40
|
+
"react-native-sse": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"optionalPeerDependencies": {
|
|
45
|
+
"react-native-webview": ">=13.0.0",
|
|
46
|
+
"react-native-sse": ">=2.0.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"react": "^18.2.0",
|
|
50
|
+
"react-native": "^0.73.0",
|
|
51
|
+
"react-native-webview": "^13.6.0",
|
|
52
|
+
"@react-native-community/slider": "^4.5.0",
|
|
53
|
+
"@react-native-async-storage/async-storage": "^1.23.0",
|
|
54
|
+
"@types/react": "^18.2.0",
|
|
55
|
+
"typescript": "^5.4.0"
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/NativeSDK.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native SDK Bridge — Imperative API for presenting OuterJoyn widgets
|
|
3
|
+
* via native bottom sheets (iOS UISheetPresentationController / Android ModalBottomSheet).
|
|
4
|
+
*
|
|
5
|
+
* This bridges to the native OuterJoynSDK (Swift/Kotlin) packages.
|
|
6
|
+
* Falls back to the WebView-based OuterJoynSheet if native modules aren't available.
|
|
7
|
+
*
|
|
8
|
+
* ## Usage
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { OuterJoynNativeSDK } from '@outerjoyn/react-native';
|
|
11
|
+
*
|
|
12
|
+
* // Configure
|
|
13
|
+
* OuterJoynNativeSDK.configure({
|
|
14
|
+
* appearance: {
|
|
15
|
+
* colors: { primary: '#6B21A8' },
|
|
16
|
+
* shapes: { cornerRadius: 12 },
|
|
17
|
+
* },
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // Present
|
|
21
|
+
* const result = await OuterJoynNativeSDK.present('pay', {
|
|
22
|
+
* sessionToken: 'ojsdk_live_...',
|
|
23
|
+
* orderTotalCents: 4999,
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { NativeModules, Platform } from 'react-native';
|
|
29
|
+
|
|
30
|
+
// =============================================================================
|
|
31
|
+
// Types
|
|
32
|
+
// =============================================================================
|
|
33
|
+
|
|
34
|
+
export type WidgetType = 'pay' | 'exchange' | 'redeem' | 'connect' | 'account';
|
|
35
|
+
|
|
36
|
+
export interface NativeAppearance {
|
|
37
|
+
colors?: {
|
|
38
|
+
primary?: string;
|
|
39
|
+
accent?: string;
|
|
40
|
+
background?: string;
|
|
41
|
+
surface?: string;
|
|
42
|
+
text?: string;
|
|
43
|
+
textMuted?: string;
|
|
44
|
+
success?: string;
|
|
45
|
+
error?: string;
|
|
46
|
+
sliderFill?: string;
|
|
47
|
+
};
|
|
48
|
+
shapes?: {
|
|
49
|
+
cornerRadius?: number;
|
|
50
|
+
borderWidth?: number;
|
|
51
|
+
};
|
|
52
|
+
typography?: {
|
|
53
|
+
fontFamily?: string;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface NativeWidgetConfig {
|
|
58
|
+
sessionToken: string;
|
|
59
|
+
apiBaseUrl?: string;
|
|
60
|
+
orderTotalCents?: number;
|
|
61
|
+
direction?: 'inbound_only' | 'outbound_only' | 'bidirectional';
|
|
62
|
+
lockTargetToBrand?: boolean;
|
|
63
|
+
lockSourceToBrand?: boolean;
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface NativeSDKConfig {
|
|
68
|
+
appearance?: NativeAppearance;
|
|
69
|
+
apiBaseUrl?: string;
|
|
70
|
+
callbackScheme?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// =============================================================================
|
|
74
|
+
// Native Module Interface
|
|
75
|
+
// =============================================================================
|
|
76
|
+
|
|
77
|
+
interface OuterJoynNativeModule {
|
|
78
|
+
configure(config: string): void;
|
|
79
|
+
present(widget: string, config: string): Promise<string>;
|
|
80
|
+
dismiss(): void;
|
|
81
|
+
startOAuthLinking(connectToken: string): Promise<string>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// =============================================================================
|
|
85
|
+
// SDK Class
|
|
86
|
+
// =============================================================================
|
|
87
|
+
|
|
88
|
+
class OuterJoynNativeSDKImpl {
|
|
89
|
+
private nativeModule: OuterJoynNativeModule | null = null;
|
|
90
|
+
private config: NativeSDKConfig = {};
|
|
91
|
+
|
|
92
|
+
constructor() {
|
|
93
|
+
// Try to load native module
|
|
94
|
+
try {
|
|
95
|
+
this.nativeModule = NativeModules.OuterJoynSDK as OuterJoynNativeModule | null;
|
|
96
|
+
} catch {
|
|
97
|
+
this.nativeModule = null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Whether native SDK modules are available.
|
|
103
|
+
* If false, falls back to WebView-based sheets.
|
|
104
|
+
*/
|
|
105
|
+
get isNativeAvailable(): boolean {
|
|
106
|
+
return this.nativeModule != null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Configure the SDK appearance and settings.
|
|
111
|
+
*/
|
|
112
|
+
configure(config: NativeSDKConfig): void {
|
|
113
|
+
this.config = config;
|
|
114
|
+
if (this.nativeModule) {
|
|
115
|
+
this.nativeModule.configure(JSON.stringify(config));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Present a widget using the native bottom sheet.
|
|
121
|
+
*
|
|
122
|
+
* Returns a promise that resolves with the widget result (success)
|
|
123
|
+
* or rejects with an error.
|
|
124
|
+
*/
|
|
125
|
+
async present(widget: WidgetType, config: NativeWidgetConfig): Promise<any> {
|
|
126
|
+
if (!this.nativeModule) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
'[OuterJoynSDK] Native module not available. ' +
|
|
129
|
+
'Install @outerjoyn/ios or @outerjoyn/android, ' +
|
|
130
|
+
'or use the WebView-based sheets as a fallback.'
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const resultJson = await this.nativeModule.present(widget, JSON.stringify(config));
|
|
135
|
+
return JSON.parse(resultJson);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Dismiss the currently presented widget.
|
|
140
|
+
*/
|
|
141
|
+
dismiss(): void {
|
|
142
|
+
this.nativeModule?.dismiss();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Start OAuth account linking via native browser.
|
|
147
|
+
*
|
|
148
|
+
* Uses ASWebAuthenticationSession (iOS) or Chrome Custom Tabs (Android).
|
|
149
|
+
* NOT a WebView — shares browser cookies for SSO.
|
|
150
|
+
*/
|
|
151
|
+
async startOAuthLinking(connectToken: string): Promise<{ code: string }> {
|
|
152
|
+
if (!this.nativeModule) {
|
|
153
|
+
throw new Error('[OuterJoynSDK] Native module not available for OAuth.');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const resultJson = await this.nativeModule.startOAuthLinking(connectToken);
|
|
157
|
+
return JSON.parse(resultJson);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Singleton instance of the native SDK bridge.
|
|
163
|
+
*/
|
|
164
|
+
export const OuterJoynNativeSDK = new OuterJoynNativeSDKImpl();
|