@outerjoyn/react-native 1.8.0 → 1.10.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/package.json +1 -1
- package/src/OuterJoynSheet.tsx +10 -3
- package/src/PromotionsView.tsx +3 -0
- package/src/appLink.ts +21 -0
- package/src/core/version.ts +1 -1
- package/src/screens/ConnectScreen.tsx +30 -4
- package/src/types.ts +2 -1
package/package.json
CHANGED
package/src/OuterJoynSheet.tsx
CHANGED
|
@@ -30,6 +30,7 @@ import { WebView } from 'react-native-webview';
|
|
|
30
30
|
const WebViewTyped = WebView<{}>;
|
|
31
31
|
import type { WebViewMessage, SDKError } from './types';
|
|
32
32
|
import { generateWidgetHTML } from './html';
|
|
33
|
+
import { openAppLink } from './appLink';
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* True for a wallet-pass hand-off URL that must go to the OS, not the WebView.
|
|
@@ -111,6 +112,9 @@ export function OuterJoynSheet({
|
|
|
111
112
|
case 'sdk_close':
|
|
112
113
|
onClose?.();
|
|
113
114
|
break;
|
|
115
|
+
case 'open_app_link':
|
|
116
|
+
openAppLink(msg.payload);
|
|
117
|
+
break;
|
|
114
118
|
}
|
|
115
119
|
} catch {
|
|
116
120
|
// Ignore non-JSON messages
|
|
@@ -119,6 +123,8 @@ export function OuterJoynSheet({
|
|
|
119
123
|
[onSuccess, onError, onClose],
|
|
120
124
|
);
|
|
121
125
|
|
|
126
|
+
const surface = theme?.backgroundColor ? { backgroundColor: theme.backgroundColor } : null;
|
|
127
|
+
|
|
122
128
|
const handleClose = useCallback(() => {
|
|
123
129
|
onClose?.();
|
|
124
130
|
}, [onClose]);
|
|
@@ -132,13 +138,14 @@ export function OuterJoynSheet({
|
|
|
132
138
|
>
|
|
133
139
|
<View style={styles.overlay}>
|
|
134
140
|
<View
|
|
135
|
-
|
|
141
|
+
// The brand's window colour, so a dark widget has no white header or corners around it.
|
|
142
|
+
style={[styles.sheet, { height: `${heightRatio * 100}%` as any }, surface]}
|
|
136
143
|
>
|
|
137
144
|
<View style={styles.safeArea}>
|
|
138
145
|
{/* Header */}
|
|
139
146
|
<View style={styles.header}>
|
|
140
147
|
<View style={styles.handle} />
|
|
141
|
-
{title && <Text style={styles.title}>{title}</Text>}
|
|
148
|
+
{title && <Text style={[styles.title, theme?.textColor ? { color: theme.textColor } : null]}>{title}</Text>}
|
|
142
149
|
<TouchableOpacity
|
|
143
150
|
onPress={handleClose}
|
|
144
151
|
style={styles.closeButton}
|
|
@@ -150,7 +157,7 @@ export function OuterJoynSheet({
|
|
|
150
157
|
{/* WebView */}
|
|
151
158
|
<View style={styles.webViewContainer}>
|
|
152
159
|
{loading && (
|
|
153
|
-
<View style={styles.loadingOverlay}>
|
|
160
|
+
<View style={[styles.loadingOverlay, surface]}>
|
|
154
161
|
<ActivityIndicator size="large" color="#6366f1" />
|
|
155
162
|
</View>
|
|
156
163
|
)}
|
package/src/PromotionsView.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { View, StyleSheet, ActivityIndicator } from 'react-native';
|
|
|
3
3
|
import { WebView } from 'react-native-webview';
|
|
4
4
|
import type { PromotionsViewProps, WebViewMessage } from './types';
|
|
5
5
|
import { generatePromotionsHTML } from './html';
|
|
6
|
+
import { openAppLink } from './appLink';
|
|
6
7
|
|
|
7
8
|
/** Inline promotions display (not a modal -- renders directly in the view hierarchy) */
|
|
8
9
|
export function PromotionsView({
|
|
@@ -25,6 +26,8 @@ export function PromotionsView({
|
|
|
25
26
|
const msg: WebViewMessage = JSON.parse(event.nativeEvent.data);
|
|
26
27
|
if (msg.type === 'sdk_ready') {
|
|
27
28
|
setLoading(false);
|
|
29
|
+
} else if (msg.type === 'open_app_link') {
|
|
30
|
+
openAppLink(msg.payload);
|
|
28
31
|
}
|
|
29
32
|
} catch {
|
|
30
33
|
// Ignore
|
package/src/appLink.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Linking } from 'react-native';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* "Open in the app" offer buttons post
|
|
5
|
+
* `{ type: 'open_app_link', payload: { appUrl, fallbackUrl } }`. The brand's app
|
|
6
|
+
* opens when the phone can open the link; otherwise the fallback page opens in
|
|
7
|
+
* the browser. Only an https fallback is ever opened.
|
|
8
|
+
*/
|
|
9
|
+
export function openAppLink(payload: { appUrl?: unknown; fallbackUrl?: unknown } | undefined): void {
|
|
10
|
+
const appUrl = payload?.appUrl;
|
|
11
|
+
const fallbackUrl = payload?.fallbackUrl;
|
|
12
|
+
if (typeof appUrl !== 'string' || typeof fallbackUrl !== 'string' || !fallbackUrl.startsWith('https://')) return;
|
|
13
|
+
const openFallback = () => {
|
|
14
|
+
Linking.openURL(fallbackUrl).catch(() => {});
|
|
15
|
+
};
|
|
16
|
+
if (/^(http|javascript|data|file|intent):/i.test(appUrl)) {
|
|
17
|
+
openFallback();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
Linking.openURL(appUrl).catch(openFallback);
|
|
21
|
+
}
|
package/src/core/version.ts
CHANGED
|
@@ -101,6 +101,10 @@ export interface ConnectScreenProps {
|
|
|
101
101
|
* `preselectedBrandId`). A program this store can't link is an error
|
|
102
102
|
* (onError code `partner_not_linkable`), never the list. */
|
|
103
103
|
preselectedInstitutionId?: string;
|
|
104
|
+
/** Only these partner programs (ids as strings), in this order. One opens
|
|
105
|
+
* straight on its consent step; several are the whole list. Any this store
|
|
106
|
+
* can't link is an error (onError code `partner_not_linkable`). */
|
|
107
|
+
partners?: string[];
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
type Step = 'loading' | 'search' | 'consent' | 'processing' | 'success' | 'error';
|
|
@@ -166,8 +170,12 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
|
|
|
166
170
|
onError,
|
|
167
171
|
sessionToken: tokenProp,
|
|
168
172
|
apiBaseUrl: baseUrlProp,
|
|
169
|
-
preselectedInstitutionId,
|
|
173
|
+
preselectedInstitutionId: preselectedProp,
|
|
174
|
+
partners,
|
|
170
175
|
}) => {
|
|
176
|
+
const preselectedInstitutionId = preselectedProp ?? (partners?.length === 1 ? partners[0] : undefined);
|
|
177
|
+
// The list is limited to the partners too, so going back never shows other programs.
|
|
178
|
+
const partnersKey = partners && partners.length > 0 ? partners.join(',') : '';
|
|
171
179
|
// Try to read from OuterJoynProvider context (optional — works standalone too)
|
|
172
180
|
const ctx = useContext(OuterJoynContext);
|
|
173
181
|
const sessionToken = tokenProp || (ctx as any)?.sessionToken || '';
|
|
@@ -274,6 +282,14 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
|
|
|
274
282
|
return;
|
|
275
283
|
}
|
|
276
284
|
|
|
285
|
+
if (partnersKey && partnersKey.split(',').some((id) => !/^\d+$/.test(id))) {
|
|
286
|
+
const message = 'These programs can\u2019t be linked from this store.';
|
|
287
|
+
setErrorMessage(message);
|
|
288
|
+
setStep('error');
|
|
289
|
+
onError?.(new SDKError('partner_not_linkable', message, { param: 'partners' }));
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
|
|
277
293
|
try {
|
|
278
294
|
// Fetch institutions and linked accounts in parallel.
|
|
279
295
|
// Retry once after 500ms if apiClient isn't available yet
|
|
@@ -298,7 +314,9 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
|
|
|
298
314
|
// supplementary calls doesn't surface as an unhandled rejection; we
|
|
299
315
|
// inspect the outcome explicitly below.
|
|
300
316
|
const instResult = client
|
|
301
|
-
.get<{ institutions: Institution[] }>(
|
|
317
|
+
.get<{ institutions: Institution[] }>(
|
|
318
|
+
partnersKey ? `/api/sdk/institutions?partners=${encodeURIComponent(partnersKey)}` : '/api/sdk/institutions',
|
|
319
|
+
)
|
|
302
320
|
.then((data) => ({ ok: true as const, data }))
|
|
303
321
|
.catch((err: any) => ({ ok: false as const, err }));
|
|
304
322
|
const [acctData, portableData, inst] = await Promise.all([
|
|
@@ -307,6 +325,14 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
|
|
|
307
325
|
instResult,
|
|
308
326
|
]);
|
|
309
327
|
|
|
328
|
+
if (!inst.ok && partnersKey && inst.err?.code === 'VALIDATION_ERROR') {
|
|
329
|
+
// 422: a partner this store can't link (ids were checked as numbers above).
|
|
330
|
+
const message = 'These programs can\u2019t be linked from this store.';
|
|
331
|
+
setErrorMessage(message);
|
|
332
|
+
setStep('error');
|
|
333
|
+
onError?.(new SDKError('partner_not_linkable', message, { param: 'partners' }));
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
310
336
|
if (!inst.ok) {
|
|
311
337
|
console.warn('[OuterJoyn] ConnectScreen institutions fetch failed:', inst.err?.message ?? inst.err);
|
|
312
338
|
const message =
|
|
@@ -356,7 +382,7 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
|
|
|
356
382
|
const message = 'This program can\u2019t be linked from this store.';
|
|
357
383
|
setErrorMessage(message);
|
|
358
384
|
setStep('error');
|
|
359
|
-
onError?.(new SDKError('partner_not_linkable', message, { param: 'preselectedInstitutionId' }));
|
|
385
|
+
onError?.(new SDKError('partner_not_linkable', message, { param: preselectedProp ? 'preselectedInstitutionId' : 'partners' }));
|
|
360
386
|
return;
|
|
361
387
|
}
|
|
362
388
|
setSelectedInstitution(match);
|
|
@@ -371,7 +397,7 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
|
|
|
371
397
|
setStep('error');
|
|
372
398
|
onError?.(new Error(message));
|
|
373
399
|
}
|
|
374
|
-
}, [isDemoMode, preselectedInstitutionId, apiBaseUrl, sessionToken, onError]);
|
|
400
|
+
}, [isDemoMode, preselectedInstitutionId, partnersKey, apiBaseUrl, sessionToken, onError]);
|
|
375
401
|
|
|
376
402
|
// Load data when modal becomes visible
|
|
377
403
|
useEffect(() => {
|
package/src/types.ts
CHANGED
|
@@ -152,4 +152,5 @@ export type WebViewMessage =
|
|
|
152
152
|
| { type: 'sdk_event'; event: string; data: any }
|
|
153
153
|
| { type: 'sdk_error'; error: SDKError }
|
|
154
154
|
| { type: 'sdk_close' }
|
|
155
|
-
| { type: 'sdk_success'; result: any }
|
|
155
|
+
| { type: 'sdk_success'; result: any }
|
|
156
|
+
| { type: 'open_app_link'; payload: { appUrl: string; fallbackUrl: string } };
|