@outerjoyn/react-native 1.7.0 → 1.7.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outerjoyn/react-native",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
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",
@@ -47,6 +47,7 @@ import {
47
47
  amountError,
48
48
  blockedReason,
49
49
  ceilingCents,
50
+ fewestPointsForValue,
50
51
  floorToIncrement,
51
52
  rulesSummary,
52
53
  uncappedCeilingCents,
@@ -193,9 +194,14 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
193
194
 
194
195
  const selectedPoints = sliderValues[progId] ?? 0;
195
196
  if (selectedPoints <= 0) return;
196
- // The store's minimum and step, checked here so the shopper gets the
197
- // refusal (with a figure that works) before the server's.
198
- const ruleError = amountError(selectedPoints, redemptionRules);
197
+ // The store's minimum and step, and points that would buy nothing,
198
+ // checked here so the shopper gets the refusal (with a figure that
199
+ // works) before the server's.
200
+ const fewest = fewestPointsForValue(selectedPoints, prog.pointValueAmount, redemptionRules);
201
+ const ruleError = amountError(selectedPoints, redemptionRules)
202
+ ?? (fewest < selectedPoints
203
+ ? `${selectedPoints.toLocaleString()} points pay the same as ${fewest.toLocaleString()} here. Use ${fewest.toLocaleString()}.`
204
+ : null);
199
205
  if (ruleError) {
200
206
  setApiError((prev) => ({ ...prev, [progId]: ruleError }));
201
207
  return;
@@ -436,7 +442,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
436
442
  const maxPointsFor = (ceiling: number) => {
437
443
  const remaining = Math.max(0, ceiling - otherConfirmedCents);
438
444
  const pts = prog.pointValueAmount > 0 ? Math.floor(remaining / prog.pointValueAmount) : prog.pointsBalance;
439
- return floorToIncrement(Math.min(prog.pointsBalance, pts), redemptionRules);
445
+ return fewestPointsForValue(floorToIncrement(Math.min(prog.pointsBalance, pts), redemptionRules), prog.pointValueAmount, redemptionRules);
440
446
  };
441
447
  const maxSlider = maxPointsFor(orderCeilingCents);
442
448
  const blocked = blockedReason(prog.pointsBalance, maxSlider, maxPointsFor(orderUncappedCents), redemptionRules);
@@ -45,6 +45,22 @@ export function floorToIncrement(points: number, rules: RedemptionRules | null):
45
45
  return inc > 1 ? Math.floor(points / inc) * inc : points;
46
46
  }
47
47
 
48
+ /**
49
+ * The fewest points, in the store's steps, worth what `points` are worth at
50
+ * `pointValue` cents a point. Checkout values points at floor(points × value),
51
+ * so below a cent a point the last points can buy nothing (51 at 0.5 cents pay
52
+ * what 50 do) and it refuses such an amount (points_buy_nothing). Down only.
53
+ */
54
+ export function fewestPointsForValue(points: number, pointValue: number, rules: RedemptionRules | null): number {
55
+ const inc = rules?.pointsIncrement ?? 0;
56
+ const step = inc > 1 ? inc : 1;
57
+ const lowest = Math.max(1, smallestValidPoints(rules));
58
+ const value = Math.floor(points * pointValue);
59
+ let fewest = points;
60
+ while (fewest - step >= lowest && Math.floor((fewest - step) * pointValue) === value) fewest -= step;
61
+ return fewest;
62
+ }
63
+
48
64
  /** The smallest amount that meets BOTH the minimum and the step (min 450, step 100 -> 500). */
49
65
  export function smallestValidPoints(rules: RedemptionRules | null): number {
50
66
  const min = rules?.minPoints ?? 0;
@@ -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.0';
17
+ export const SDK_VERSION = '1.7.1';
@@ -500,9 +500,10 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
500
500
  const publicToken = params.get('public_token'); // legacy
501
501
 
502
502
  if (error || status === 'error') {
503
- setErrorMessage(error ?? 'Authorization failed');
503
+ const message = params.get('error_description') ?? error ?? 'Authorization failed';
504
+ setErrorMessage(message);
504
505
  setStep('error');
505
- onError?.(new Error(error ?? 'Authorization failed'));
506
+ onError?.(new Error(message));
506
507
  return;
507
508
  }
508
509
 
@@ -190,17 +190,18 @@ export function ExchangeScreen({
190
190
 
191
191
  if (!isDemo && clientRef.current) {
192
192
  clientRef.current
193
- .get<any>('/api/sdk/exchange/rate', {
193
+ .get<any>('/api/v1/exchange/rates', {
194
194
  source_currency_id: String(source.currencyId),
195
195
  target_currency_id: String(target.currencyId),
196
- amount: String(amountNum),
197
196
  })
198
197
  .then((data) => {
198
+ const found = data.rates?.[0];
199
+ if (!found) return;
199
200
  setRate({
200
- rate: data.rate ?? r,
201
- sourceValueAmount: data.source_value_cents ?? amountNum * source.pointValueAmount,
202
- targetValueAmount: data.target_value_cents ?? targetAmount * target.pointValueAmount,
203
- fee: data.fee ?? 0,
201
+ rate: found.rate,
202
+ sourceValueAmount: amountNum * source.pointValueAmount,
203
+ targetValueAmount: Math.floor(amountNum * found.rate) * target.pointValueAmount,
204
+ fee: 0,
204
205
  });
205
206
  })
206
207
  .catch(() => {
@@ -237,21 +238,21 @@ export function ExchangeScreen({
237
238
  return;
238
239
  }
239
240
 
240
- // Fix #8: add idempotency_key to mutation POST
241
241
  if (!clientRef.current) {
242
242
  throw new Error('API client not available');
243
243
  }
244
- const data = await clientRef.current.post<any>('/api/sdk/exchange', {
245
- source_currency_id: source.currencyId,
246
- target_currency_id: target.currencyId,
247
- amount: amountNum,
248
- idempotency_key: Date.now() + '_' + Math.random().toString(36).slice(2),
244
+ // The key travels in the body so the client's network retry replays it.
245
+ const data = await clientRef.current.post<any>('/api/v1/exchange', {
246
+ sourceCurrencyId: String(source.currencyId),
247
+ targetCurrencyId: String(target.currencyId),
248
+ sourceAmount: amountNum,
249
+ idempotencyKey: Date.now() + '_' + Math.random().toString(36).slice(2),
249
250
  });
250
251
 
251
252
  const res: ExchangeResult = {
252
- transactionId: data.transaction_id ?? data.id ?? '',
253
- sourceAmount: amountNum,
254
- targetAmount: data.target_amount ?? targetAmount,
253
+ transactionId: String(data.transactionId),
254
+ sourceAmount: data.sourceAmount,
255
+ targetAmount: data.targetAmount,
255
256
  sourceCurrency: source.currencyName,
256
257
  targetCurrency: target.currencyName,
257
258
  status: data.status ?? 'completed',
@@ -161,7 +161,7 @@ export function RedeemScreen({
161
161
  // Category chip filter ('' = All) — Plaid-grade redesign 2026-07-21.
162
162
  const [categoryFilter, setCategoryFilter] = useState('');
163
163
 
164
- // "Available to spend": /api/sdk/balance only reads the single brand
164
+ // "Available to spend": the account's points_balance only reads the single brand
165
165
  // Member.points_balance, which is 0 for cross-program demo members even
166
166
  // when the provider holds six-figure payable balances — the infamous
167
167
  // "Total Available Value: 0 pts" header. Prefer the provider's
@@ -226,8 +226,8 @@ export function RedeemScreen({
226
226
  .finally(() => setLoading(false));
227
227
 
228
228
  clientRef.current
229
- .get<any>('/api/sdk/balance')
230
- .then((data) => setBalance(data?.points_balance ?? data?.pointsBalance ?? data?.balance ?? 0))
229
+ .get<any>('/api/sdk/account')
230
+ .then((data) => setBalance(data?.member?.points_balance ?? 0))
231
231
  .catch(() => {});
232
232
  }, [visible, isDemo, ctx.apiClient, reloadKey]);
233
233
 
@@ -371,7 +371,7 @@ export function RedeemScreen({
371
371
  // DEPS: balance, tenderRows and ctx are READ in this callback and MUST be
372
372
  // listed. They were omitted once, which froze the callback at its
373
373
  // mount-time values (balance 0, tenderRows []) — both are populated
374
- // asynchronously (/api/sdk/balance and /sessions/context). planRedeemTender
374
+ // asynchronously (/api/sdk/account and /sessions/context). planRedeemTender
375
375
  // then returned null on every real redemption, and the old
376
376
  // `?? {method:'points'}` fallback submitted a points tender against a
377
377
  // scalar of 0: a guaranteed 400 insufficient_balance for exactly the
@@ -467,7 +467,7 @@ export function RedeemScreen({
467
467
  const renderCatalog = () => (
468
468
  <View style={styles.content}>
469
469
  {/* Available-to-spend chip — cross-program totals from the provider
470
- (the old header read /api/sdk/balance = single-brand
470
+ (the old header read the account's single-brand
471
471
  Member.points_balance, which rendered "0 pts" for cross-program
472
472
  demo members). */}
473
473
  <View style={styles.balanceChip}>