@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
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Screen exports for @outerjoyn/react-native SDK
|
|
3
|
+
*
|
|
4
|
+
* Full-screen Modal components ported from web SDK widgets:
|
|
5
|
+
* - ConnectScreen: Plaid-style account linking with OAuth flow
|
|
6
|
+
* - ExchangeScreen: points exchange between partner brands
|
|
7
|
+
* - RedeemScreen: browse catalog and redeem points for rewards
|
|
8
|
+
* - AccountScreen: member account overview with connected brands
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export { ConnectScreen } from './ConnectScreen';
|
|
12
|
+
export type { ConnectScreenProps, ConnectResult } from './ConnectScreen';
|
|
13
|
+
|
|
14
|
+
export { ExchangeScreen } from './ExchangeScreen';
|
|
15
|
+
export type { ExchangeScreenProps } from './ExchangeScreen';
|
|
16
|
+
|
|
17
|
+
export { RedeemScreen } from './RedeemScreen';
|
|
18
|
+
export type { RedeemScreenProps } from './RedeemScreen';
|
|
19
|
+
|
|
20
|
+
export { AccountScreen } from './AccountScreen';
|
|
21
|
+
export type { AccountScreenProps } from './AccountScreen';
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
export interface OuterJoynConfig {
|
|
2
|
+
/** SDK session token (ojsdk_live_* or ojsdk_test_*) */
|
|
3
|
+
sessionToken: string;
|
|
4
|
+
/** API base URL override */
|
|
5
|
+
apiBaseUrl?: string;
|
|
6
|
+
/** Theme customization */
|
|
7
|
+
theme?: OuterJoynTheme;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface OuterJoynTheme {
|
|
11
|
+
primaryColor?: string;
|
|
12
|
+
accentColor?: string;
|
|
13
|
+
backgroundColor?: string;
|
|
14
|
+
surfaceColor?: string;
|
|
15
|
+
textColor?: string;
|
|
16
|
+
mutedTextColor?: string;
|
|
17
|
+
borderColor?: string;
|
|
18
|
+
borderRadius?: string;
|
|
19
|
+
fontFamily?: string;
|
|
20
|
+
colorScheme?: 'light' | 'dark' | 'auto';
|
|
21
|
+
buttonStyle?: 'filled' | 'outline' | 'soft';
|
|
22
|
+
shadow?: 'none' | 'sm' | 'md' | 'lg';
|
|
23
|
+
spacing?: 'compact' | 'comfortable' | 'spacious';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface PaySheetProps extends OuterJoynConfig {
|
|
27
|
+
/** Whether the sheet is visible */
|
|
28
|
+
visible: boolean;
|
|
29
|
+
/** Order total in cents */
|
|
30
|
+
orderTotal?: number;
|
|
31
|
+
/** ISO 4217 currency code (default: USD) */
|
|
32
|
+
currencyCode?: string;
|
|
33
|
+
/** Called when payment completes successfully */
|
|
34
|
+
onSuccess?: (result: PayResult) => void;
|
|
35
|
+
/** Called when an error occurs */
|
|
36
|
+
onError?: (error: SDKError) => void;
|
|
37
|
+
/** Called when the user closes the sheet */
|
|
38
|
+
onClose?: () => void;
|
|
39
|
+
/** Called when points selection changes */
|
|
40
|
+
onPointsChanged?: (points: number, valueAmount: number) => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ConnectSheetProps extends OuterJoynConfig {
|
|
44
|
+
visible: boolean;
|
|
45
|
+
onSuccess?: (result: ConnectResult) => void;
|
|
46
|
+
onError?: (error: SDKError) => void;
|
|
47
|
+
onClose?: () => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ExchangeSheetProps extends OuterJoynConfig {
|
|
51
|
+
visible: boolean;
|
|
52
|
+
onSuccess?: (result: ExchangeResult) => void;
|
|
53
|
+
onError?: (error: SDKError) => void;
|
|
54
|
+
onClose?: () => void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface RedeemSheetProps extends OuterJoynConfig {
|
|
58
|
+
visible: boolean;
|
|
59
|
+
onSuccess?: (result: RedeemResult) => void;
|
|
60
|
+
onError?: (error: SDKError) => void;
|
|
61
|
+
onClose?: () => void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface WalletPassButtonProps extends OuterJoynConfig {
|
|
65
|
+
/** Pass type */
|
|
66
|
+
passType?: 'apple' | 'google' | 'both';
|
|
67
|
+
onSuccess?: (result: any) => void;
|
|
68
|
+
onError?: (error: SDKError) => void;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface PromotionsViewProps extends OuterJoynConfig {
|
|
72
|
+
/** Promotion array ID */
|
|
73
|
+
arrayId: string;
|
|
74
|
+
/** Layout style */
|
|
75
|
+
layout?: 'carousel' | 'grid' | 'list';
|
|
76
|
+
/** Height of the promotions view */
|
|
77
|
+
height?: number;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface PayResult {
|
|
81
|
+
reservationId: number;
|
|
82
|
+
status: string;
|
|
83
|
+
pointsUsed: number;
|
|
84
|
+
valueAmount: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface ConnectResult {
|
|
88
|
+
linkedProgramId: number;
|
|
89
|
+
programName: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface ExchangeResult {
|
|
93
|
+
transactionId: number;
|
|
94
|
+
sourceAmount: number;
|
|
95
|
+
targetAmount: number;
|
|
96
|
+
rate: number;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface RedeemResult {
|
|
100
|
+
redemptionId: number;
|
|
101
|
+
status: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface SDKError {
|
|
105
|
+
code: string;
|
|
106
|
+
message: string;
|
|
107
|
+
requestId?: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Internal message types between WebView and native */
|
|
111
|
+
export type WebViewMessage =
|
|
112
|
+
| { type: 'sdk_ready' }
|
|
113
|
+
| { type: 'sdk_event'; event: string; data: any }
|
|
114
|
+
| { type: 'sdk_error'; error: SDKError }
|
|
115
|
+
| { type: 'sdk_close' }
|
|
116
|
+
| { type: 'sdk_success'; result: any };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useOuterJoyn — React hook for accessing the OuterJoyn SDK context.
|
|
3
|
+
*
|
|
4
|
+
* Provides session state, linked programs, balance totals, sheet actions,
|
|
5
|
+
* and brand configuration. Must be called within an `<OuterJoynProvider>`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* function CheckoutButton() {
|
|
10
|
+
* const { isLinked, totalAvailableValue, openPay } = useOuterJoyn();
|
|
11
|
+
*
|
|
12
|
+
* if (!isLinked) return null;
|
|
13
|
+
*
|
|
14
|
+
* return (
|
|
15
|
+
* <Button
|
|
16
|
+
* title={`Pay with ${totalAvailableValue}c in points`}
|
|
17
|
+
* onPress={() => openPay({ orderTotalCents: 2499 })}
|
|
18
|
+
* />
|
|
19
|
+
* );
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { useContext } from 'react';
|
|
25
|
+
import { OuterJoynContext } from './OuterJoynProvider';
|
|
26
|
+
import type { OuterJoynContextValue } from './core/types';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Access the OuterJoyn SDK context.
|
|
30
|
+
*
|
|
31
|
+
* Returns session state, linked programs, balance totals, sheet actions,
|
|
32
|
+
* brand configuration, and an i18n translation function.
|
|
33
|
+
*
|
|
34
|
+
* @throws {Error} If called outside of an `<OuterJoynProvider>`.
|
|
35
|
+
*/
|
|
36
|
+
export function useOuterJoyn(): OuterJoynContextValue {
|
|
37
|
+
const ctx = useContext(OuterJoynContext);
|
|
38
|
+
if (!ctx) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
'useOuterJoyn must be used within an <OuterJoynProvider>. ' +
|
|
41
|
+
'Wrap your component tree with <OuterJoynProvider sessionToken={...}>.',
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return ctx;
|
|
45
|
+
}
|
package/src/widgets.tsx
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced Widget Sheets — Auto-read from OuterJoynProvider context
|
|
3
|
+
*
|
|
4
|
+
* These sheets can be used in two ways:
|
|
5
|
+
* 1. With explicit props (standalone, no provider needed)
|
|
6
|
+
* 2. Inside <OuterJoynProvider> — session token and theme auto-read from context
|
|
7
|
+
*
|
|
8
|
+
* When used inside the provider, all platform SDK setup tab configuration
|
|
9
|
+
* (theme, field visibility, availability) flows through automatically.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import React, { useContext } from 'react';
|
|
13
|
+
import { OuterJoynSheet } from './OuterJoynSheet';
|
|
14
|
+
import type {
|
|
15
|
+
PaySheetProps,
|
|
16
|
+
ConnectSheetProps,
|
|
17
|
+
ExchangeSheetProps,
|
|
18
|
+
RedeemSheetProps,
|
|
19
|
+
} from './types';
|
|
20
|
+
|
|
21
|
+
// Try to read from provider context (optional — sheets work standalone too)
|
|
22
|
+
// This is imported lazily to avoid circular deps when provider imports sheets
|
|
23
|
+
let _contextRef: React.Context<any> | null = null;
|
|
24
|
+
export function _setContextRef(ctx: React.Context<any>) { _contextRef = ctx; }
|
|
25
|
+
|
|
26
|
+
function useOptionalContext() {
|
|
27
|
+
if (!_contextRef) return null;
|
|
28
|
+
try {
|
|
29
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
30
|
+
return useContext(_contextRef);
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Pay with points bottom sheet.
|
|
38
|
+
*
|
|
39
|
+
* When used inside <OuterJoynProvider>, sessionToken and theme are auto-read
|
|
40
|
+
* from context. Only `visible`, `orderTotal`, `onSuccess`, and `onClose` are required.
|
|
41
|
+
*/
|
|
42
|
+
export function PaySheet({
|
|
43
|
+
visible,
|
|
44
|
+
sessionToken,
|
|
45
|
+
apiBaseUrl,
|
|
46
|
+
theme,
|
|
47
|
+
orderTotal,
|
|
48
|
+
currencyCode,
|
|
49
|
+
onSuccess,
|
|
50
|
+
onError,
|
|
51
|
+
onClose,
|
|
52
|
+
onPointsChanged,
|
|
53
|
+
}: PaySheetProps) {
|
|
54
|
+
const ctx = useOptionalContext();
|
|
55
|
+
const token = sessionToken || ctx?.sessionToken;
|
|
56
|
+
const base = apiBaseUrl || ctx?.apiBaseUrl;
|
|
57
|
+
const resolvedTheme = theme || ctx?.brandConfig?.theme;
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<OuterJoynSheet
|
|
61
|
+
visible={visible}
|
|
62
|
+
sessionToken={token}
|
|
63
|
+
apiBaseUrl={base}
|
|
64
|
+
theme={resolvedTheme}
|
|
65
|
+
module="pay"
|
|
66
|
+
title="Pay with Points"
|
|
67
|
+
onSuccess={(result) => {
|
|
68
|
+
onSuccess?.(result);
|
|
69
|
+
ctx?.refreshBalances?.();
|
|
70
|
+
}}
|
|
71
|
+
onError={onError}
|
|
72
|
+
onClose={onClose}
|
|
73
|
+
widgetOptions={{
|
|
74
|
+
...(orderTotal !== undefined ? { orderTotal } : {}),
|
|
75
|
+
...(currencyCode !== undefined ? { currencyCode } : {}),
|
|
76
|
+
...(onPointsChanged ? { onPointsChanged } : {}),
|
|
77
|
+
}}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Account linking bottom sheet.
|
|
84
|
+
*
|
|
85
|
+
* On success, auto-refreshes balances if inside <OuterJoynProvider>.
|
|
86
|
+
*/
|
|
87
|
+
export function ConnectSheet({
|
|
88
|
+
visible,
|
|
89
|
+
sessionToken,
|
|
90
|
+
apiBaseUrl,
|
|
91
|
+
theme,
|
|
92
|
+
onSuccess,
|
|
93
|
+
onError,
|
|
94
|
+
onClose,
|
|
95
|
+
}: ConnectSheetProps) {
|
|
96
|
+
const ctx = useOptionalContext();
|
|
97
|
+
const token = sessionToken || ctx?.sessionToken;
|
|
98
|
+
const base = apiBaseUrl || ctx?.apiBaseUrl;
|
|
99
|
+
const resolvedTheme = theme || ctx?.brandConfig?.theme;
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<OuterJoynSheet
|
|
103
|
+
visible={visible}
|
|
104
|
+
sessionToken={token}
|
|
105
|
+
apiBaseUrl={base}
|
|
106
|
+
theme={resolvedTheme}
|
|
107
|
+
module="connect"
|
|
108
|
+
title="Link Account"
|
|
109
|
+
onSuccess={(result) => {
|
|
110
|
+
onSuccess?.(result);
|
|
111
|
+
ctx?.refreshBalances?.();
|
|
112
|
+
}}
|
|
113
|
+
onError={onError}
|
|
114
|
+
onClose={onClose}
|
|
115
|
+
/>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Points exchange bottom sheet.
|
|
121
|
+
*
|
|
122
|
+
* On success, auto-refreshes balances if inside <OuterJoynProvider>.
|
|
123
|
+
*/
|
|
124
|
+
export function ExchangeSheet({
|
|
125
|
+
visible,
|
|
126
|
+
sessionToken,
|
|
127
|
+
apiBaseUrl,
|
|
128
|
+
theme,
|
|
129
|
+
onSuccess,
|
|
130
|
+
onError,
|
|
131
|
+
onClose,
|
|
132
|
+
}: ExchangeSheetProps) {
|
|
133
|
+
const ctx = useOptionalContext();
|
|
134
|
+
const token = sessionToken || ctx?.sessionToken;
|
|
135
|
+
const base = apiBaseUrl || ctx?.apiBaseUrl;
|
|
136
|
+
const resolvedTheme = theme || ctx?.brandConfig?.theme;
|
|
137
|
+
|
|
138
|
+
return (
|
|
139
|
+
<OuterJoynSheet
|
|
140
|
+
visible={visible}
|
|
141
|
+
sessionToken={token}
|
|
142
|
+
apiBaseUrl={base}
|
|
143
|
+
theme={resolvedTheme}
|
|
144
|
+
module="exchange"
|
|
145
|
+
title="Exchange Points"
|
|
146
|
+
onSuccess={(result) => {
|
|
147
|
+
onSuccess?.(result);
|
|
148
|
+
ctx?.refreshBalances?.();
|
|
149
|
+
}}
|
|
150
|
+
onError={onError}
|
|
151
|
+
onClose={onClose}
|
|
152
|
+
/>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Reward redemption bottom sheet.
|
|
158
|
+
*
|
|
159
|
+
* On success, auto-refreshes balances if inside <OuterJoynProvider>.
|
|
160
|
+
*/
|
|
161
|
+
export function RedeemSheet({
|
|
162
|
+
visible,
|
|
163
|
+
sessionToken,
|
|
164
|
+
apiBaseUrl,
|
|
165
|
+
theme,
|
|
166
|
+
onSuccess,
|
|
167
|
+
onError,
|
|
168
|
+
onClose,
|
|
169
|
+
}: RedeemSheetProps) {
|
|
170
|
+
const ctx = useOptionalContext();
|
|
171
|
+
const token = sessionToken || ctx?.sessionToken;
|
|
172
|
+
const base = apiBaseUrl || ctx?.apiBaseUrl;
|
|
173
|
+
const resolvedTheme = theme || ctx?.brandConfig?.theme;
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<OuterJoynSheet
|
|
177
|
+
visible={visible}
|
|
178
|
+
sessionToken={token}
|
|
179
|
+
apiBaseUrl={base}
|
|
180
|
+
theme={resolvedTheme}
|
|
181
|
+
module="redeem"
|
|
182
|
+
title="Redeem Reward"
|
|
183
|
+
onSuccess={(result) => {
|
|
184
|
+
onSuccess?.(result);
|
|
185
|
+
ctx?.refreshBalances?.();
|
|
186
|
+
}}
|
|
187
|
+
onError={onError}
|
|
188
|
+
onClose={onClose}
|
|
189
|
+
/>
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Account management sheet */
|
|
194
|
+
export function AccountSheet({
|
|
195
|
+
visible,
|
|
196
|
+
sessionToken,
|
|
197
|
+
apiBaseUrl,
|
|
198
|
+
theme,
|
|
199
|
+
onClose,
|
|
200
|
+
onError,
|
|
201
|
+
}: {
|
|
202
|
+
visible: boolean;
|
|
203
|
+
sessionToken?: string;
|
|
204
|
+
apiBaseUrl?: string;
|
|
205
|
+
theme?: any;
|
|
206
|
+
onClose?: () => void;
|
|
207
|
+
onError?: (error: any) => void;
|
|
208
|
+
}) {
|
|
209
|
+
const ctx = useOptionalContext();
|
|
210
|
+
const token = sessionToken || ctx?.sessionToken;
|
|
211
|
+
const base = apiBaseUrl || ctx?.apiBaseUrl;
|
|
212
|
+
const resolvedTheme = theme || ctx?.brandConfig?.theme;
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<OuterJoynSheet
|
|
216
|
+
visible={visible}
|
|
217
|
+
sessionToken={token}
|
|
218
|
+
apiBaseUrl={base}
|
|
219
|
+
theme={resolvedTheme}
|
|
220
|
+
module="account"
|
|
221
|
+
title="My Account"
|
|
222
|
+
onClose={onClose}
|
|
223
|
+
onError={onError}
|
|
224
|
+
/>
|
|
225
|
+
);
|
|
226
|
+
}
|