@outerjoyn/react-native 1.4.0 → 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.0",
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",
@@ -592,7 +592,7 @@ export function OuterJoynProvider({
592
592
  );
593
593
 
594
594
  const openExchange = useCallback(
595
- (opts?: { sourceCurrencyId?: number }) => {
595
+ (opts?: { sourceCurrencyId?: number | string }) => {
596
596
  analyticsRef.current?.trackOpen('exchange');
597
597
  openSheet('exchange', opts ?? {});
598
598
  },
@@ -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(
package/src/core/types.ts CHANGED
@@ -14,7 +14,9 @@ export interface CreateSessionResponse {
14
14
  status: 'ready' | 'link_required';
15
15
  expires_at: string;
16
16
  member_context?: {
17
- member_id: number;
17
+ // Snowflake IDs ride as JSON strings on the wire post-audit-D2b; the
18
+ // legacy numeric shape is still accepted from pre-D2b servers.
19
+ member_id: number | string;
18
20
  display_name?: string;
19
21
  linked_programs?: Array<{ program_name: string; currency_name: string }>;
20
22
  };
@@ -23,9 +25,9 @@ export interface CreateSessionResponse {
23
25
 
24
26
  export interface SessionContextResponse {
25
27
  status: string;
26
- member_id: number | null;
28
+ member_id: number | string | null;
27
29
  display_name?: string;
28
- business_unit_id: number;
30
+ business_unit_id: number | string;
29
31
  scopes: string[];
30
32
  expires_at: string;
31
33
  payable_balances?: PayableBalance[];
@@ -34,9 +36,12 @@ export interface SessionContextResponse {
34
36
  }
35
37
 
36
38
  export interface PayableBalance {
39
+ // Snowflake IDs (memberCurrencyId/currencyId/partnershipId) ride as JSON
40
+ // strings on the wire post-audit-D2; kept `number | string` to also accept
41
+ // the legacy numeric shape. Amounts/balances stay numeric.
37
42
  // Go gateway returns camelCase
38
- memberCurrencyId?: number;
39
- currencyId?: number;
43
+ memberCurrencyId?: number | string;
44
+ currencyId?: number | string;
40
45
  currencyName?: string;
41
46
  currencyCode?: string;
42
47
  brandName?: string;
@@ -45,10 +50,10 @@ export interface PayableBalance {
45
50
  balance?: number;
46
51
  pointValueAmount?: number;
47
52
  valueAmount?: number;
48
- partnershipId?: number;
53
+ partnershipId?: number | string;
49
54
  // Express returns snake_case
50
- member_currency_id?: number;
51
- currency_id?: number;
55
+ member_currency_id?: number | string;
56
+ currency_id?: number | string;
52
57
  currency_name?: string;
53
58
  currency_code?: string;
54
59
  brand_name?: string;
@@ -56,7 +61,7 @@ export interface PayableBalance {
56
61
  brand_color?: string | null;
57
62
  point_value_amount?: number;
58
63
  value_amount?: number;
59
- partnership_id?: number;
64
+ partnership_id?: number | string;
60
65
  }
61
66
 
62
67
  export interface BrandConfig {
@@ -87,7 +92,7 @@ export interface LinkedProgram {
87
92
  brandLogoUrl: string | null;
88
93
  brandColor: string | null;
89
94
  /** Partnership ID — used for disconnect. May be undefined for demo programs. */
90
- partnershipId?: number;
95
+ partnershipId?: number | string;
91
96
  }
92
97
 
93
98
  // =============================================================================
@@ -183,7 +188,7 @@ export interface OuterJoynContextValue {
183
188
  // Actions
184
189
  refreshBalances: () => Promise<void>;
185
190
  openConnect: (opts?: { institutionId?: string }) => void;
186
- openExchange: (opts?: { sourceCurrencyId?: number }) => void;
191
+ openExchange: (opts?: { sourceCurrencyId?: number | string }) => void;
187
192
  openRedeem: (opts?: { category?: string }) => void;
188
193
  openPay: (opts: { orderTotalCents: number; merchantOrderId?: string }) => void;
189
194
  openAccount: () => void;
@@ -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';
@@ -67,7 +67,9 @@ interface ConnectedBrand {
67
67
  total_redeemed: number;
68
68
  scopes: string[];
69
69
  linked_at: string;
70
- partnership_id?: number;
70
+ // Snowflake ID: JSON string on the wire post-audit-D2; sourced from the
71
+ // widened LinkedProgram.partnershipId. Legacy numeric shape still accepted.
72
+ partnership_id?: number | string;
71
73
  }
72
74
 
73
75
  interface ActivityItem {
@@ -63,7 +63,8 @@ interface RedemptionResult {
63
63
  }
64
64
 
65
65
  interface CatalogItem {
66
- product_id: number;
66
+ // Snowflake catalog ID: JSON string on the wire post-audit-D2; legacy numeric accepted.
67
+ product_id: number | string;
67
68
  name: string;
68
69
  description: string;
69
70
  short_description?: string;
package/src/types.ts CHANGED
@@ -99,26 +99,29 @@ export interface PromotionsViewProps extends OuterJoynConfig {
99
99
  }
100
100
 
101
101
  export interface PayResult {
102
- reservationId: number;
102
+ // Snowflake ID: JSON string on the wire post-audit-D2b; legacy numeric accepted.
103
+ reservationId: number | string;
103
104
  status: string;
104
105
  pointsUsed: number;
105
106
  valueAmount: number;
106
107
  }
107
108
 
108
109
  export interface ConnectResult {
109
- linkedProgramId: number;
110
+ // Snowflake ID: emitted as a JSON string on the wire (see audit D2). Widened
111
+ // to accept the legacy numeric shape too for pre-D2 servers.
112
+ linkedProgramId: number | string;
110
113
  programName: string;
111
114
  }
112
115
 
113
116
  export interface ExchangeResult {
114
- transactionId: number;
117
+ transactionId: number | string;
115
118
  sourceAmount: number;
116
119
  targetAmount: number;
117
120
  rate: number;
118
121
  }
119
122
 
120
123
  export interface RedeemResult {
121
- redemptionId: number;
124
+ redemptionId: number | string;
122
125
  status: string;
123
126
  }
124
127