@bundleup/core 0.0.2 → 0.0.4
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.
- package/dist/client.d.mts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +20 -13
- package/dist/client.mjs +20 -13
- package/dist/server.js +11 -7
- package/dist/server.mjs +11 -7
- package/package.json +1 -1
package/dist/client.d.mts
CHANGED
|
@@ -3,6 +3,6 @@ interface AuthenticateWithPopupOptions {
|
|
|
3
3
|
height?: number;
|
|
4
4
|
debug?: boolean;
|
|
5
5
|
}
|
|
6
|
-
declare function authenticateWithPopup(token: string, options?: AuthenticateWithPopupOptions): Promise<
|
|
6
|
+
declare function authenticateWithPopup(token: string, options?: AuthenticateWithPopupOptions): Promise<Record<string, any>>;
|
|
7
7
|
|
|
8
8
|
export { AuthenticateWithPopupOptions, authenticateWithPopup };
|
package/dist/client.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ interface AuthenticateWithPopupOptions {
|
|
|
3
3
|
height?: number;
|
|
4
4
|
debug?: boolean;
|
|
5
5
|
}
|
|
6
|
-
declare function authenticateWithPopup(token: string, options?: AuthenticateWithPopupOptions): Promise<
|
|
6
|
+
declare function authenticateWithPopup(token: string, options?: AuthenticateWithPopupOptions): Promise<Record<string, any>>;
|
|
7
7
|
|
|
8
8
|
export { AuthenticateWithPopupOptions, authenticateWithPopup };
|
package/dist/client.js
CHANGED
|
@@ -45,6 +45,8 @@ function authenticateWithPopup(token, options = {}) {
|
|
|
45
45
|
}
|
|
46
46
|
const width = options?.width ?? 500;
|
|
47
47
|
const height = options?.height ?? 600;
|
|
48
|
+
const left = window.screenX + (window.outerWidth - width) / 2;
|
|
49
|
+
const top = window.screenY + (window.outerHeight - height) / 2.5;
|
|
48
50
|
const debug = options?.debug ?? false;
|
|
49
51
|
const client = isClient();
|
|
50
52
|
const log = logger(debug);
|
|
@@ -60,15 +62,15 @@ function authenticateWithPopup(token, options = {}) {
|
|
|
60
62
|
const popup = window.open(
|
|
61
63
|
`https://auth.bundleup.io/${token}`,
|
|
62
64
|
"bundleup-auth",
|
|
63
|
-
`width=${width},height=${height},scrollbars=yes,resizable=yes`
|
|
65
|
+
`width=${width},height=${height},left=${left},top=${top},scrollbars=yes,resizable=yes`
|
|
64
66
|
);
|
|
65
67
|
if (!popup) {
|
|
66
68
|
log("Failed to open popup window. Please check popup blocker settings.");
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"Failed to open popup window. Please check popup blocker settings."
|
|
70
|
-
)
|
|
69
|
+
const error = new Error(
|
|
70
|
+
"Failed to open popup window. Please check popup blocker settings."
|
|
71
71
|
);
|
|
72
|
+
error.name = "POPUP_BLOCKED";
|
|
73
|
+
return reject(error);
|
|
72
74
|
}
|
|
73
75
|
const handleMessage = (event) => {
|
|
74
76
|
if (event.origin !== "https://auth.bundleup.io") {
|
|
@@ -77,25 +79,28 @@ function authenticateWithPopup(token, options = {}) {
|
|
|
77
79
|
if (!event.data?.type) {
|
|
78
80
|
return;
|
|
79
81
|
}
|
|
80
|
-
log("Received authentication message", event.data);
|
|
81
82
|
cleanup();
|
|
82
83
|
popup.close();
|
|
83
|
-
if (event.data.type === "bundleup
|
|
84
|
+
if (event.data.type === "bundleup:success") {
|
|
84
85
|
log("Authentication successful");
|
|
85
|
-
return resolve();
|
|
86
|
+
return resolve(event.data.data);
|
|
86
87
|
}
|
|
87
|
-
if (event.data.type === "bundleup
|
|
88
|
-
log("Authentication failed", event.data.
|
|
89
|
-
|
|
88
|
+
if (event.data.type === "bundleup:error") {
|
|
89
|
+
log("Authentication failed", event.data.message);
|
|
90
|
+
const error = new Error(event.data.message || "Authentication failed");
|
|
91
|
+
error.name = event.data.code || "AUTHENTICATION_ERROR";
|
|
92
|
+
return reject(error);
|
|
90
93
|
}
|
|
91
94
|
};
|
|
92
95
|
const checkClosed = setInterval(() => {
|
|
93
96
|
if (!popup.closed) {
|
|
94
97
|
return;
|
|
95
98
|
}
|
|
99
|
+
const error = new Error("Authentication popup was closed by user");
|
|
100
|
+
error.name = "POPUP_CLOSED";
|
|
96
101
|
cleanup();
|
|
97
102
|
log("Authentication popup closed by user");
|
|
98
|
-
reject(
|
|
103
|
+
reject(error);
|
|
99
104
|
}, 1e3);
|
|
100
105
|
const cleanup = () => {
|
|
101
106
|
window.removeEventListener("message", handleMessage);
|
|
@@ -108,7 +113,9 @@ function authenticateWithPopup(token, options = {}) {
|
|
|
108
113
|
}
|
|
109
114
|
cleanup();
|
|
110
115
|
log("Authentication popup was blocked or closed immediately");
|
|
111
|
-
|
|
116
|
+
const error = new Error("Popup was blocked or closed immediately");
|
|
117
|
+
error.name = "POPUP_BLOCKED";
|
|
118
|
+
reject(error);
|
|
112
119
|
}, 100);
|
|
113
120
|
});
|
|
114
121
|
}
|
package/dist/client.mjs
CHANGED
|
@@ -11,6 +11,8 @@ function authenticateWithPopup(token, options = {}) {
|
|
|
11
11
|
}
|
|
12
12
|
const width = options?.width ?? 500;
|
|
13
13
|
const height = options?.height ?? 600;
|
|
14
|
+
const left = window.screenX + (window.outerWidth - width) / 2;
|
|
15
|
+
const top = window.screenY + (window.outerHeight - height) / 2.5;
|
|
14
16
|
const debug = options?.debug ?? false;
|
|
15
17
|
const client = isClient();
|
|
16
18
|
const log = logger(debug);
|
|
@@ -26,15 +28,15 @@ function authenticateWithPopup(token, options = {}) {
|
|
|
26
28
|
const popup = window.open(
|
|
27
29
|
`https://auth.bundleup.io/${token}`,
|
|
28
30
|
"bundleup-auth",
|
|
29
|
-
`width=${width},height=${height},scrollbars=yes,resizable=yes`
|
|
31
|
+
`width=${width},height=${height},left=${left},top=${top},scrollbars=yes,resizable=yes`
|
|
30
32
|
);
|
|
31
33
|
if (!popup) {
|
|
32
34
|
log("Failed to open popup window. Please check popup blocker settings.");
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"Failed to open popup window. Please check popup blocker settings."
|
|
36
|
-
)
|
|
35
|
+
const error = new Error(
|
|
36
|
+
"Failed to open popup window. Please check popup blocker settings."
|
|
37
37
|
);
|
|
38
|
+
error.name = "POPUP_BLOCKED";
|
|
39
|
+
return reject(error);
|
|
38
40
|
}
|
|
39
41
|
const handleMessage = (event) => {
|
|
40
42
|
if (event.origin !== "https://auth.bundleup.io") {
|
|
@@ -43,25 +45,28 @@ function authenticateWithPopup(token, options = {}) {
|
|
|
43
45
|
if (!event.data?.type) {
|
|
44
46
|
return;
|
|
45
47
|
}
|
|
46
|
-
log("Received authentication message", event.data);
|
|
47
48
|
cleanup();
|
|
48
49
|
popup.close();
|
|
49
|
-
if (event.data.type === "bundleup
|
|
50
|
+
if (event.data.type === "bundleup:success") {
|
|
50
51
|
log("Authentication successful");
|
|
51
|
-
return resolve();
|
|
52
|
+
return resolve(event.data.data);
|
|
52
53
|
}
|
|
53
|
-
if (event.data.type === "bundleup
|
|
54
|
-
log("Authentication failed", event.data.
|
|
55
|
-
|
|
54
|
+
if (event.data.type === "bundleup:error") {
|
|
55
|
+
log("Authentication failed", event.data.message);
|
|
56
|
+
const error = new Error(event.data.message || "Authentication failed");
|
|
57
|
+
error.name = event.data.code || "AUTHENTICATION_ERROR";
|
|
58
|
+
return reject(error);
|
|
56
59
|
}
|
|
57
60
|
};
|
|
58
61
|
const checkClosed = setInterval(() => {
|
|
59
62
|
if (!popup.closed) {
|
|
60
63
|
return;
|
|
61
64
|
}
|
|
65
|
+
const error = new Error("Authentication popup was closed by user");
|
|
66
|
+
error.name = "POPUP_CLOSED";
|
|
62
67
|
cleanup();
|
|
63
68
|
log("Authentication popup closed by user");
|
|
64
|
-
reject(
|
|
69
|
+
reject(error);
|
|
65
70
|
}, 1e3);
|
|
66
71
|
const cleanup = () => {
|
|
67
72
|
window.removeEventListener("message", handleMessage);
|
|
@@ -74,7 +79,9 @@ function authenticateWithPopup(token, options = {}) {
|
|
|
74
79
|
}
|
|
75
80
|
cleanup();
|
|
76
81
|
log("Authentication popup was blocked or closed immediately");
|
|
77
|
-
|
|
82
|
+
const error = new Error("Popup was blocked or closed immediately");
|
|
83
|
+
error.name = "POPUP_BLOCKED";
|
|
84
|
+
reject(error);
|
|
78
85
|
}, 100);
|
|
79
86
|
});
|
|
80
87
|
}
|
package/dist/server.js
CHANGED
|
@@ -49,7 +49,7 @@ var BundleUp = class {
|
|
|
49
49
|
return logger(!!this.config.debug)(message, ...args);
|
|
50
50
|
}
|
|
51
51
|
async createConnection(integrationId, options) {
|
|
52
|
-
this.log(`Creating connection for integration: ${integrationId}
|
|
52
|
+
this.log(`Creating connection for integration: ${integrationId}`);
|
|
53
53
|
if (!integrationId) {
|
|
54
54
|
this.log("Integration ID is missing");
|
|
55
55
|
throw new Error("Integration ID is required to create a connection");
|
|
@@ -63,18 +63,22 @@ var BundleUp = class {
|
|
|
63
63
|
},
|
|
64
64
|
body: JSON.stringify({
|
|
65
65
|
integrationId,
|
|
66
|
-
externalId: options.externalId
|
|
67
|
-
metadata: options.metadata
|
|
66
|
+
externalId: options.externalId || void 0,
|
|
67
|
+
metadata: options.metadata || {}
|
|
68
68
|
})
|
|
69
69
|
});
|
|
70
70
|
if (!response.ok) {
|
|
71
|
-
this.log(
|
|
72
|
-
|
|
71
|
+
this.log(
|
|
72
|
+
`Authentication request failed: ${response.status} ${response.statusText}`
|
|
73
|
+
);
|
|
74
|
+
throw new Error(
|
|
75
|
+
`Authentication request failed: ${response.status} ${response.statusText}`
|
|
76
|
+
);
|
|
73
77
|
}
|
|
74
78
|
const data = await response.json();
|
|
75
79
|
if (!data.token) {
|
|
76
|
-
this.log("Invalid response:
|
|
77
|
-
throw new Error("Invalid response:
|
|
80
|
+
this.log("Invalid response: could not create token", data);
|
|
81
|
+
throw new Error("Invalid response: could not create token");
|
|
78
82
|
}
|
|
79
83
|
this.log("Authentication token received successfully");
|
|
80
84
|
return data;
|
package/dist/server.mjs
CHANGED
|
@@ -17,7 +17,7 @@ var BundleUp = class {
|
|
|
17
17
|
return logger(!!this.config.debug)(message, ...args);
|
|
18
18
|
}
|
|
19
19
|
async createConnection(integrationId, options) {
|
|
20
|
-
this.log(`Creating connection for integration: ${integrationId}
|
|
20
|
+
this.log(`Creating connection for integration: ${integrationId}`);
|
|
21
21
|
if (!integrationId) {
|
|
22
22
|
this.log("Integration ID is missing");
|
|
23
23
|
throw new Error("Integration ID is required to create a connection");
|
|
@@ -31,18 +31,22 @@ var BundleUp = class {
|
|
|
31
31
|
},
|
|
32
32
|
body: JSON.stringify({
|
|
33
33
|
integrationId,
|
|
34
|
-
externalId: options.externalId
|
|
35
|
-
metadata: options.metadata
|
|
34
|
+
externalId: options.externalId || void 0,
|
|
35
|
+
metadata: options.metadata || {}
|
|
36
36
|
})
|
|
37
37
|
});
|
|
38
38
|
if (!response.ok) {
|
|
39
|
-
this.log(
|
|
40
|
-
|
|
39
|
+
this.log(
|
|
40
|
+
`Authentication request failed: ${response.status} ${response.statusText}`
|
|
41
|
+
);
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Authentication request failed: ${response.status} ${response.statusText}`
|
|
44
|
+
);
|
|
41
45
|
}
|
|
42
46
|
const data = await response.json();
|
|
43
47
|
if (!data.token) {
|
|
44
|
-
this.log("Invalid response:
|
|
45
|
-
throw new Error("Invalid response:
|
|
48
|
+
this.log("Invalid response: could not create token", data);
|
|
49
|
+
throw new Error("Invalid response: could not create token");
|
|
46
50
|
}
|
|
47
51
|
this.log("Authentication token received successfully");
|
|
48
52
|
return data;
|