@outerjoyn/react-native 1.4.1 → 1.4.2

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.4.1",
3
+ "version": "1.4.2",
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",
@@ -11,7 +11,11 @@
11
11
  "README.md"
12
12
  ],
13
13
  "scripts": {
14
- "typecheck": "tsc --noEmit"
14
+ "typecheck": "tsc --noEmit",
15
+ "sync:version": "node scripts/sync-version.js",
16
+ "check:version": "node scripts/sync-version.js --check",
17
+ "version": "node scripts/sync-version.js",
18
+ "prepublishOnly": "npm run check:version && npm run typecheck"
15
19
  },
16
20
  "keywords": [
17
21
  "outerjoyn",
@@ -16,12 +16,19 @@
16
16
  * <CheckoutPointsApply
17
17
  * ref={checkoutRef}
18
18
  * orderTotalCents={4999}
19
+ * merchandiseSubtotalCents={4299}
20
+ * taxCents={400}
21
+ * shippingCents={300}
19
22
  * onPointsChanged={(applied) => setDiscount(applied.totalValueAmount)}
20
23
  * />
21
24
  *
22
25
  * // To finalize all reservations:
23
26
  * await checkoutRef.current?.confirmAll();
24
27
  * ```
28
+ *
29
+ * Pass the order breakdown alongside the total. Most storefront bases require
30
+ * `merchandiseSubtotalCents`; without it the reserve fails closed with
31
+ * `merchandise_subtotal_required`.
25
32
  */
26
33
  import React, { useState, useCallback, useMemo, useRef, useEffect, useImperativeHandle, forwardRef } from 'react';
27
34
  import {
@@ -70,6 +77,23 @@ export interface CheckoutPointsApplyHandle {
70
77
  export interface CheckoutPointsApplyProps {
71
78
  /** Order total in cents (required) */
72
79
  orderTotalCents: number;
80
+ /**
81
+ * Merchandise subtotal in cents — the order total minus tax and shipping.
82
+ *
83
+ * REQUIRED for every storefront basis except `tender` with both
84
+ * `redeem_include_tax` and `redeem_include_shipping` enabled (where the order
85
+ * total itself is the redeemable basis). Omitting it on any other basis makes
86
+ * the reserve fail closed with `merchandise_subtotal_required` — the server
87
+ * will not silently widen a partial basis to gross.
88
+ *
89
+ * Pass it whenever you know it; there is no cost to sending it on a basis
90
+ * that ignores it.
91
+ */
92
+ merchandiseSubtotalCents?: number;
93
+ /** Tax in cents. Required when the storefront's basis includes tax. */
94
+ taxCents?: number;
95
+ /** Shipping in cents. Required when the storefront's basis includes shipping. */
96
+ shippingCents?: number;
73
97
  /** Called whenever the user adjusts sliders */
74
98
  onPointsChanged?: (payload: PointsChangedPayload) => void;
75
99
  /** Called when the user taps "Link another program". If provided, overrides the default sheet flow. */
@@ -80,6 +104,9 @@ export interface CheckoutPointsApplyProps {
80
104
 
81
105
  export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, CheckoutPointsApplyProps>(function CheckoutPointsApply({
82
106
  orderTotalCents,
107
+ merchandiseSubtotalCents,
108
+ taxCents,
109
+ shippingCents,
83
110
  onPointsChanged,
84
111
  onLinkAnother,
85
112
  style,
@@ -150,6 +177,20 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
150
177
  const validOrderTotal = (typeof orderTotalCents === 'number' && !Number.isNaN(orderTotalCents))
151
178
  ? orderTotalCents : 0;
152
179
 
180
+ // The order breakdown the server needs to compute the redeemable basis.
181
+ // Only send a field the caller actually supplied: the server distinguishes
182
+ // "absent" (fail closed) from a real 0, so coercing undefined to 0 here
183
+ // would assert a zero merchandise subtotal and cap redemption at nothing.
184
+ const validCents = (v: number | undefined) =>
185
+ typeof v === 'number' && Number.isFinite(v) ? v : undefined;
186
+ const breakdown: Record<string, number> = {};
187
+ const ms = validCents(merchandiseSubtotalCents);
188
+ const tx = validCents(taxCents);
189
+ const sh = validCents(shippingCents);
190
+ if (ms !== undefined) breakdown.merchandiseSubtotalCents = ms;
191
+ if (tx !== undefined) breakdown.taxCents = tx;
192
+ if (sh !== undefined) breakdown.shippingCents = sh;
193
+
153
194
  // In demo mode or no apiClient, skip API calls
154
195
  if (demoMode || !apiClient) {
155
196
  setConfirmedPrograms((prev) => {
@@ -180,6 +221,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
180
221
  merchantOrderId: `checkout_${Date.now()}`,
181
222
  orderTotalCents: validOrderTotal,
182
223
  currencyCode: 'USD',
224
+ ...breakdown,
183
225
  reservations: [{
184
226
  memberCurrencyId: prog.memberCurrencyId,
185
227
  currencyId: prog.currencyId,
@@ -219,7 +261,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
219
261
  setApiLoading((prev) => ({ ...prev, [progId]: false }));
220
262
  }
221
263
  },
222
- [programs, sliderValues, demoMode, apiClient, orderTotalCents, buildPayload, onPointsChanged, redemptionTokens],
264
+ [programs, sliderValues, demoMode, apiClient, orderTotalCents, merchandiseSubtotalCents, taxCents, shippingCents, buildPayload, onPointsChanged, redemptionTokens],
223
265
  );
224
266
 
225
267
  const handleRemove = useCallback(
@@ -1,2 +1,17 @@
1
- /** Single source of truth for SDK version. Imported by api-client and analytics. */
2
- export const SDK_VERSION = '1.0.0';
1
+ /**
2
+ * Single source of truth for SDK version. Imported by api-client and analytics.
3
+ *
4
+ * This MUST equal the `version` in package.json. It ships on every request as
5
+ * `X-SDK-Version` and stamps every analytics event as `sdk_version`, which is
6
+ * what the SDK-version-adoption breakdown groups by — so a stale value here
7
+ * does not fail loudly, it silently mislabels all telemetry as an old release.
8
+ *
9
+ * It drifted to 1.0.0 across five releases exactly that way. Do not hand-edit
10
+ * it on its own: `npm version` runs the `version` script, which rewrites this
11
+ * file from package.json and stages it. `npm run check:version` fails the build
12
+ * if the two ever disagree.
13
+ *
14
+ * (It is not imported from package.json because that inlines the entire
15
+ * manifest — repo URLs, scripts, devDependencies — into consumer bundles.)
16
+ */
17
+ export const SDK_VERSION = '1.4.2';