Skip to content

Commit e27566f

Browse files
Adding onCancel and onClose callbacks
1 parent b903cea commit e27566f

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

packages/sdk/CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
# Changelog
44

5+
## [1.6.4] - 2025-05-30
6+
7+
### Added
8+
9+
- Added `onClose` callback to `connectAccount` method that fires whenever the Connect iFrame is closed (success or cancel)
10+
- Added `onCancel` callback to `connectAccount` method that fires when the Connect iFrame is closed without successfully connecting
11+
512
## [1.6.3] - 2025-05-20b
613

714
### Added
@@ -61,8 +68,8 @@
6168

6269
### Added
6370

64-
- PD_SDK_DEBUG env var. Set it to true to enable debugging of Pipedream Connect
65-
API requests. Simple sanitization is performed to prevent sensitive field leakage
71+
- PD_SDK_DEBUG env var. Set it to true to enable debugging of Pipedream Connect
72+
API requests. Simple sanitization is performed to prevent sensitive field leakage
6673
but use caution.
6774

6875
## [1.5.1] - 2025-04-15

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@pipedream/sdk",
33
"type": "module",
4-
"version": "1.6.3",
4+
"version": "1.6.4",
55
"description": "Pipedream SDK",
66
"main": "./dist/server.js",
77
"module": "./dist/server.js",

packages/sdk/src/browser/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ type StartConnectOpts = {
109109
* @param err - The error that occurred during the connection.
110110
*/
111111
onError?: (err: ConnectError) => void;
112+
113+
/**
114+
* Callback function to be called when the Connect iFrame is closed.
115+
*/
116+
onClose?: () => void;
117+
118+
/**
119+
* Callback function to be called when the user cancels/closes the Connect
120+
* iFrame without successfully connecting an account.
121+
*/
122+
onCancel?: () => void;
112123
};
113124

114125
/**
@@ -223,13 +234,22 @@ export class BrowserClient extends BaseClient {
223234
* onError: (err) => {
224235
* console.error("Connection error:", err);
225236
* },
237+
* onClose: () => {
238+
* console.log("Connect iFrame closed");
239+
* },
240+
* onCancel: () => {
241+
* console.log("User cancelled without connecting");
242+
* },
226243
* });
227244
* ```
228245
*/
229246
public async connectAccount(opts: StartConnectOpts) {
247+
let connectionSuccessful = false;
248+
230249
const onMessage = (e: MessageEvent) => {
231250
switch (e.data?.type) {
232251
case "success":
252+
connectionSuccessful = true;
233253
opts.onSuccess?.({
234254
id: e.data?.authProvisionId,
235255
});
@@ -239,6 +259,11 @@ export class BrowserClient extends BaseClient {
239259
break;
240260
case "close":
241261
this.cleanup(onMessage);
262+
opts.onClose?.();
263+
// Call onCancel if the connection wasn't successful
264+
if (!connectionSuccessful) {
265+
opts.onCancel?.();
266+
}
242267
break;
243268
default:
244269
break;

0 commit comments

Comments
 (0)