@onramper/onramper-react-native 1.2.2 → 1.3.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +214 -0
  2. package/README.md +46 -4
  3. package/ios/Frameworks/OnramperSDK.xcframework/ios-arm64/OnramperSDK.framework/Modules/OnramperSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  4. package/ios/Frameworks/OnramperSDK.xcframework/ios-arm64/OnramperSDK.framework/Modules/OnramperSDK.swiftmodule/arm64-apple-ios.swiftinterface +107 -4
  5. package/ios/Frameworks/OnramperSDK.xcframework/ios-arm64/OnramperSDK.framework/OnramperSDK +0 -0
  6. package/ios/Frameworks/OnramperSDK.xcframework/ios-arm64/dSYMs/OnramperSDK.framework.dSYM/Contents/Resources/DWARF/OnramperSDK +0 -0
  7. package/ios/Frameworks/OnramperSDK.xcframework/ios-arm64/dSYMs/OnramperSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/OnramperSDK.yml +3560 -2684
  8. package/ios/Frameworks/OnramperSDK.xcframework/ios-arm64_x86_64-simulator/OnramperSDK.framework/Modules/OnramperSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  9. package/ios/Frameworks/OnramperSDK.xcframework/ios-arm64_x86_64-simulator/OnramperSDK.framework/Modules/OnramperSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +107 -4
  10. package/ios/Frameworks/OnramperSDK.xcframework/ios-arm64_x86_64-simulator/OnramperSDK.framework/Modules/OnramperSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  11. package/ios/Frameworks/OnramperSDK.xcframework/ios-arm64_x86_64-simulator/OnramperSDK.framework/Modules/OnramperSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +107 -4
  12. package/ios/Frameworks/OnramperSDK.xcframework/ios-arm64_x86_64-simulator/OnramperSDK.framework/OnramperSDK +0 -0
  13. package/ios/Frameworks/OnramperSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/OnramperSDK.framework.dSYM/Contents/Resources/DWARF/OnramperSDK +0 -0
  14. package/ios/Frameworks/OnramperSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/OnramperSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/OnramperSDK.yml +3560 -2684
  15. package/ios/Frameworks/OnramperSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/OnramperSDK.framework.dSYM/Contents/Resources/Relocations/x86_64/OnramperSDK.yml +3523 -2651
  16. package/ios/HybridOnramperCheckoutButton.swift +77 -3
  17. package/ios/HybridOnramperNitro.swift +140 -78
  18. package/ios/OnramperSDKBridge.swift +19 -2
  19. package/ios/PreparedIntentRegistry.swift +124 -6
  20. package/ios/SDKLogRelay.swift +41 -0
  21. package/lib/commonjs/CheckoutButton.js +34 -0
  22. package/lib/commonjs/CheckoutButton.js.map +1 -0
  23. package/lib/commonjs/OnramperClient.js +69 -12
  24. package/lib/commonjs/OnramperClient.js.map +1 -1
  25. package/lib/commonjs/errors.js +19 -5
  26. package/lib/commonjs/errors.js.map +1 -1
  27. package/lib/commonjs/generated/OnramperCheckoutButtonConfig.json +1 -0
  28. package/lib/module/CheckoutButton.js +30 -0
  29. package/lib/module/CheckoutButton.js.map +1 -0
  30. package/lib/module/OnramperClient.js +69 -12
  31. package/lib/module/OnramperClient.js.map +1 -1
  32. package/lib/module/errors.js +19 -5
  33. package/lib/module/errors.js.map +1 -1
  34. package/lib/module/generated/OnramperCheckoutButtonConfig.json +1 -0
  35. package/lib/typescript/commonjs/src/CheckoutButton.d.ts +20 -0
  36. package/lib/typescript/commonjs/src/CheckoutButton.d.ts.map +1 -0
  37. package/lib/typescript/commonjs/src/OnramperClient.d.ts +5 -1
  38. package/lib/typescript/commonjs/src/OnramperClient.d.ts.map +1 -1
  39. package/lib/typescript/commonjs/src/errors.d.ts +6 -1
  40. package/lib/typescript/commonjs/src/errors.d.ts.map +1 -1
  41. package/lib/typescript/commonjs/src/events.d.ts +10 -0
  42. package/lib/typescript/commonjs/src/events.d.ts.map +1 -1
  43. package/lib/typescript/commonjs/src/index.d.ts +1 -1
  44. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  45. package/lib/typescript/commonjs/src/specs/OnramperCheckoutButton.nitro.d.ts +6 -0
  46. package/lib/typescript/commonjs/src/specs/OnramperCheckoutButton.nitro.d.ts.map +1 -1
  47. package/lib/typescript/commonjs/src/specs/OnramperNitro.nitro.d.ts +3 -0
  48. package/lib/typescript/commonjs/src/specs/OnramperNitro.nitro.d.ts.map +1 -1
  49. package/lib/typescript/commonjs/src/types.d.ts +32 -3
  50. package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
  51. package/lib/typescript/module/src/CheckoutButton.d.ts +20 -0
  52. package/lib/typescript/module/src/CheckoutButton.d.ts.map +1 -0
  53. package/lib/typescript/module/src/OnramperClient.d.ts +5 -1
  54. package/lib/typescript/module/src/OnramperClient.d.ts.map +1 -1
  55. package/lib/typescript/module/src/errors.d.ts +6 -1
  56. package/lib/typescript/module/src/errors.d.ts.map +1 -1
  57. package/lib/typescript/module/src/events.d.ts +10 -0
  58. package/lib/typescript/module/src/events.d.ts.map +1 -1
  59. package/lib/typescript/module/src/index.d.ts +1 -1
  60. package/lib/typescript/module/src/index.d.ts.map +1 -1
  61. package/lib/typescript/module/src/specs/OnramperCheckoutButton.nitro.d.ts +6 -0
  62. package/lib/typescript/module/src/specs/OnramperCheckoutButton.nitro.d.ts.map +1 -1
  63. package/lib/typescript/module/src/specs/OnramperNitro.nitro.d.ts +3 -0
  64. package/lib/typescript/module/src/specs/OnramperNitro.nitro.d.ts.map +1 -1
  65. package/lib/typescript/module/src/types.d.ts +32 -3
  66. package/lib/typescript/module/src/types.d.ts.map +1 -1
  67. package/nitrogen/generated/ios/OnramperReactNative-Swift-Cxx-Bridge.cpp +11 -3
  68. package/nitrogen/generated/ios/OnramperReactNative-Swift-Cxx-Bridge.hpp +44 -7
  69. package/nitrogen/generated/ios/c++/HybridOnramperCheckoutButtonSpecSwift.hpp +9 -0
  70. package/nitrogen/generated/ios/c++/HybridOnramperNitroSpecSwift.hpp +6 -0
  71. package/nitrogen/generated/ios/c++/views/HybridOnramperCheckoutButtonComponent.mm +5 -0
  72. package/nitrogen/generated/ios/swift/Func_void_double.swift +46 -0
  73. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +5 -5
  74. package/nitrogen/generated/ios/swift/HybridOnramperCheckoutButtonSpec.swift +1 -0
  75. package/nitrogen/generated/ios/swift/HybridOnramperCheckoutButtonSpec_cxx.swift +32 -0
  76. package/nitrogen/generated/ios/swift/HybridOnramperNitroSpec.swift +1 -0
  77. package/nitrogen/generated/ios/swift/HybridOnramperNitroSpec_cxx.swift +27 -11
  78. package/nitrogen/generated/ios/swift/OnramperNitroConfig.swift +16 -6
  79. package/nitrogen/generated/shared/c++/HybridOnramperCheckoutButtonSpec.cpp +2 -0
  80. package/nitrogen/generated/shared/c++/HybridOnramperCheckoutButtonSpec.hpp +4 -0
  81. package/nitrogen/generated/shared/c++/HybridOnramperNitroSpec.cpp +1 -0
  82. package/nitrogen/generated/shared/c++/HybridOnramperNitroSpec.hpp +1 -0
  83. package/nitrogen/generated/shared/c++/OnramperNitroConfig.hpp +10 -2
  84. package/nitrogen/generated/shared/c++/views/HybridOnramperCheckoutButtonComponent.cpp +11 -0
  85. package/nitrogen/generated/shared/c++/views/HybridOnramperCheckoutButtonComponent.hpp +3 -2
  86. package/nitrogen/generated/shared/json/OnramperCheckoutButtonConfig.json +1 -0
  87. package/package.json +5 -2
  88. package/src/CheckoutButton.ts +28 -0
  89. package/src/OnramperClient.ts +69 -9
  90. package/src/errors.ts +29 -6
  91. package/src/events.ts +5 -0
  92. package/src/generated/OnramperCheckoutButtonConfig.json +1 -0
  93. package/src/index.ts +3 -0
  94. package/src/specs/OnramperCheckoutButton.nitro.ts +6 -0
  95. package/src/specs/OnramperNitro.nitro.ts +3 -0
  96. package/src/types.ts +36 -3
@@ -0,0 +1,41 @@
1
+ import Foundation
2
+ import NitroModules
3
+ import OnramperSDK
4
+
5
+ /// The SDK can emit records from any thread. Keep callback registration and
6
+ /// teardown synchronized; invoke outside the lock (Nitro schedules delivery).
7
+ final class SDKLogRelay: @unchecked Sendable {
8
+ private let lock = NSLock()
9
+ private var listener: ((String) -> Void)?
10
+
11
+ func setListener(_ listener: ((String) -> Void)?) {
12
+ lock.lock()
13
+ self.listener = listener
14
+ lock.unlock()
15
+ }
16
+
17
+ func emit(_ record: OnramperLogRecord) {
18
+ lock.lock()
19
+ let callback = listener
20
+ lock.unlock()
21
+ guard let callback else { return }
22
+ callback(jsonString([
23
+ "timestamp": record.timestamp.timeIntervalSince1970 * 1000,
24
+ "level": String(describing: record.level),
25
+ "category": record.category,
26
+ "event": record.event,
27
+ "context": record.context,
28
+ "message": record.message,
29
+ ]))
30
+ }
31
+ }
32
+
33
+ /// Nitro otherwise converts a Swift error to a message-only JavaScript Error.
34
+ /// Both failed events and rejected operations must carry the SDK's safe copy.
35
+ func bridgeSDKError(_ error: Error) -> Error {
36
+ if let lifecycleError = error as? BridgeLifecycleError {
37
+ return RuntimeError.error(withMessage: "ONRAMPER_ERROR:" + jsonString(lifecycleError.payload))
38
+ }
39
+ guard let sdkError = error as? OnramperError else { return error }
40
+ return RuntimeError.error(withMessage: "ONRAMPER_ERROR:" + jsonString(sdkError.toJSDict()))
41
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CHECKOUT_BUTTON_FALLBACK_HEIGHT = void 0;
7
+ exports.CheckoutButton = CheckoutButton;
8
+ var _react = require("react");
9
+ var _reactNativeNitroModules = require("react-native-nitro-modules");
10
+ var _OnramperCheckoutButtonView = require("./OnramperCheckoutButtonView.js");
11
+ // Height of the bare Buy button. Used until native reports the measured content
12
+ // height so the first frame isn't collapsed.
13
+ const CHECKOUT_BUTTON_FALLBACK_HEIGHT = exports.CHECKOUT_BUTTON_FALLBACK_HEIGHT = 56;
14
+ /**
15
+ * Sizes the native checkout button to its SwiftUI content. The content grows when
16
+ * the SDK shows ToS text under the Buy button (which can change after mount), and
17
+ * Yoga can't measure a SwiftUI view — so native reports the height and it is
18
+ * applied here as an explicit `height`.
19
+ */
20
+ function CheckoutButton({
21
+ intentHandle
22
+ }) {
23
+ const [height, setHeight] = (0, _react.useState)(null);
24
+ const onContentHeightChange = (0, _react.useMemo)(() => (0, _reactNativeNitroModules.callback)(h => setHeight(Math.ceil(h))), []);
25
+ return /*#__PURE__*/(0, _react.createElement)(_OnramperCheckoutButtonView.OnramperCheckoutButtonView, {
26
+ intentHandle,
27
+ onContentHeightChange,
28
+ style: {
29
+ width: '100%',
30
+ height: height ?? CHECKOUT_BUTTON_FALLBACK_HEIGHT
31
+ }
32
+ });
33
+ }
34
+ //# sourceMappingURL=CheckoutButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_reactNativeNitroModules","_OnramperCheckoutButtonView","CHECKOUT_BUTTON_FALLBACK_HEIGHT","exports","CheckoutButton","intentHandle","height","setHeight","useState","onContentHeightChange","useMemo","callback","h","Math","ceil","createElement","OnramperCheckoutButtonView","style","width"],"sourceRoot":"../../src","sources":["CheckoutButton.ts"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,wBAAA,GAAAD,OAAA;AAEA,IAAAE,2BAAA,GAAAF,OAAA;AAEA;AACA;AACO,MAAMG,+BAA+B,GAAAC,OAAA,CAAAD,+BAAA,GAAG,EAAE;AAMjD;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,cAAcA,CAAC;EAAEC;AAAkC,CAAC,EAAE;EACpE,MAAM,CAACC,MAAM,EAAEC,SAAS,CAAC,GAAG,IAAAC,eAAQ,EAAgB,IAAI,CAAC;EACzD,MAAMC,qBAAqB,GAAG,IAAAC,cAAO,EAAC,MAAM,IAAAC,iCAAQ,EAAEC,CAAS,IAAKL,SAAS,CAACM,IAAI,CAACC,IAAI,CAACF,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;EACjG,oBAAO,IAAAG,oBAAa,EAACC,sDAA0B,EAAE;IAC/CX,YAAY;IACZI,qBAAqB;IACrBQ,KAAK,EAAE;MAAEC,KAAK,EAAE,MAAM;MAAEZ,MAAM,EAAEA,MAAM,IAAIJ;IAAgC;EAC5E,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.OnramperClient = void 0;
7
7
  var _react = require("react");
8
- var _OnramperCheckoutButtonView = require("./OnramperCheckoutButtonView.js");
8
+ var _CheckoutButton = require("./CheckoutButton.js");
9
9
  var _OnramperNative = require("./OnramperNative.js");
10
10
  var _errors = require("./errors.js");
11
11
  /**
@@ -30,9 +30,23 @@ class OnramperClient {
30
30
  // Resolved when the constructor-issued configure() completes. Public methods
31
31
  // that need the native client await this first.
32
32
 
33
+ destroyed = false;
33
34
  constructor(config) {
35
+ if (config.logHandler) {
36
+ const handler = config.logHandler;
37
+ this.native.setLogListener(json => {
38
+ if (this.destroyed) return;
39
+ try {
40
+ handler(JSON.parse(json));
41
+ } catch {
42
+ // Diagnostics must never interrupt checkout; do not log callback data.
43
+ console.warn('Onramper logHandler failed.');
44
+ }
45
+ });
46
+ }
34
47
  // Single native state callback → update the mirror + fan out to listeners.
35
48
  this.native.setStateListener(json => {
49
+ if (this.destroyed) return;
36
50
  const s = JSON.parse(json);
37
51
  this.state = s;
38
52
  if (s.kind === 'failed') this.lastError = _errors.OnramperError.from(s.error);
@@ -42,6 +56,7 @@ class OnramperClient {
42
56
  // Single native checkout-event callback → keep the transaction ID mirror
43
57
  // synchronized at finalization, then fan out to checkout listeners.
44
58
  this.native.setEventListener(json => {
59
+ if (this.destroyed) return;
45
60
  const e = JSON.parse(json);
46
61
  if (e.type === 'checkoutFinalized') {
47
62
  this.updateCurrentTransactionId(e.response.onramperTransactionId);
@@ -49,6 +64,7 @@ class OnramperClient {
49
64
  for (const fn of this.eventListeners) fn(e);
50
65
  });
51
66
  this.native.setTransactionIdListener(transactionId => {
67
+ if (this.destroyed) return;
52
68
  // The SDK transiently publishes nil while re-preparing after the payment
53
69
  // sheet is dismissed. The finalized transaction ID remains durable across
54
70
  // that attempt change; only explicit reset()/signOut() clear the JS mirror.
@@ -59,7 +75,9 @@ class OnramperClient {
59
75
  // Nitro stores the async callback natively and awaits it directly — no
60
76
  // event round-trip needed.
61
77
  this.native.setSessionExpirationHandler(async () => {
78
+ this.assertActive();
62
79
  const creds = await config.onSessionExpired();
80
+ this.assertActive();
63
81
  return {
64
82
  sessionId: creds.sessionId,
65
83
  sessionToken: creds.sessionToken
@@ -70,20 +88,33 @@ class OnramperClient {
70
88
  clientId: config.clientId,
71
89
  environment: config.environment,
72
90
  theme: config.theme ?? 'system',
73
- logLevel: config.logLevel ?? 'off'
91
+ logLevel: config.logLevel ?? 'off',
92
+ isEventLoggingEnabled: config.isEventLoggingEnabled ?? false,
93
+ isEventConsoleLoggingEnabled: config.isEventConsoleLoggingEnabled ?? false
74
94
  }).catch(e => {
75
95
  const err = _errors.OnramperError.from(e);
76
- this.lastError = err;
96
+ if (!this.destroyed) this.lastError = err;
77
97
  throw err;
78
98
  });
79
99
  // Swallow the unhandled-rejection warning when no one awaits .configured
80
100
  // before calling initialize(). The error still surfaces via initialize().
81
101
  this.configured.catch(() => undefined);
82
102
  }
103
+ assertActive() {
104
+ if (this.destroyed) {
105
+ throw new _errors.OnramperError({
106
+ code: 'clientDestroyed',
107
+ message: 'This OnramperClient has been destroyed. Create a new client before making SDK calls.',
108
+ userMessage: 'This checkout session has ended. Please reopen checkout.'
109
+ });
110
+ }
111
+ }
83
112
  updateCurrentTransactionId(next) {
113
+ if (this.destroyed) return;
84
114
  if (next === this.currentTransactionId) return;
85
115
  this.currentTransactionId = next;
86
116
  for (const fn of [...this.transactionIdListeners]) {
117
+ if (this.destroyed) break;
87
118
  try {
88
119
  fn(next);
89
120
  } catch (error) {
@@ -93,18 +124,26 @@ class OnramperClient {
93
124
  }
94
125
  async initialize(creds) {
95
126
  try {
127
+ this.assertActive();
96
128
  await this.configured;
129
+ this.assertActive();
97
130
  await this.native.initialize(creds.sessionId, creds.sessionToken);
131
+ this.assertActive();
98
132
  } catch (e) {
133
+ this.assertActive();
99
134
  throw _errors.OnramperError.from(e);
100
135
  }
101
136
  }
102
137
  async reset() {
103
138
  try {
139
+ this.assertActive();
104
140
  await this.configured;
141
+ this.assertActive();
105
142
  await this.native.reset();
143
+ this.assertActive();
106
144
  this.updateCurrentTransactionId(null);
107
145
  } catch (e) {
146
+ this.assertActive();
108
147
  throw _errors.OnramperError.from(e);
109
148
  }
110
149
  }
@@ -117,10 +156,14 @@ class OnramperClient {
117
156
  */
118
157
  async signOut() {
119
158
  try {
159
+ this.assertActive();
120
160
  await this.configured;
161
+ this.assertActive();
121
162
  await this.native.signOut();
163
+ this.assertActive();
122
164
  this.updateCurrentTransactionId(null);
123
165
  } catch (e) {
166
+ this.assertActive();
124
167
  throw _errors.OnramperError.from(e);
125
168
  }
126
169
  }
@@ -129,6 +172,8 @@ class OnramperClient {
129
172
  * Fetches checkout requirements + quote and returns a native checkout button
130
173
  * to render plus the quote. The button handles login / finalize / webview
131
174
  * internally; outcomes surface via the event stream (`addEventListener`).
175
+ * A newer preparation, reset, or sign-out invalidates older unmounted buttons
176
+ * and rejects obsolete in-flight preparations with `intentInvalidated`.
132
177
  *
133
178
  * Pass `prefill` to pre-populate the OnramperID sign-in and additional-info
134
179
  * screens with values you already know about the user. It is best-effort and
@@ -142,32 +187,40 @@ class OnramperClient {
142
187
  */
143
188
  async getCheckoutRequirements(request, buttonStyle = {}, prefill = {}) {
144
189
  try {
190
+ this.assertActive();
145
191
  await this.configured;
192
+ this.assertActive();
146
193
  const result = await this.native.getCheckoutRequirements(JSON.stringify(request), JSON.stringify(prefill), JSON.stringify(buttonStyle));
194
+ this.assertActive();
147
195
  const quote = JSON.parse(result.quoteJson);
148
- const button = /*#__PURE__*/(0, _react.createElement)(_OnramperCheckoutButtonView.OnramperCheckoutButtonView, {
149
- intentHandle: result.intentHandle,
150
- style: {
151
- width: '100%',
152
- minHeight: 56
153
- }
196
+ const button = /*#__PURE__*/(0, _react.createElement)(_CheckoutButton.CheckoutButton, {
197
+ intentHandle: result.intentHandle
154
198
  });
155
199
  return {
156
200
  button,
157
201
  quote
158
202
  };
159
203
  } catch (e) {
204
+ this.assertActive();
160
205
  throw _errors.OnramperError.from(e);
161
206
  }
162
207
  }
163
208
 
164
209
  /** Discards a prepared intent (e.g. if the user navigates away before checkout). */
165
- cancelPreparedIntent(intentHandle) {
166
- return this.native.cancelPreparedIntent(intentHandle);
210
+ async cancelPreparedIntent(intentHandle) {
211
+ try {
212
+ this.assertActive();
213
+ await this.native.cancelPreparedIntent(intentHandle);
214
+ this.assertActive();
215
+ } catch (e) {
216
+ this.assertActive();
217
+ throw _errors.OnramperError.from(e);
218
+ }
167
219
  }
168
220
 
169
221
  /** Subscribe to state changes. Returns an unsubscribe function. */
170
222
  addStateListener(fn) {
223
+ this.assertActive();
171
224
  this.stateListeners.add(fn);
172
225
  return () => {
173
226
  this.stateListeners.delete(fn);
@@ -176,6 +229,7 @@ class OnramperClient {
176
229
 
177
230
  /** Subscribe to the durable Onramper transaction ID. Successful reset/signOut publish null. */
178
231
  addTransactionIdListener(fn) {
232
+ this.assertActive();
179
233
  this.transactionIdListeners.add(fn);
180
234
  return () => {
181
235
  this.transactionIdListeners.delete(fn);
@@ -184,6 +238,7 @@ class OnramperClient {
184
238
 
185
239
  /** Subscribe to a specific checkout event. Returns an unsubscribe function. */
186
240
  addEventListener(name, fn) {
241
+ this.assertActive();
187
242
  const wrapper = e => {
188
243
  if (e.type === name) fn(e);
189
244
  };
@@ -193,8 +248,10 @@ class OnramperClient {
193
248
  };
194
249
  }
195
250
 
196
- /** Tear down: clears JS listeners and releases the native callbacks + SDK client. */
251
+ /** Idempotent teardown. Further operations reject with `clientDestroyed`; create a new client to restart. */
197
252
  destroy() {
253
+ if (this.destroyed) return;
254
+ this.destroyed = true;
198
255
  this.stateListeners.clear();
199
256
  this.eventListeners.clear();
200
257
  this.transactionIdListeners.clear();
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_OnramperCheckoutButtonView","_OnramperNative","_errors","OnramperClient","state","kind","lastError","currentTransactionId","native","createOnramperNative","stateListeners","Set","eventListeners","transactionIdListeners","constructor","config","setStateListener","json","s","JSON","parse","OnramperError","from","error","fn","setEventListener","e","type","updateCurrentTransactionId","response","onramperTransactionId","setTransactionIdListener","transactionId","undefined","setSessionExpirationHandler","creds","onSessionExpired","sessionId","sessionToken","configured","configure","apiKey","clientId","environment","theme","logLevel","catch","err","next","console","initialize","reset","signOut","getCheckoutRequirements","request","buttonStyle","prefill","result","stringify","quote","quoteJson","button","createElement","OnramperCheckoutButtonView","intentHandle","style","width","minHeight","cancelPreparedIntent","addStateListener","add","delete","addTransactionIdListener","addEventListener","name","wrapper","destroy","clear","dispose","exports"],"sourceRoot":"../../src","sources":["OnramperClient.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,2BAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAmBA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMI,cAAc,CAAC;EAC1BC,KAAK,GAAkB;IAAEC,IAAI,EAAE;EAAO,CAAC;EACvCC,SAAS,GAAyB,IAAI;EACtCC,oBAAoB,GAAkB,IAAI;;EAE1C;EACiBC,MAAM,GAAG,IAAAC,oCAAoB,EAAC,CAAC;EAE/BC,cAAc,GAAG,IAAIC,GAAG,CAAiC,CAAC;EAC1DC,cAAc,GAAG,IAAID,GAAG,CAAiC,CAAC;EAC1DE,sBAAsB,GAAG,IAAIF,GAAG,CAAyC,CAAC;;EAE3F;EACA;;EAGAG,WAAWA,CAACC,MAA6B,EAAE;I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E,OAAO,CAAC,CAAC;EACvB;AACF;AAACC,OAAA,CAAA5E,cAAA,GAAAA,cAAA","ignoreList":[]}
1
+ {"version":3,"names":["_react","require","_CheckoutButton","_OnramperNative","_errors","OnramperClient","state","kind","lastError","currentTransactionId","native","createOnramperNative","stateListeners","Set","eventListeners","transactionIdListeners","destroyed","constructor","config","logHandler","handler","setLogListener","json","JSON","parse","console","warn","setStateListener","s","OnramperError","from","error","fn","setEventListener","e","type","updateCurrentTransactionId","response","onramperTransactionId","setTransactionIdListener","transactionId","undefined","setSessionExpirationHandler","assertActive","creds","onSessionExpired","sessionId","sessionToken","configured","configure","apiKey","clientId","environment","theme","logLevel","isEventLoggingEnabled","isEventConsoleLoggingEnabled","catch","err","code","message","userMessage","next","initialize","reset","signOut","getCheckoutRequirements","request","buttonStyle","prefill","result","stringify","quote","quoteJson","button","createElement","CheckoutButton","intentHandle","cancelPreparedIntent","addStateListener","add","delete","addTransactionIdListener","addEventListener","name","wrapper","destroy","clear","dispose","exports"],"sourceRoot":"../../src","sources":["OnramperClient.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAoBA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMI,cAAc,CAAC;EAC1BC,KAAK,GAAkB;IAAEC,IAAI,EAAE;EAAO,CAAC;EACvCC,SAAS,GAAyB,IAAI;EACtCC,oBAAoB,GAAkB,IAAI;;EAE1C;EACiBC,MAAM,GAAG,IAAAC,oCAAoB,EAAC,CAAC;EAE/BC,cAAc,GAAG,IAAIC,GAAG,CAAiC,CAAC;EAC1DC,cAAc,GAAG,IAAID,GAAG,CAAiC,CAAC;EAC1DE,sBAAsB,GAAG,IAAIF,GAAG,CAAyC,CAAC;;EAE3F;EACA;;EAEQG,SAAS,GAAG,KAAK;EAEzBC,WAAWA,CAACC,MAA6B,EAAE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ACAmD,gBAAgBA,CAAsBC,IAAO,EAAEpD,EAAgC,EAAc;IAC3F,IAAI,CAACW,YAAY,CAAC,CAAC;IACnB,MAAM0C,OAAO,GAAInD,CAAgB,IAAK;MACpC,IAAIA,CAAC,CAACC,IAAI,KAAKiD,IAAI,EAAEpD,EAAE,CAACE,CAAoB,CAAC;IAC/C,CAAC;IACD,IAAI,CAACpB,cAAc,CAACkE,GAAG,CAACK,OAAO,CAAC;IAChC,OAAO,MAAM;MACX,IAAI,CAACvE,cAAc,CAACmE,MAAM,CAACI,OAAO,CAAC;IACrC,CAAC;EACH;;EAEA;EACAC,OAAOA,CAAA,EAAS;IACd,IAAI,IAAI,CAACtE,SAAS,EAAE;IACpB,IAAI,CAACA,SAAS,GAAG,IAAI;IACrB,IAAI,CAACJ,cAAc,CAAC2E,KAAK,CAAC,CAAC;IAC3B,IAAI,CAACzE,cAAc,CAACyE,KAAK,CAAC,CAAC;IAC3B,IAAI,CAACxE,sBAAsB,CAACwE,KAAK,CAAC,CAAC;IACnC,IAAI,CAAC7E,MAAM,CAAC8E,OAAO,CAAC,CAAC;EACvB;AACF;AAACC,OAAA,CAAApF,cAAA,GAAAA,cAAA","ignoreList":[]}
@@ -9,20 +9,34 @@ class OnramperError extends Error {
9
9
  super(payload.message);
10
10
  this.name = 'OnramperError';
11
11
  this.code = payload.code;
12
+ this.userMessage = payload.userMessage ?? 'Something went wrong. Please try again.';
13
+ this.supportCode = payload.supportCode ?? payload.code;
12
14
  this.info = payload.info;
13
15
  }
14
16
  static from(value) {
15
17
  if (value instanceof OnramperError) return value;
18
+ // Nitro transports Swift exceptions as message-only JS Errors. Our native
19
+ // bridge encodes SDK errors explicitly so Promise rejections retain the
20
+ // same fields as failed events, without consulting unrelated client state.
21
+ const message = value instanceof Error ? value.message : typeof value === 'string' ? value : undefined;
22
+ if (message?.startsWith('ONRAMPER_ERROR:')) {
23
+ try {
24
+ const payload = JSON.parse(message.slice('ONRAMPER_ERROR:'.length));
25
+ if (payload && typeof payload.code === 'string' && typeof payload.message === 'string') {
26
+ return OnramperError.from(payload);
27
+ }
28
+ } catch {
29
+ // A malformed/non-SDK error falls back to the ordinary error path.
30
+ }
31
+ }
16
32
  if (value && typeof value === 'object') {
17
- // Structured errors (from the `.failed` state) arrive as a plain
18
- // `{ code, message, info? }` object. Thrown promise rejections surface
19
- // as a JS Error with just a message; we default the code in that case
20
- // (the structured error is also available on `client.state` / lastError).
21
33
  const v = value;
22
34
  return new OnramperError({
23
35
  code: v.code ?? 'unrecoverable',
24
36
  message: v.message ?? 'Unknown error',
25
- info: v.info
37
+ info: v.info,
38
+ userMessage: typeof v.userMessage === 'string' ? v.userMessage : undefined,
39
+ supportCode: typeof v.supportCode === 'string' ? v.supportCode : undefined
26
40
  });
27
41
  }
28
42
  return new OnramperError({
@@ -1 +1 @@
1
- {"version":3,"names":["OnramperError","Error","constructor","payload","message","name","code","info","from","value","v","String","exports"],"sourceRoot":"../../src","sources":["errors.ts"],"mappings":";;;;;;AAyCO,MAAMA,aAAa,SAASC,KAAK,CAAiC;EAIvEC,WAAWA,CAACC,OAA6B,EAAE;IACzC,KAAK,CAACA,OAAO,CAACC,OAAO,CAAC;IACtB,IAAI,CAACC,IAAI,GAAG,eAAe;IAC3B,IAAI,CAACC,IAAI,GAAGH,OAAO,CAACG,IAAI;IACxB,IAAI,CAACC,IAAI,GAAGJ,OAAO,CAACI,IAAI;EAC1B;EAEA,OAAOC,IAAIA,CAACC,KAAc,EAAiB;IACzC,IAAIA,KAAK,YAAYT,aAAa,EAAE,OAAOS,KAAK;IAChD,IAAIA,KAAK,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MACtC;MACA;MACA;MACA;MACA,MAAMC,CAAC,GAAGD,KAA4E;MACtF,OAAO,IAAIT,aAAa,CAAC;QACvBM,IAAI,EAAGI,CAAC,CAACJ,IAAI,IAAI,eAAqC;QACtDF,OAAO,EAAEM,CAAC,CAACN,OAAO,IAAI,eAAe;QACrCG,IAAI,EAAEG,CAAC,CAACH;MACV,CAAC,CAAC;IACJ;IACA,OAAO,IAAIP,aAAa,CAAC;MAAEM,IAAI,EAAE,eAAe;MAAEF,OAAO,EAAEO,MAAM,CAACF,KAAK;IAAE,CAAC,CAAC;EAC7E;AACF;AAACG,OAAA,CAAAZ,aAAA,GAAAA,aAAA","ignoreList":[]}
1
+ {"version":3,"names":["OnramperError","Error","constructor","payload","message","name","code","userMessage","supportCode","info","from","value","undefined","startsWith","JSON","parse","slice","length","v","String","exports"],"sourceRoot":"../../src","sources":["errors.ts"],"mappings":";;;;;;AAgDO,MAAMA,aAAa,SAASC,KAAK,CAAiC;EAMvEC,WAAWA,CAACC,OAA6B,EAAE;IACzC,KAAK,CAACA,OAAO,CAACC,OAAO,CAAC;IACtB,IAAI,CAACC,IAAI,GAAG,eAAe;IAC3B,IAAI,CAACC,IAAI,GAAGH,OAAO,CAACG,IAAI;IACxB,IAAI,CAACC,WAAW,GAAGJ,OAAO,CAACI,WAAW,IAAI,yCAAyC;IACnF,IAAI,CAACC,WAAW,GAAGL,OAAO,CAACK,WAAW,IAAIL,OAAO,CAACG,IAAI;IACtD,IAAI,CAACG,IAAI,GAAGN,OAAO,CAACM,IAAI;EAC1B;EAEA,OAAOC,IAAIA,CAACC,KAAc,EAAiB;IACzC,IAAIA,KAAK,YAAYX,aAAa,EAAE,OAAOW,KAAK;IAChD;IACA;IACA;IACA,MAAMP,OAAO,GAAGO,KAAK,YAAYV,KAAK,GAAGU,KAAK,CAACP,OAAO,GAAG,OAAOO,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAGC,SAAS;IACtG,IAAIR,OAAO,EAAES,UAAU,CAAC,iBAAiB,CAAC,EAAE;MAC1C,IAAI;QACF,MAAMV,OAAO,GAAGW,IAAI,CAACC,KAAK,CAACX,OAAO,CAACY,KAAK,CAAC,iBAAiB,CAACC,MAAM,CAAC,CAAC;QACnE,IAAId,OAAO,IAAI,OAAOA,OAAO,CAACG,IAAI,KAAK,QAAQ,IAAI,OAAOH,OAAO,CAACC,OAAO,KAAK,QAAQ,EAAE;UACtF,OAAOJ,aAAa,CAACU,IAAI,CAACP,OAAO,CAAC;QACpC;MACF,CAAC,CAAC,MAAM;QACN;MAAA;IAEJ;IACA,IAAIQ,KAAK,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MACtC,MAAMO,CAAC,GAAGP,KAAsC;MAChD,OAAO,IAAIX,aAAa,CAAC;QACvBM,IAAI,EAAGY,CAAC,CAACZ,IAAI,IAAI,eAAqC;QACtDF,OAAO,EAAEc,CAAC,CAACd,OAAO,IAAI,eAAe;QACrCK,IAAI,EAAES,CAAC,CAACT,IAAI;QACZF,WAAW,EAAE,OAAOW,CAAC,CAACX,WAAW,KAAK,QAAQ,GAAGW,CAAC,CAACX,WAAW,GAAGK,SAAS;QAC1EJ,WAAW,EAAE,OAAOU,CAAC,CAACV,WAAW,KAAK,QAAQ,GAAGU,CAAC,CAACV,WAAW,GAAGI;MACnE,CAAC,CAAC;IACJ;IACA,OAAO,IAAIZ,aAAa,CAAC;MAAEM,IAAI,EAAE,eAAe;MAAEF,OAAO,EAAEe,MAAM,CAACR,KAAK;IAAE,CAAC,CAAC;EAC7E;AACF;AAACS,OAAA,CAAApB,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -5,6 +5,7 @@
5
5
  "directEventTypes": {},
6
6
  "validAttributes": {
7
7
  "intentHandle": true,
8
+ "onContentHeightChange": true,
8
9
  "hybridRef": true
9
10
  }
10
11
  }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ import { createElement, useMemo, useState } from 'react';
4
+ import { callback } from 'react-native-nitro-modules';
5
+ import { OnramperCheckoutButtonView } from "./OnramperCheckoutButtonView.js";
6
+
7
+ // Height of the bare Buy button. Used until native reports the measured content
8
+ // height so the first frame isn't collapsed.
9
+ export const CHECKOUT_BUTTON_FALLBACK_HEIGHT = 56;
10
+ /**
11
+ * Sizes the native checkout button to its SwiftUI content. The content grows when
12
+ * the SDK shows ToS text under the Buy button (which can change after mount), and
13
+ * Yoga can't measure a SwiftUI view — so native reports the height and it is
14
+ * applied here as an explicit `height`.
15
+ */
16
+ export function CheckoutButton({
17
+ intentHandle
18
+ }) {
19
+ const [height, setHeight] = useState(null);
20
+ const onContentHeightChange = useMemo(() => callback(h => setHeight(Math.ceil(h))), []);
21
+ return /*#__PURE__*/createElement(OnramperCheckoutButtonView, {
22
+ intentHandle,
23
+ onContentHeightChange,
24
+ style: {
25
+ width: '100%',
26
+ height: height ?? CHECKOUT_BUTTON_FALLBACK_HEIGHT
27
+ }
28
+ });
29
+ }
30
+ //# sourceMappingURL=CheckoutButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createElement","useMemo","useState","callback","OnramperCheckoutButtonView","CHECKOUT_BUTTON_FALLBACK_HEIGHT","CheckoutButton","intentHandle","height","setHeight","onContentHeightChange","h","Math","ceil","style","width"],"sourceRoot":"../../src","sources":["CheckoutButton.ts"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACxD,SAASC,QAAQ,QAAQ,4BAA4B;AAErD,SAASC,0BAA0B,QAAQ,iCAA8B;;AAEzE;AACA;AACA,OAAO,MAAMC,+BAA+B,GAAG,EAAE;AAMjD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAC;EAAEC;AAAkC,CAAC,EAAE;EACpE,MAAM,CAACC,MAAM,EAAEC,SAAS,CAAC,GAAGP,QAAQ,CAAgB,IAAI,CAAC;EACzD,MAAMQ,qBAAqB,GAAGT,OAAO,CAAC,MAAME,QAAQ,CAAEQ,CAAS,IAAKF,SAAS,CAACG,IAAI,CAACC,IAAI,CAACF,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;EACjG,oBAAOX,aAAa,CAACI,0BAA0B,EAAE;IAC/CG,YAAY;IACZG,qBAAqB;IACrBI,KAAK,EAAE;MAAEC,KAAK,EAAE,MAAM;MAAEP,MAAM,EAAEA,MAAM,IAAIH;IAAgC;EAC5E,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  import { createElement } from 'react';
4
- import { OnramperCheckoutButtonView } from "./OnramperCheckoutButtonView.js";
4
+ import { CheckoutButton } from "./CheckoutButton.js";
5
5
  import { createOnramperNative } from "./OnramperNative.js";
6
6
  import { OnramperError } from "./errors.js";
7
7
  /**
@@ -26,9 +26,23 @@ export class OnramperClient {
26
26
  // Resolved when the constructor-issued configure() completes. Public methods
27
27
  // that need the native client await this first.
28
28
 
29
+ destroyed = false;
29
30
  constructor(config) {
31
+ if (config.logHandler) {
32
+ const handler = config.logHandler;
33
+ this.native.setLogListener(json => {
34
+ if (this.destroyed) return;
35
+ try {
36
+ handler(JSON.parse(json));
37
+ } catch {
38
+ // Diagnostics must never interrupt checkout; do not log callback data.
39
+ console.warn('Onramper logHandler failed.');
40
+ }
41
+ });
42
+ }
30
43
  // Single native state callback → update the mirror + fan out to listeners.
31
44
  this.native.setStateListener(json => {
45
+ if (this.destroyed) return;
32
46
  const s = JSON.parse(json);
33
47
  this.state = s;
34
48
  if (s.kind === 'failed') this.lastError = OnramperError.from(s.error);
@@ -38,6 +52,7 @@ export class OnramperClient {
38
52
  // Single native checkout-event callback → keep the transaction ID mirror
39
53
  // synchronized at finalization, then fan out to checkout listeners.
40
54
  this.native.setEventListener(json => {
55
+ if (this.destroyed) return;
41
56
  const e = JSON.parse(json);
42
57
  if (e.type === 'checkoutFinalized') {
43
58
  this.updateCurrentTransactionId(e.response.onramperTransactionId);
@@ -45,6 +60,7 @@ export class OnramperClient {
45
60
  for (const fn of this.eventListeners) fn(e);
46
61
  });
47
62
  this.native.setTransactionIdListener(transactionId => {
63
+ if (this.destroyed) return;
48
64
  // The SDK transiently publishes nil while re-preparing after the payment
49
65
  // sheet is dismissed. The finalized transaction ID remains durable across
50
66
  // that attempt change; only explicit reset()/signOut() clear the JS mirror.
@@ -55,7 +71,9 @@ export class OnramperClient {
55
71
  // Nitro stores the async callback natively and awaits it directly — no
56
72
  // event round-trip needed.
57
73
  this.native.setSessionExpirationHandler(async () => {
74
+ this.assertActive();
58
75
  const creds = await config.onSessionExpired();
76
+ this.assertActive();
59
77
  return {
60
78
  sessionId: creds.sessionId,
61
79
  sessionToken: creds.sessionToken
@@ -66,20 +84,33 @@ export class OnramperClient {
66
84
  clientId: config.clientId,
67
85
  environment: config.environment,
68
86
  theme: config.theme ?? 'system',
69
- logLevel: config.logLevel ?? 'off'
87
+ logLevel: config.logLevel ?? 'off',
88
+ isEventLoggingEnabled: config.isEventLoggingEnabled ?? false,
89
+ isEventConsoleLoggingEnabled: config.isEventConsoleLoggingEnabled ?? false
70
90
  }).catch(e => {
71
91
  const err = OnramperError.from(e);
72
- this.lastError = err;
92
+ if (!this.destroyed) this.lastError = err;
73
93
  throw err;
74
94
  });
75
95
  // Swallow the unhandled-rejection warning when no one awaits .configured
76
96
  // before calling initialize(). The error still surfaces via initialize().
77
97
  this.configured.catch(() => undefined);
78
98
  }
99
+ assertActive() {
100
+ if (this.destroyed) {
101
+ throw new OnramperError({
102
+ code: 'clientDestroyed',
103
+ message: 'This OnramperClient has been destroyed. Create a new client before making SDK calls.',
104
+ userMessage: 'This checkout session has ended. Please reopen checkout.'
105
+ });
106
+ }
107
+ }
79
108
  updateCurrentTransactionId(next) {
109
+ if (this.destroyed) return;
80
110
  if (next === this.currentTransactionId) return;
81
111
  this.currentTransactionId = next;
82
112
  for (const fn of [...this.transactionIdListeners]) {
113
+ if (this.destroyed) break;
83
114
  try {
84
115
  fn(next);
85
116
  } catch (error) {
@@ -89,18 +120,26 @@ export class OnramperClient {
89
120
  }
90
121
  async initialize(creds) {
91
122
  try {
123
+ this.assertActive();
92
124
  await this.configured;
125
+ this.assertActive();
93
126
  await this.native.initialize(creds.sessionId, creds.sessionToken);
127
+ this.assertActive();
94
128
  } catch (e) {
129
+ this.assertActive();
95
130
  throw OnramperError.from(e);
96
131
  }
97
132
  }
98
133
  async reset() {
99
134
  try {
135
+ this.assertActive();
100
136
  await this.configured;
137
+ this.assertActive();
101
138
  await this.native.reset();
139
+ this.assertActive();
102
140
  this.updateCurrentTransactionId(null);
103
141
  } catch (e) {
142
+ this.assertActive();
104
143
  throw OnramperError.from(e);
105
144
  }
106
145
  }
@@ -113,10 +152,14 @@ export class OnramperClient {
113
152
  */
114
153
  async signOut() {
115
154
  try {
155
+ this.assertActive();
116
156
  await this.configured;
157
+ this.assertActive();
117
158
  await this.native.signOut();
159
+ this.assertActive();
118
160
  this.updateCurrentTransactionId(null);
119
161
  } catch (e) {
162
+ this.assertActive();
120
163
  throw OnramperError.from(e);
121
164
  }
122
165
  }
@@ -125,6 +168,8 @@ export class OnramperClient {
125
168
  * Fetches checkout requirements + quote and returns a native checkout button
126
169
  * to render plus the quote. The button handles login / finalize / webview
127
170
  * internally; outcomes surface via the event stream (`addEventListener`).
171
+ * A newer preparation, reset, or sign-out invalidates older unmounted buttons
172
+ * and rejects obsolete in-flight preparations with `intentInvalidated`.
128
173
  *
129
174
  * Pass `prefill` to pre-populate the OnramperID sign-in and additional-info
130
175
  * screens with values you already know about the user. It is best-effort and
@@ -138,32 +183,40 @@ export class OnramperClient {
138
183
  */
139
184
  async getCheckoutRequirements(request, buttonStyle = {}, prefill = {}) {
140
185
  try {
186
+ this.assertActive();
141
187
  await this.configured;
188
+ this.assertActive();
142
189
  const result = await this.native.getCheckoutRequirements(JSON.stringify(request), JSON.stringify(prefill), JSON.stringify(buttonStyle));
190
+ this.assertActive();
143
191
  const quote = JSON.parse(result.quoteJson);
144
- const button = /*#__PURE__*/createElement(OnramperCheckoutButtonView, {
145
- intentHandle: result.intentHandle,
146
- style: {
147
- width: '100%',
148
- minHeight: 56
149
- }
192
+ const button = /*#__PURE__*/createElement(CheckoutButton, {
193
+ intentHandle: result.intentHandle
150
194
  });
151
195
  return {
152
196
  button,
153
197
  quote
154
198
  };
155
199
  } catch (e) {
200
+ this.assertActive();
156
201
  throw OnramperError.from(e);
157
202
  }
158
203
  }
159
204
 
160
205
  /** Discards a prepared intent (e.g. if the user navigates away before checkout). */
161
- cancelPreparedIntent(intentHandle) {
162
- return this.native.cancelPreparedIntent(intentHandle);
206
+ async cancelPreparedIntent(intentHandle) {
207
+ try {
208
+ this.assertActive();
209
+ await this.native.cancelPreparedIntent(intentHandle);
210
+ this.assertActive();
211
+ } catch (e) {
212
+ this.assertActive();
213
+ throw OnramperError.from(e);
214
+ }
163
215
  }
164
216
 
165
217
  /** Subscribe to state changes. Returns an unsubscribe function. */
166
218
  addStateListener(fn) {
219
+ this.assertActive();
167
220
  this.stateListeners.add(fn);
168
221
  return () => {
169
222
  this.stateListeners.delete(fn);
@@ -172,6 +225,7 @@ export class OnramperClient {
172
225
 
173
226
  /** Subscribe to the durable Onramper transaction ID. Successful reset/signOut publish null. */
174
227
  addTransactionIdListener(fn) {
228
+ this.assertActive();
175
229
  this.transactionIdListeners.add(fn);
176
230
  return () => {
177
231
  this.transactionIdListeners.delete(fn);
@@ -180,6 +234,7 @@ export class OnramperClient {
180
234
 
181
235
  /** Subscribe to a specific checkout event. Returns an unsubscribe function. */
182
236
  addEventListener(name, fn) {
237
+ this.assertActive();
183
238
  const wrapper = e => {
184
239
  if (e.type === name) fn(e);
185
240
  };
@@ -189,8 +244,10 @@ export class OnramperClient {
189
244
  };
190
245
  }
191
246
 
192
- /** Tear down: clears JS listeners and releases the native callbacks + SDK client. */
247
+ /** Idempotent teardown. Further operations reject with `clientDestroyed`; create a new client to restart. */
193
248
  destroy() {
249
+ if (this.destroyed) return;
250
+ this.destroyed = true;
194
251
  this.stateListeners.clear();
195
252
  this.eventListeners.clear();
196
253
  this.transactionIdListeners.clear();