Skip to content

Commit b281e80

Browse files
Adding onCancel and onClose callbacks (#16904)
* Adding onCancel and onClose callbacks * Fixing it up
1 parent b903cea commit b281e80

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-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 receives a
10+
`ConnectStatus` object with `successful` and `completed` boolean properties
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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ type ConnectResult = {
7070
id: string;
7171
};
7272

73+
/**
74+
* The status when the Connect dialog is closed.
75+
*/
76+
type ConnectStatus = {
77+
/**
78+
* Whether the connection was successful (account was connected).
79+
*/
80+
successful: boolean;
81+
/**
82+
* Whether the connection process was completed (vs user closing early).
83+
*/
84+
completed: boolean;
85+
};
86+
7387
/**
7488
* Custom error class for handling connection errors.
7589
*/
@@ -109,6 +123,13 @@ type StartConnectOpts = {
109123
* @param err - The error that occurred during the connection.
110124
*/
111125
onError?: (err: ConnectError) => void;
126+
127+
/**
128+
* Callback function to be called when the Connect iFrame is closed.
129+
*
130+
* @param status - The status of the connection when closed.
131+
*/
132+
onClose?: (status: ConnectStatus) => void;
112133
};
113134

114135
/**
@@ -223,22 +244,37 @@ export class BrowserClient extends BaseClient {
223244
* onError: (err) => {
224245
* console.error("Connection error:", err);
225246
* },
247+
* onClose: (status) => {
248+
* if (!status.successful) {
249+
* console.log("User closed without connecting");
250+
* }
251+
* },
226252
* });
227253
* ```
228254
*/
229255
public async connectAccount(opts: StartConnectOpts) {
256+
let connectionSuccessful = false;
257+
let connectionCompleted = false;
258+
230259
const onMessage = (e: MessageEvent) => {
231260
switch (e.data?.type) {
232261
case "success":
262+
connectionSuccessful = true;
263+
connectionCompleted = true;
233264
opts.onSuccess?.({
234265
id: e.data?.authProvisionId,
235266
});
236267
break;
237268
case "error":
269+
connectionCompleted = true;
238270
opts.onError?.(new ConnectError(e.data.error));
239271
break;
240272
case "close":
241273
this.cleanup(onMessage);
274+
opts.onClose?.({
275+
successful: connectionSuccessful,
276+
completed: connectionCompleted,
277+
});
242278
break;
243279
default:
244280
break;

0 commit comments

Comments
 (0)