react-native-plaid-link-sdk 12.8.3 → 12.8.5

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 (51) hide show
  1. package/README.md +3 -1
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/AndroidManifest.xml +1 -1
  4. package/android/src/main/java/com/plaid/PlaidModule.kt +60 -8
  5. package/android/src/paper/java/com/plaid/NativePlaidLinkModuleiOSSpec.java +5 -0
  6. package/dist/EmbeddedLink/EmbeddedLinkView.d.ts +13 -0
  7. package/dist/{build/EmbeddedLink → EmbeddedLink}/EmbeddedLinkView.js +0 -1
  8. package/dist/EmbeddedLink/EmbeddedLinkView.web.d.ts +1 -0
  9. package/dist/EmbeddedLink/EmbeddedLinkView.web.js +1 -0
  10. package/dist/{build/EmbeddedLink → EmbeddedLink}/NativeEmbeddedLinkView.js +0 -1
  11. package/dist/PlaidLink.d.ts +27 -0
  12. package/dist/{build/PlaidLink.js → PlaidLink.js} +8 -21
  13. package/dist/Types.d.ts +539 -0
  14. package/dist/{build/Types.js → Types.js} +0 -8
  15. package/dist/build/PlaidEmbeddedSearchView.d.ts +1 -1
  16. package/dist/build/PlaidEmbeddedSearchView.js +1 -7
  17. package/dist/build/ReactNativePlaidLinkSdk.types.d.ts +1 -1
  18. package/dist/build/ReactNativePlaidLinkSdk.types.js +2 -1
  19. package/dist/build/index.js +53 -103
  20. package/dist/fabric/EmbeddedLinkViewNativeComponent.d.ts +15 -0
  21. package/dist/{build/fabric → fabric}/EmbeddedLinkViewNativeComponent.js +0 -1
  22. package/dist/fabric/NativePlaidLinkModuleAndroid.d.ts +14 -0
  23. package/dist/{build/fabric → fabric}/NativePlaidLinkModuleAndroid.js +0 -1
  24. package/dist/fabric/NativePlaidLinkModuleiOS.d.ts +15 -0
  25. package/dist/{build/fabric → fabric}/NativePlaidLinkModuleiOS.js +0 -1
  26. package/dist/fabric/fabricUtils.d.ts +1 -0
  27. package/dist/index.d.ts +4 -0
  28. package/dist/index.js +6 -0
  29. package/dist/src/PlaidLink.js +3 -0
  30. package/dist/src/fabric/NativePlaidLinkModuleiOS.d.ts +1 -0
  31. package/ios/RNLinksdk.mm +45 -11
  32. package/package.json +1 -1
  33. package/react-native-plaid-link-sdk.podspec +1 -1
  34. package/src/PlaidLink.tsx +2 -0
  35. package/src/__tests__/iOSCallbackLifecycle.tests.js +127 -0
  36. package/src/fabric/NativePlaidLinkModuleiOS.ts +1 -0
  37. package/dist/build/EmbeddedLink/EmbeddedLinkView.d.ts +0 -2
  38. package/dist/build/EmbeddedLink/EmbeddedLinkView.web.d.ts +0 -1
  39. package/dist/build/EmbeddedLink/EmbeddedLinkView.web.js +0 -2
  40. package/dist/build/PlaidLink.d.ts +0 -7
  41. package/dist/build/ReactNativePlaidLinkSdkView.d.ts +0 -2
  42. package/dist/build/ReactNativePlaidLinkSdkView.js +0 -7
  43. package/dist/build/Types.d.ts +0 -108
  44. package/dist/build/fabric/EmbeddedLinkViewNativeComponent.d.ts +0 -2
  45. package/dist/build/fabric/NativePlaidLinkModuleAndroid.d.ts +0 -2
  46. package/dist/build/fabric/NativePlaidLinkModuleiOS.d.ts +0 -2
  47. package/dist/build/fabric/fabricUtils.js +0 -2
  48. package/dist/{build/EmbeddedLink → EmbeddedLink}/NativeEmbeddedLinkView.d.ts +1 -1
  49. /package/dist/{src/__tests__ → __tests__}/Types.tests.d.ts +0 -0
  50. /package/dist/{src/__tests__ → __tests__}/Types.tests.js +0 -0
  51. /package/dist/{build/fabric/fabricUtils.d.ts → fabric/fabricUtils.js} +0 -0
package/README.md CHANGED
@@ -168,7 +168,7 @@ The React Native Plaid module emits `onEvent` events throughout the account link
168
168
 
169
169
  #### Clearing Previous Session State with `destroy()`
170
170
 
171
- The `destroy()` method clears state and resources from a previously opened session.
171
+ The `destroy()` method clears state and resources from a previously opened session. On iOS, it also dismisses any presented Link UI and clears stored callback state.
172
172
  It's especially useful if you're seeing unexpected behavior when calling `create()` multiple times — for example, if the phone number isn't submitting properly after multiple `create()` calls.
173
173
 
174
174
  #### Problem scenario:
@@ -215,6 +215,8 @@ If migrating from older versions, see the [docs](https://plaid.com/docs/link/rea
215
215
 
216
216
  | Plaid SDK Version | Min React Native Version | Android SDK | Android Min Version | Android Compile Version| iOS SDK | iOS Min Version | Status |
217
217
  |-------------------|--------------------------|-------------|---------------------|------------------------|---------|-----------------|-------------------------------|
218
+ | 12.8.5 | * | [5.5.3+] | 21 | 34 | >=6.5.0 | 14.0 | Active, supports Xcode 16.1.0 |
219
+ | 12.8.4 | * | [5.5.2+] | 21 | 34 | >=6.4.7 | 14.0 | Active, supports Xcode 16.1.0 |
218
220
  | 12.8.3 | * | [5.5.1+] | 21 | 34 | >=6.4.3 | 14.0 | Active, supports Xcode 16.1.0 |
219
221
  | 12.8.2 | * | [5.5.1+] | 21 | 34 | >=6.4.3 | 14.0 | Active, supports Xcode 16.1.0 |
220
222
  | 12.8.1 | * | [5.5.2+] | 21 | 34 | >=6.4.3 | 14.0 | Active, supports Xcode 16.1.0 |
@@ -106,6 +106,6 @@ repositories {
106
106
 
107
107
  dependencies {
108
108
  implementation "com.facebook.react:react-native:+"
109
- implementation "com.plaid.link:sdk-core:5.5.2"
109
+ implementation "com.plaid.link:sdk-core:5.5.3"
110
110
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
111
111
  }
@@ -3,7 +3,7 @@
3
3
  <application>
4
4
  <meta-data
5
5
  android:name="com.plaid.link.react_native"
6
- android:value="12.8.3" />
6
+ android:value="12.8.5" />
7
7
  </application>
8
8
 
9
9
  </manifest>
@@ -38,11 +38,18 @@ class PlaidModule internal constructor(reactContext: ReactApplicationContext) :
38
38
 
39
39
  private val jsonConverter by lazy { PlaidJsonConverter() }
40
40
 
41
- private var onSuccessCallback: Callback? = null
42
- private var onExitCallback: Callback? = null
41
+ // Written on the RN native-modules thread (open/create), read and cleared on the
42
+ // main thread (onActivityResult); @Volatile for cross-thread visibility.
43
+ @Volatile private var onSuccessCallback: Callback? = null
44
+ @Volatile private var onExitCallback: Callback? = null
43
45
 
44
46
  private var plaidHandler: PlaidHandler? = null
45
47
 
48
+ // Tracks whether this module has created a Link session in this process. Guards
49
+ // releaseCurrentSession() so Plaid.destroy() isn't called when there is nothing to
50
+ // release, which would tear down sessions this module doesn't own (e.g. embedded Link).
51
+ private var didCreateSession = false
52
+
46
53
  companion object {
47
54
  private const val LINK_TOKEN_PREFIX = "link"
48
55
 
@@ -114,6 +121,12 @@ class PlaidModule internal constructor(reactContext: ReactApplicationContext) :
114
121
  throw LinkException("Unable to open link, please check that your configuration is valid")
115
122
  }
116
123
 
124
+ // Tear down any previous session before creating a new one. Without this, a stale session (e.g. the
125
+ // user bypassed the OAuth redirect and relaunched Link) leaves old callbacks in place, and its result
126
+ // can re-invoke a spent RN Callback, crashing with "This callback type only permits a single
127
+ // invocation from native code."
128
+ releaseCurrentSession()
129
+
117
130
  // Set the event listener here instead of in open for Layer use cases.
118
131
  try {
119
132
  Plaid.setLinkEventListener { linkEvent: LinkEvent ->
@@ -139,6 +152,7 @@ class PlaidModule internal constructor(reactContext: ReactApplicationContext) :
139
152
  }
140
153
  }
141
154
  )
155
+ this.didCreateSession = true
142
156
  }
143
157
 
144
158
  @ReactMethod
@@ -194,6 +208,10 @@ class PlaidModule internal constructor(reactContext: ReactApplicationContext) :
194
208
  onExitCallback: Callback
195
209
  ) {
196
210
  val activity = reactApplicationContext.currentActivity ?: throw IllegalStateException("Current activity is null")
211
+
212
+ // Tear down any previous session before starting a new one. See create() for rationale.
213
+ releaseCurrentSession()
214
+
197
215
  this.onSuccessCallback = onSuccessCallback
198
216
  this.onExitCallback = onExitCallback
199
217
 
@@ -207,10 +225,12 @@ class PlaidModule internal constructor(reactContext: ReactApplicationContext) :
207
225
 
208
226
  val tokenConfiguration = getLinkTokenConfiguration(token, noLoadingState, getLogLevel(logLevel))
209
227
  tokenConfiguration?.let {
210
- Plaid.create(
228
+ val handler = Plaid.create(
211
229
  reactApplicationContext.getApplicationContext() as Application,
212
230
  it
213
- ).open(activity)
231
+ )
232
+ this.didCreateSession = true
233
+ handler.open(activity)
214
234
  return
215
235
  }
216
236
 
@@ -225,6 +245,32 @@ class PlaidModule internal constructor(reactContext: ReactApplicationContext) :
225
245
 
226
246
  override fun removeListeners(count: Double) = Unit
227
247
 
248
+ /**
249
+ * Releases the current Link session: drops any pending success/exit callbacks, clears the cached
250
+ * handler, and tears down the underlying Plaid SDK resources (preloaded WebView / token component)
251
+ * via [Plaid.destroy]. Safe to call when no session exists (no-op). Used before creating a new
252
+ * session so a stale session cannot deliver a result into spent callbacks.
253
+ *
254
+ * Plaid.destroy() is deliberately called synchronously on the calling (RN native-modules) thread
255
+ * rather than posted to the main looper: the caller creates the replacement session immediately
256
+ * afterwards on this thread, and an async destroy could run after Plaid.create() and null the new
257
+ * session's token component.
258
+ */
259
+ private fun releaseCurrentSession() {
260
+ onSuccessCallback = null
261
+ onExitCallback = null
262
+ plaidHandler = null
263
+ if (!didCreateSession) {
264
+ return
265
+ }
266
+ didCreateSession = false
267
+ try {
268
+ Plaid.destroy()
269
+ } catch (ex: Exception) {
270
+ Log.w("PlaidModule", "Failed to destroy previous Plaid session", ex)
271
+ }
272
+ }
273
+
228
274
  private fun maybeGetStringField(obj: JSONObject, fieldName: String): String? {
229
275
  if (obj.has(fieldName) && !TextUtils.isEmpty(obj.getString(fieldName))) {
230
276
  return obj.getString(fieldName)
@@ -267,13 +313,19 @@ class PlaidModule internal constructor(reactContext: ReactApplicationContext) :
267
313
  val linkHandler = LinkResultHandler(
268
314
  onSuccess = { success ->
269
315
  val result = convertJsonToMap(JSONObject(jsonConverter.convert(success)))
270
- print(result)
271
- this.onSuccessCallback?.invoke(result)
316
+ // Capture and null both callbacks before invoking so a duplicate result delivery cannot
317
+ // re-invoke a single-use RN Callback.
318
+ val callback = this.onSuccessCallback
319
+ this.onSuccessCallback = null
320
+ this.onExitCallback = null
321
+ callback?.invoke(result)
272
322
  },
273
323
  onExit = { exit ->
274
324
  val result = convertJsonToMap(JSONObject(jsonConverter.convert(exit)))
275
- print(result)
276
- this.onExitCallback?.invoke(result)
325
+ val callback = this.onExitCallback
326
+ this.onSuccessCallback = null
327
+ this.onExitCallback = null
328
+ callback?.invoke(result)
277
329
  }
278
330
  )
279
331
 
@@ -14,6 +14,7 @@ package com.plaid;
14
14
 
15
15
  import com.facebook.proguard.annotations.DoNotStrip;
16
16
  import com.facebook.react.bridge.Callback;
17
+ import com.facebook.react.bridge.Promise;
17
18
  import com.facebook.react.bridge.ReactApplicationContext;
18
19
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
19
20
  import com.facebook.react.bridge.ReactMethod;
@@ -45,6 +46,10 @@ public abstract class NativePlaidLinkModuleiOSSpec extends ReactContextBaseJavaM
45
46
  @DoNotStrip
46
47
  public abstract void dismiss();
47
48
 
49
+ @ReactMethod
50
+ @DoNotStrip
51
+ public abstract void destroy(Promise promise);
52
+
48
53
  @ReactMethod
49
54
  @DoNotStrip
50
55
  public abstract void submit(String phoneNumber, String dateOfBirth, ReadableMap params);
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { StyleProp, ViewStyle } from 'react-native';
3
+ import { LinkSuccessListener, LinkExitListener, LinkIOSPresentationStyle, LinkOnEventListener } from '../Types';
4
+ type EmbeddedLinkProps = {
5
+ token: string;
6
+ iOSPresentationStyle: LinkIOSPresentationStyle;
7
+ onEvent: LinkOnEventListener | undefined;
8
+ onSuccess: LinkSuccessListener;
9
+ onExit: LinkExitListener | undefined;
10
+ style: StyleProp<ViewStyle> | undefined;
11
+ };
12
+ export declare const EmbeddedLinkView: React.FC<EmbeddedLinkProps>;
13
+ export {};
@@ -53,4 +53,3 @@ export const EmbeddedLinkView = (props) => {
53
53
  };
54
54
  return <NativeEmbeddedLinkView token={token} iOSPresentationStyle={iOSPresentationStyle.toString()} onEmbeddedEvent={onEmbeddedEvent} style={style}/>;
55
55
  };
56
- //# sourceMappingURL=EmbeddedLinkView.js.map
@@ -0,0 +1 @@
1
+ export declare const EmbeddedLinkView: () => null;
@@ -0,0 +1 @@
1
+ export const EmbeddedLinkView = () => null;
@@ -1,3 +1,2 @@
1
1
  import NativeEmbeddedLinkView from '../fabric/EmbeddedLinkViewNativeComponent';
2
2
  export default NativeEmbeddedLinkView;
3
- //# sourceMappingURL=NativeEmbeddedLinkView.js.map
@@ -0,0 +1,27 @@
1
+ import { LinkEventListener, LinkOpenProps, LinkTokenConfiguration, FinanceKitError, SubmissionData } from './Types';
2
+ /**
3
+ * A hook that registers a listener on the Plaid emitter for the 'onEvent' type.
4
+ * The listener is cleaned up when this view is unmounted
5
+ *
6
+ * @param LinkEventListener the listener to call
7
+ */
8
+ export declare const usePlaidEmitter: (linkEventListener: LinkEventListener) => void;
9
+ export declare const create: (props: LinkTokenConfiguration) => void;
10
+ export declare const open: (props: LinkOpenProps) => Promise<void>;
11
+ export declare const dismissLink: () => void;
12
+ export declare const submit: (data: SubmissionData) => void;
13
+ /**
14
+ * Function to sync the user's transactions from their Apple card.
15
+ *
16
+ * @param {string} token - The `LinkToken` your server retrieved from the /link/token/create endpoint from the Plaid API.
17
+ * This token must be associated with an accessToken.
18
+ * @param {boolean} requestAuthorizationIfNeeded - Indicates if the user should be prompted to authorize the sync if
19
+ * they have not already done so.
20
+ * @param {function} completion - A callback function that is called when the sync has completed.
21
+ *
22
+ * @warning This method only works on iOS >= 17.4.
23
+ * @warning This method is not supported on Android or MacCatalyst.
24
+ * @warning This method can only be used once the user has granted access to their Apple card via a standard Link Session.
25
+ * @warning This method requires that your app has been granted FinanceKit access from Apple.
26
+ */
27
+ export declare const syncFinanceKit: (token: string, requestAuthorizationIfNeeded: boolean, completion: (error?: FinanceKitError) => void) => void;
@@ -31,18 +31,17 @@ export const usePlaidEmitter = (linkEventListener) => {
31
31
  }, []);
32
32
  };
33
33
  export const create = (props) => {
34
- var _a, _b, _c, _d;
34
+ var _a, _b;
35
35
  let token = props.token;
36
36
  let noLoadingState = (_a = props.noLoadingState) !== null && _a !== void 0 ? _a : false;
37
37
  if (Platform.OS === 'android') {
38
- RNLinksdkAndroid === null || RNLinksdkAndroid === void 0 ? void 0 : RNLinksdkAndroid.createPlaidLink(token, noLoadingState, (_b = props.logLevel) !== null && _b !== void 0 ? _b : LinkLogLevel.ERROR, (_c = props.onLoad) !== null && _c !== void 0 ? _c : (() => { }));
38
+ RNLinksdkAndroid === null || RNLinksdkAndroid === void 0 ? void 0 : RNLinksdkAndroid.create(token, noLoadingState, (_b = props.logLevel) !== null && _b !== void 0 ? _b : LinkLogLevel.ERROR);
39
39
  }
40
40
  else {
41
- const onLoad = (_d = props.onLoad) !== null && _d !== void 0 ? _d : (() => { });
42
- RNLinksdkiOS === null || RNLinksdkiOS === void 0 ? void 0 : RNLinksdkiOS.createPlaidLink(token, noLoadingState, onLoad);
41
+ RNLinksdkiOS === null || RNLinksdkiOS === void 0 ? void 0 : RNLinksdkiOS.create(token, noLoadingState);
43
42
  }
44
43
  };
45
- export const open = (props) => {
44
+ export const open = (props) => __awaiter(void 0, void 0, void 0, function* () {
46
45
  if (Platform.OS === 'android') {
47
46
  RNLinksdkAndroid === null || RNLinksdkAndroid === void 0 ? void 0 : RNLinksdkAndroid.open((result) => {
48
47
  if (props.onSuccess != null) {
@@ -77,17 +76,6 @@ export const open = (props) => {
77
76
  }
78
77
  });
79
78
  }
80
- };
81
- /**
82
- * Clears any previously created Plaid session and associated resources
83
- * that were captured during a prior call to create(). This method should
84
- * be invoked before starting a new layer session with create() to ensure
85
- * proper cleanup and avoid conflicts from lingering state or resources.
86
- */
87
- export const destroy = () => __awaiter(void 0, void 0, void 0, function* () {
88
- if (Platform.OS === 'android') {
89
- yield (RNLinksdkAndroid === null || RNLinksdkAndroid === void 0 ? void 0 : RNLinksdkAndroid.destroy());
90
- }
91
79
  });
92
80
  export const dismissLink = () => {
93
81
  if (Platform.OS === 'ios') {
@@ -96,10 +84,10 @@ export const dismissLink = () => {
96
84
  };
97
85
  export const submit = (data) => {
98
86
  if (Platform.OS === 'android') {
99
- RNLinksdkAndroid === null || RNLinksdkAndroid === void 0 ? void 0 : RNLinksdkAndroid.submit(data.phoneNumber, data.dateOfBirth, data.params);
87
+ RNLinksdkAndroid === null || RNLinksdkAndroid === void 0 ? void 0 : RNLinksdkAndroid.submit(data.phoneNumber);
100
88
  }
101
89
  else {
102
- RNLinksdkiOS === null || RNLinksdkiOS === void 0 ? void 0 : RNLinksdkiOS.submit(data.phoneNumber, data.dateOfBirth, data.params);
90
+ RNLinksdkiOS === null || RNLinksdkiOS === void 0 ? void 0 : RNLinksdkiOS.submit(data.phoneNumber);
103
91
  }
104
92
  };
105
93
  /**
@@ -116,7 +104,7 @@ export const submit = (data) => {
116
104
  * @warning This method can only be used once the user has granted access to their Apple card via a standard Link Session.
117
105
  * @warning This method requires that your app has been granted FinanceKit access from Apple.
118
106
  */
119
- export const syncFinanceKit = (token, requestAuthorizationIfNeeded, simulatedBehavior, completion) => {
107
+ export const syncFinanceKit = (token, requestAuthorizationIfNeeded, completion) => {
120
108
  if (Platform.OS === 'android') {
121
109
  completion({
122
110
  type: FinanceKitErrorType.Unknown,
@@ -124,7 +112,7 @@ export const syncFinanceKit = (token, requestAuthorizationIfNeeded, simulatedBeh
124
112
  });
125
113
  }
126
114
  else {
127
- RNLinksdkiOS === null || RNLinksdkiOS === void 0 ? void 0 : RNLinksdkiOS.syncFinanceKit(token, requestAuthorizationIfNeeded, simulatedBehavior, () => {
115
+ RNLinksdkiOS === null || RNLinksdkiOS === void 0 ? void 0 : RNLinksdkiOS.syncFinanceKit(token, requestAuthorizationIfNeeded, () => {
128
116
  completion();
129
117
  }, (error) => {
130
118
  completion({
@@ -134,4 +122,3 @@ export const syncFinanceKit = (token, requestAuthorizationIfNeeded, simulatedBeh
134
122
  });
135
123
  }
136
124
  };
137
- //# sourceMappingURL=PlaidLink.js.map