From 5da11b6da110395105564ba25e617723e845dc3e Mon Sep 17 00:00:00 2001 From: dtroupe Date: Mon, 30 Mar 2026 14:17:39 -0700 Subject: [PATCH 1/2] name space events --- ios/src/ReactNativePlaidLinkSdkModule.swift | 6 +-- .../ReactNativePlaidLinkSdkModule.ts | 12 ++--- .../createPlaidHeadlessSession.test.ts | 14 +++--- src/__tests__/createPlaidLayerSession.test.ts | 8 ++-- src/__tests__/createPlaidLinkSession.test.ts | 22 ++++----- src/__tests__/listener-lifecycle.test.ts | 46 +++++++++---------- src/index.ts | 18 ++++---- 7 files changed, 63 insertions(+), 63 deletions(-) diff --git a/ios/src/ReactNativePlaidLinkSdkModule.swift b/ios/src/ReactNativePlaidLinkSdkModule.swift index 85cb6c7f..f115d749 100644 --- a/ios/src/ReactNativePlaidLinkSdkModule.swift +++ b/ios/src/ReactNativePlaidLinkSdkModule.swift @@ -337,9 +337,9 @@ public class ReactNativePlaidLinkSdkModule: Module { /// Event names that the module can send to JavaScript. enum ModuleEventName: String, CaseIterable { - case onSuccess - case onExit - case onEvent + case onSuccess = "PlaidLink.onSuccess" + case onExit = "PlaidLink.onExit" + case onEvent = "PlaidLink.onEvent" } /// Function names that the module can call from JavaScript. diff --git a/src/__mocks__/ReactNativePlaidLinkSdkModule.ts b/src/__mocks__/ReactNativePlaidLinkSdkModule.ts index 1d052a36..c78b7586 100644 --- a/src/__mocks__/ReactNativePlaidLinkSdkModule.ts +++ b/src/__mocks__/ReactNativePlaidLinkSdkModule.ts @@ -1,7 +1,7 @@ const mockListeners: Record = { - onSuccess: [], - onExit: [], - onEvent: [], + "PlaidLink.onSuccess": [], + "PlaidLink.onExit": [], + "PlaidLink.onEvent": [], }; const mockNativeModule = { @@ -54,9 +54,9 @@ const mockNativeModule = { }, __clearListeners: () => { - mockListeners.onSuccess = []; - mockListeners.onExit = []; - mockListeners.onEvent = []; + mockListeners["PlaidLink.onSuccess"] = []; + mockListeners["PlaidLink.onExit"] = []; + mockListeners["PlaidLink.onEvent"] = []; }, __getListenerCount: (eventName: string) => { diff --git a/src/__tests__/createPlaidHeadlessSession.test.ts b/src/__tests__/createPlaidHeadlessSession.test.ts index 7b6f766d..0e6f37b5 100644 --- a/src/__tests__/createPlaidHeadlessSession.test.ts +++ b/src/__tests__/createPlaidHeadlessSession.test.ts @@ -67,7 +67,7 @@ describe("createPlaidHeadlessSession", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onSuccess", mockSuccess); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onSuccess", mockSuccess); expect(onSuccessMock).toHaveBeenCalledWith(mockSuccess); }); @@ -89,7 +89,7 @@ describe("createPlaidHeadlessSession", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onExit", mockExit); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onExit", mockExit); expect(onExitMock).toHaveBeenCalledWith(mockExit); }); @@ -114,7 +114,7 @@ describe("createPlaidHeadlessSession", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onEvent", mockEvent); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onEvent", mockEvent); expect(onEventMock).toHaveBeenCalledWith(mockEvent); }); @@ -166,11 +166,11 @@ describe("createPlaidHeadlessSession", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onSuccess", mockSuccess); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onSuccess", mockSuccess); expect(onSuccessMock).toHaveBeenCalledWith(mockSuccess); - (NativePlaidModule as any).__triggerEvent("onExit", {}); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onExit", {}); expect(onExitMock).not.toHaveBeenCalled(); }); @@ -194,11 +194,11 @@ describe("createPlaidHeadlessSession", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onExit", mockExit); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onExit", mockExit); expect(onExitMock).toHaveBeenCalledWith(mockExit); - (NativePlaidModule as any).__triggerEvent("onSuccess", {}); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onSuccess", {}); expect(onSuccessMock).not.toHaveBeenCalled(); }); diff --git a/src/__tests__/createPlaidLayerSession.test.ts b/src/__tests__/createPlaidLayerSession.test.ts index f4672031..762078c8 100644 --- a/src/__tests__/createPlaidLayerSession.test.ts +++ b/src/__tests__/createPlaidLayerSession.test.ts @@ -53,7 +53,7 @@ describe("createPlaidLayerSession", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onExit", mockExit); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onExit", mockExit); expect(onExitMock).toHaveBeenCalledWith(mockExit); }); @@ -78,7 +78,7 @@ describe("createPlaidLayerSession", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onEvent", mockEvent); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onEvent", mockEvent); expect(onEventMock).toHaveBeenCalledWith(mockEvent); }); @@ -145,11 +145,11 @@ describe("createPlaidLayerSession", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onSuccess", mockSuccess); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onSuccess", mockSuccess); expect(onSuccessMock).toHaveBeenCalledWith(mockSuccess); - (NativePlaidModule as any).__triggerEvent("onExit", {}); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onExit", {}); expect(onExitMock).not.toHaveBeenCalled(); }); diff --git a/src/__tests__/createPlaidLinkSession.test.ts b/src/__tests__/createPlaidLinkSession.test.ts index fb55383c..220ed98c 100644 --- a/src/__tests__/createPlaidLinkSession.test.ts +++ b/src/__tests__/createPlaidLinkSession.test.ts @@ -32,15 +32,15 @@ describe("createPlaidLinkSession", () => { expect(typeof session.open).toBe("function"); expect(NativePlaidModule.addListener).toHaveBeenCalledTimes(3); expect(NativePlaidModule.addListener).toHaveBeenCalledWith( - "onSuccess", + "PlaidLink.onSuccess", expect.any(Function) ); expect(NativePlaidModule.addListener).toHaveBeenCalledWith( - "onExit", + "PlaidLink.onExit", expect.any(Function) ); expect(NativePlaidModule.addListener).toHaveBeenCalledWith( - "onEvent", + "PlaidLink.onEvent", expect.any(Function) ); }); @@ -128,12 +128,12 @@ describe("createPlaidLinkSession", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onSuccess", mockSuccessData); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onSuccess", mockSuccessData); expect(onSuccessMock).toHaveBeenCalledWith(mockSuccessData); expect(onSuccessMock).toHaveBeenCalledTimes(1); - (NativePlaidModule as any).__triggerEvent("onExit", {}); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onExit", {}); expect(onExitMock).not.toHaveBeenCalled(); }); @@ -159,12 +159,12 @@ describe("createPlaidLinkSession", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onExit", mockExitData); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onExit", mockExitData); expect(onExitMock).toHaveBeenCalledWith(mockExitData); expect(onExitMock).toHaveBeenCalledTimes(1); - (NativePlaidModule as any).__triggerEvent("onSuccess", {}); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onSuccess", {}); expect(onSuccessMock).not.toHaveBeenCalled(); }); @@ -200,16 +200,16 @@ describe("createPlaidLinkSession", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onEvent", mockEvent1); - (NativePlaidModule as any).__triggerEvent("onEvent", mockEvent2); - (NativePlaidModule as any).__triggerEvent("onEvent", mockEvent1); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onEvent", mockEvent1); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onEvent", mockEvent2); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onEvent", mockEvent1); expect(onEventMock).toHaveBeenCalledTimes(3); expect(onEventMock).toHaveBeenCalledWith(mockEvent1); expect(onEventMock).toHaveBeenCalledWith(mockEvent2); expect( - (NativePlaidModule as any).__getListenerCount("onEvent") + (NativePlaidModule as any).__getListenerCount("PlaidLink.onEvent") ).toBeGreaterThan(0); }); diff --git a/src/__tests__/listener-lifecycle.test.ts b/src/__tests__/listener-lifecycle.test.ts index 8d41f41b..7b772115 100644 --- a/src/__tests__/listener-lifecycle.test.ts +++ b/src/__tests__/listener-lifecycle.test.ts @@ -26,13 +26,13 @@ describe("Listener Lifecycle", () => { await createPlaidLinkSession(config); expect( - (NativePlaidModule as any).__getListenerCount("onSuccess") + (NativePlaidModule as any).__getListenerCount("PlaidLink.onSuccess") ).toBeGreaterThan(0); expect( - (NativePlaidModule as any).__getListenerCount("onExit") + (NativePlaidModule as any).__getListenerCount("PlaidLink.onExit") ).toBeGreaterThan(0); expect( - (NativePlaidModule as any).__getListenerCount("onEvent") + (NativePlaidModule as any).__getListenerCount("PlaidLink.onEvent") ).toBeGreaterThan(0); const mockSuccess: LinkSuccess = { @@ -43,11 +43,11 @@ describe("Listener Lifecycle", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onSuccess", mockSuccess); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onSuccess", mockSuccess); - expect((NativePlaidModule as any).__getListenerCount("onSuccess")).toBe(0); - expect((NativePlaidModule as any).__getListenerCount("onExit")).toBe(0); - expect((NativePlaidModule as any).__getListenerCount("onEvent")).toBe(0); + expect((NativePlaidModule as any).__getListenerCount("PlaidLink.onSuccess")).toBe(0); + expect((NativePlaidModule as any).__getListenerCount("PlaidLink.onExit")).toBe(0); + expect((NativePlaidModule as any).__getListenerCount("PlaidLink.onEvent")).toBe(0); }); it("multiple session creations do not stack listeners", async () => { @@ -80,7 +80,7 @@ describe("Listener Lifecycle", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onSuccess", mockSuccess); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onSuccess", mockSuccess); expect(firstSuccess).not.toHaveBeenCalled(); expect(secondSuccess).toHaveBeenCalledTimes(1); @@ -111,12 +111,12 @@ describe("Listener Lifecycle", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onSuccess", mockSuccess); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onSuccess", mockSuccess); } - expect((NativePlaidModule as any).__getListenerCount("onSuccess")).toBe(0); - expect((NativePlaidModule as any).__getListenerCount("onExit")).toBe(0); - expect((NativePlaidModule as any).__getListenerCount("onEvent")).toBe(0); + expect((NativePlaidModule as any).__getListenerCount("PlaidLink.onSuccess")).toBe(0); + expect((NativePlaidModule as any).__getListenerCount("PlaidLink.onExit")).toBe(0); + expect((NativePlaidModule as any).__getListenerCount("PlaidLink.onEvent")).toBe(0); successCallbacks.forEach((callback, index) => { expect(callback).toHaveBeenCalledTimes(1); @@ -145,7 +145,7 @@ describe("Listener Lifecycle", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onSuccess", mockSuccess); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onSuccess", mockSuccess); expect(onSuccess).toHaveBeenCalledTimes(1); @@ -166,8 +166,8 @@ describe("Listener Lifecycle", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onExit", mockExit); - (NativePlaidModule as any).__triggerEvent("onEvent", mockEvent); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onExit", mockExit); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onEvent", mockEvent); expect(onExit).not.toHaveBeenCalled(); expect(onEvent).not.toHaveBeenCalled(); @@ -194,7 +194,7 @@ describe("Listener Lifecycle", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onExit", mockExit); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onExit", mockExit); expect(onExit).toHaveBeenCalledTimes(1); @@ -216,8 +216,8 @@ describe("Listener Lifecycle", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onSuccess", mockSuccess); - (NativePlaidModule as any).__triggerEvent("onEvent", mockEvent); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onSuccess", mockSuccess); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onEvent", mockEvent); expect(onSuccess).not.toHaveBeenCalled(); expect(onEvent).not.toHaveBeenCalled(); @@ -284,7 +284,7 @@ describe("Listener Lifecycle", () => { ]; events.forEach((event) => { - (NativePlaidModule as any).__triggerEvent("onEvent", event); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onEvent", event); }); expect(onEvent).toHaveBeenCalledTimes(5); @@ -293,7 +293,7 @@ describe("Listener Lifecycle", () => { }); expect( - (NativePlaidModule as any).__getListenerCount("onEvent") + (NativePlaidModule as any).__getListenerCount("PlaidLink.onEvent") ).toBeGreaterThan(0); }); @@ -319,11 +319,11 @@ describe("Listener Lifecycle", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onSuccess", mockSuccess); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onSuccess", mockSuccess); expect(onSuccess).toHaveBeenCalledTimes(1); - (NativePlaidModule as any).__triggerEvent("onExit", {}); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onExit", {}); expect(onExit).not.toHaveBeenCalled(); }); @@ -357,7 +357,7 @@ describe("Listener Lifecycle", () => { }, }; - (NativePlaidModule as any).__triggerEvent("onSuccess", mockSuccess); + (NativePlaidModule as any).__triggerEvent("PlaidLink.onSuccess", mockSuccess); expect(linkSuccess).not.toHaveBeenCalled(); expect(layerSuccess).toHaveBeenCalledTimes(1); diff --git a/src/index.ts b/src/index.ts index bd28b3cb..255ef9d4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,19 +36,19 @@ export async function createPlaidLinkSession( cleanupListeners(); successSub = NativePlaidModule.addListener( - "onSuccess", + "PlaidLink.onSuccess", (success: LinkSuccess) => { config.onSuccess(success); cleanupListeners(); } ); - exitSub = NativePlaidModule.addListener("onExit", (exit: LinkExit) => { + exitSub = NativePlaidModule.addListener("PlaidLink.onExit", (exit: LinkExit) => { config.onExit(exit); cleanupListeners(); }); - eventSub = NativePlaidModule.addListener("onEvent", (event: LinkEvent) => { + eventSub = NativePlaidModule.addListener("PlaidLink.onEvent", (event: LinkEvent) => { config.onEvent(event); }); @@ -81,7 +81,7 @@ export async function createPlaidLayerSession( ); successSub = NativePlaidModule.addListener( - "onSuccess", + "PlaidLink.onSuccess", (success: LinkSuccess) => { console.log("[PlaidLink] JS received onSuccess event"); config.onSuccess(success); @@ -89,13 +89,13 @@ export async function createPlaidLayerSession( } ); - exitSub = NativePlaidModule.addListener("onExit", (exit: LinkExit) => { + exitSub = NativePlaidModule.addListener("PlaidLink.onExit", (exit: LinkExit) => { console.log("[PlaidLink] JS received onExit event"); config.onExit?.(exit); cleanupListeners(); }); - eventSub = NativePlaidModule.addListener("onEvent", (event: LinkEvent) => { + eventSub = NativePlaidModule.addListener("PlaidLink.onEvent", (event: LinkEvent) => { console.log("[PlaidLink] JS received onEvent:", event.eventName); config.onEvent?.(event); }); @@ -136,7 +136,7 @@ export async function createPlaidHeadlessSession( ); successSub = NativePlaidModule.addListener( - "onSuccess", + "PlaidLink.onSuccess", (success: LinkSuccess) => { console.log("[PlaidLink] JS received onSuccess event"); config.onSuccess(success); @@ -144,13 +144,13 @@ export async function createPlaidHeadlessSession( } ); - exitSub = NativePlaidModule.addListener("onExit", (exit: LinkExit) => { + exitSub = NativePlaidModule.addListener("PlaidLink.onExit", (exit: LinkExit) => { console.log("[PlaidLink] JS received onExit event"); config.onExit(exit); cleanupListeners(); }); - eventSub = NativePlaidModule.addListener("onEvent", (event: LinkEvent) => { + eventSub = NativePlaidModule.addListener("PlaidLink.onEvent", (event: LinkEvent) => { console.log("[PlaidLink] JS received onEvent:", event.eventName); config.onEvent(event); }); From 3ee3efd6bfc85463761a92ae415d85d72fff3189 Mon Sep 17 00:00:00 2001 From: dtroupe Date: Mon, 30 Mar 2026 14:40:32 -0700 Subject: [PATCH 2/2] event names --- src/ReactNativePlaidLinkSdk.types.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ReactNativePlaidLinkSdk.types.ts b/src/ReactNativePlaidLinkSdk.types.ts index e0f83f32..e3b256e3 100644 --- a/src/ReactNativePlaidLinkSdk.types.ts +++ b/src/ReactNativePlaidLinkSdk.types.ts @@ -767,9 +767,9 @@ export enum LinkIOSPresentationStyle { } export type ReactNativePlaidLinkSdkModuleEvents = { - onSuccess: (success: LinkSuccess) => void; - onExit: (exit: LinkExit) => void; - onEvent: (event: LinkEvent) => void; + "PlaidLink.onSuccess": (success: LinkSuccess) => void; + "PlaidLink.onExit": (exit: LinkExit) => void; + "PlaidLink.onEvent": (event: LinkEvent) => void; }; export type LinkSuccessListener = (LinkSuccess: LinkSuccess) => void;