@outerjoyn/react-native 1.7.2 → 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/README.md CHANGED
@@ -133,7 +133,7 @@ zero-point checkout.
133
133
  |-----------|-------------|
134
134
  | `<LoyaltyBanner>` | Home/product page banner. Brand logos + balance. |
135
135
  | `<BalanceSummary>` | Balance display: `compact`, `card`, or `inline` layout. |
136
- | `<CheckoutPointsApply>` | Per-program sliders at checkout. Brand-colored tracks. |
136
+ | `<CheckoutPointsApply>` | Per-program sliders at checkout. Brand-colored tracks. Pass your order number as `merchantOrderId`, and the same number to `POST /api/sdk/earn/submit` when the order completes. |
137
137
  | `<LoyaltyProfileSection>` | Profile card with linked programs + unlink. |
138
138
  | `<PostCheckoutSavePrompt>` | Post-checkout phone OTP to save programs. |
139
139
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outerjoyn/react-native",
3
- "version": "1.7.2",
3
+ "version": "1.10.0",
4
4
  "description": "Drop-in loyalty SDK for React Native. Works in Expo Go.",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -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
- style={[styles.sheet, { height: `${heightRatio * 100}%` as any }]}
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
  )}
@@ -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
+ }
@@ -84,6 +84,13 @@ export interface CheckoutPointsApplyHandle {
84
84
  }
85
85
 
86
86
  export interface CheckoutPointsApplyProps {
87
+ /**
88
+ * The store's own order number (required). Every program the shopper applies
89
+ * is held under it, so the purchase you record afterwards (POST
90
+ * /api/sdk/earn/submit with the same merchantOrderId) knows what points paid
91
+ * and earns only on the rest.
92
+ */
93
+ merchantOrderId: string;
87
94
  /** Order total in integer MINOR UNITS of the order currency (required) —
88
95
  * cents for USD ($50.00 = 5000), whole yen for JPY (¥1,850 = 1850). */
89
96
  orderTotalCents: number;
@@ -132,6 +139,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
132
139
  onPointsChanged,
133
140
  onLinkAnother,
134
141
  style,
142
+ merchantOrderId,
135
143
  }: CheckoutPointsApplyProps, ref) {
136
144
  const ctx = useOuterJoyn();
137
145
  const { isReady, isLinked, linkedPrograms, loading, demoMode, apiClient, redemptionRules, t } = ctx;
@@ -260,7 +268,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
260
268
  valueAmount?: number;
261
269
  }>;
262
270
  }>('/api/sdk/pay/checkout', {
263
- merchantOrderId: `checkout_${Date.now()}`,
271
+ merchantOrderId,
264
272
  orderTotalCents: validOrderTotal,
265
273
  currencyCode: orderCurrency,
266
274
  ...breakdown,
@@ -303,7 +311,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
303
311
  setApiLoading((prev) => ({ ...prev, [progId]: false }));
304
312
  }
305
313
  },
306
- [programs, sliderValues, demoMode, apiClient, orderTotalCents, merchandiseSubtotalCents, taxCents, shippingCents, currencyCode, buildPayload, onPointsChanged, redemptionTokens, redemptionRules],
314
+ [programs, sliderValues, demoMode, apiClient, orderTotalCents, merchandiseSubtotalCents, taxCents, shippingCents, currencyCode, merchantOrderId, buildPayload, onPointsChanged, redemptionTokens, redemptionRules],
307
315
  );
308
316
 
309
317
  const handleRemove = useCallback(
@@ -14,4 +14,4 @@
14
14
  * (It is not imported from package.json because that inlines the entire
15
15
  * manifest — repo URLs, scripts, devDependencies — into consumer bundles.)
16
16
  */
17
- export const SDK_VERSION = '1.7.2';
17
+ export const SDK_VERSION = '1.10.0';
@@ -43,7 +43,7 @@ import {
43
43
  } from 'react-native';
44
44
  import * as WebBrowser from 'expo-web-browser';
45
45
  import { OuterJoynContext } from '../OuterJoynProvider';
46
- import { APIClient } from '../core/api-client';
46
+ import { APIClient, SDKError } from '../core/api-client';
47
47
  import { createPortabilityHandoff, getPortabilityHandoffAvailable, getPortabilityHandoffStatus } from '../core/portabilityHandoff';
48
48
 
49
49
  const OJ_LOGO_URL = 'https://app.outerjoyn.com/outerjoyn-logo.png';
@@ -97,8 +97,14 @@ export interface ConnectScreenProps {
97
97
  sessionToken?: string;
98
98
  /** Override API base URL (reads from context if omitted) */
99
99
  apiBaseUrl?: string;
100
- /** Pre-select a specific institution by ID */
100
+ /** Open straight on this partner program's consent step (the web SDK's
101
+ * `preselectedBrandId`). A program this store can't link is an error
102
+ * (onError code `partner_not_linkable`), never the list. */
101
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[];
102
108
  }
103
109
 
104
110
  type Step = 'loading' | 'search' | 'consent' | 'processing' | 'success' | 'error';
@@ -164,8 +170,12 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
164
170
  onError,
165
171
  sessionToken: tokenProp,
166
172
  apiBaseUrl: baseUrlProp,
167
- preselectedInstitutionId,
173
+ preselectedInstitutionId: preselectedProp,
174
+ partners,
168
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(',') : '';
169
179
  // Try to read from OuterJoynProvider context (optional — works standalone too)
170
180
  const ctx = useContext(OuterJoynContext);
171
181
  const sessionToken = tokenProp || (ctx as any)?.sessionToken || '';
@@ -272,6 +282,14 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
272
282
  return;
273
283
  }
274
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
+
275
293
  try {
276
294
  // Fetch institutions and linked accounts in parallel.
277
295
  // Retry once after 500ms if apiClient isn't available yet
@@ -296,7 +314,9 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
296
314
  // supplementary calls doesn't surface as an unhandled rejection; we
297
315
  // inspect the outcome explicitly below.
298
316
  const instResult = client
299
- .get<{ institutions: Institution[] }>('/api/sdk/institutions')
317
+ .get<{ institutions: Institution[] }>(
318
+ partnersKey ? `/api/sdk/institutions?partners=${encodeURIComponent(partnersKey)}` : '/api/sdk/institutions',
319
+ )
300
320
  .then((data) => ({ ok: true as const, data }))
301
321
  .catch((err: any) => ({ ok: false as const, err }));
302
322
  const [acctData, portableData, inst] = await Promise.all([
@@ -305,6 +325,14 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
305
325
  instResult,
306
326
  ]);
307
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
+ }
308
336
  if (!inst.ok) {
309
337
  console.warn('[OuterJoyn] ConnectScreen institutions fetch failed:', inst.err?.message ?? inst.err);
310
338
  const message =
@@ -341,13 +369,24 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
341
369
 
342
370
  setStep('search');
343
371
 
344
- const activeList = list;
345
372
  if (preselectedInstitutionId) {
346
- const match = activeList.find((i) => i.institution_id === preselectedInstitutionId);
347
- if (match) {
348
- setSelectedInstitution(match);
349
- setStep('consent');
373
+ // Asked of the server, which says whether this store can link it: the
374
+ // full list is capped, so a missing row there proves nothing.
375
+ const only = await client.get<{ institutions: Institution[] }>(
376
+ `/api/sdk/institutions?program=${encodeURIComponent(preselectedInstitutionId)}`,
377
+ );
378
+ const match = (only?.institutions || []).find(
379
+ (i) => i.institution_id === preselectedInstitutionId && i.is_active !== false,
380
+ );
381
+ if (!match) {
382
+ const message = 'This program can\u2019t be linked from this store.';
383
+ setErrorMessage(message);
384
+ setStep('error');
385
+ onError?.(new SDKError('partner_not_linkable', message, { param: preselectedProp ? 'preselectedInstitutionId' : 'partners' }));
386
+ return;
350
387
  }
388
+ setSelectedInstitution(match);
389
+ setStep('consent');
351
390
  }
352
391
  } catch (err: any) {
353
392
  console.warn('[OuterJoyn] ConnectScreen loadData failed:', err.message);
@@ -358,7 +397,7 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
358
397
  setStep('error');
359
398
  onError?.(new Error(message));
360
399
  }
361
- }, [isDemoMode, preselectedInstitutionId, apiBaseUrl, sessionToken, onError]);
400
+ }, [isDemoMode, preselectedInstitutionId, partnersKey, apiBaseUrl, sessionToken, onError]);
362
401
 
363
402
  // Load data when modal becomes visible
364
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 } };