@bundleup/core 0.0.3 → 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.js +13 -7
- package/dist/client.mjs +13 -7
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -66,11 +66,11 @@ function authenticateWithPopup(token, options = {}) {
|
|
|
66
66
|
);
|
|
67
67
|
if (!popup) {
|
|
68
68
|
log("Failed to open popup window. Please check popup blocker settings.");
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"Failed to open popup window. Please check popup blocker settings."
|
|
72
|
-
)
|
|
69
|
+
const error = new Error(
|
|
70
|
+
"Failed to open popup window. Please check popup blocker settings."
|
|
73
71
|
);
|
|
72
|
+
error.name = "POPUP_BLOCKED";
|
|
73
|
+
return reject(error);
|
|
74
74
|
}
|
|
75
75
|
const handleMessage = (event) => {
|
|
76
76
|
if (event.origin !== "https://auth.bundleup.io") {
|
|
@@ -87,16 +87,20 @@ function authenticateWithPopup(token, options = {}) {
|
|
|
87
87
|
}
|
|
88
88
|
if (event.data.type === "bundleup:error") {
|
|
89
89
|
log("Authentication failed", event.data.message);
|
|
90
|
-
|
|
90
|
+
const error = new Error(event.data.message || "Authentication failed");
|
|
91
|
+
error.name = event.data.code || "AUTHENTICATION_ERROR";
|
|
92
|
+
return reject(error);
|
|
91
93
|
}
|
|
92
94
|
};
|
|
93
95
|
const checkClosed = setInterval(() => {
|
|
94
96
|
if (!popup.closed) {
|
|
95
97
|
return;
|
|
96
98
|
}
|
|
99
|
+
const error = new Error("Authentication popup was closed by user");
|
|
100
|
+
error.name = "POPUP_CLOSED";
|
|
97
101
|
cleanup();
|
|
98
102
|
log("Authentication popup closed by user");
|
|
99
|
-
reject(
|
|
103
|
+
reject(error);
|
|
100
104
|
}, 1e3);
|
|
101
105
|
const cleanup = () => {
|
|
102
106
|
window.removeEventListener("message", handleMessage);
|
|
@@ -109,7 +113,9 @@ function authenticateWithPopup(token, options = {}) {
|
|
|
109
113
|
}
|
|
110
114
|
cleanup();
|
|
111
115
|
log("Authentication popup was blocked or closed immediately");
|
|
112
|
-
|
|
116
|
+
const error = new Error("Popup was blocked or closed immediately");
|
|
117
|
+
error.name = "POPUP_BLOCKED";
|
|
118
|
+
reject(error);
|
|
113
119
|
}, 100);
|
|
114
120
|
});
|
|
115
121
|
}
|
package/dist/client.mjs
CHANGED
|
@@ -32,11 +32,11 @@ function authenticateWithPopup(token, options = {}) {
|
|
|
32
32
|
);
|
|
33
33
|
if (!popup) {
|
|
34
34
|
log("Failed to open popup window. Please check popup blocker settings.");
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"Failed to open popup window. Please check popup blocker settings."
|
|
38
|
-
)
|
|
35
|
+
const error = new Error(
|
|
36
|
+
"Failed to open popup window. Please check popup blocker settings."
|
|
39
37
|
);
|
|
38
|
+
error.name = "POPUP_BLOCKED";
|
|
39
|
+
return reject(error);
|
|
40
40
|
}
|
|
41
41
|
const handleMessage = (event) => {
|
|
42
42
|
if (event.origin !== "https://auth.bundleup.io") {
|
|
@@ -53,16 +53,20 @@ function authenticateWithPopup(token, options = {}) {
|
|
|
53
53
|
}
|
|
54
54
|
if (event.data.type === "bundleup:error") {
|
|
55
55
|
log("Authentication failed", event.data.message);
|
|
56
|
-
|
|
56
|
+
const error = new Error(event.data.message || "Authentication failed");
|
|
57
|
+
error.name = event.data.code || "AUTHENTICATION_ERROR";
|
|
58
|
+
return reject(error);
|
|
57
59
|
}
|
|
58
60
|
};
|
|
59
61
|
const checkClosed = setInterval(() => {
|
|
60
62
|
if (!popup.closed) {
|
|
61
63
|
return;
|
|
62
64
|
}
|
|
65
|
+
const error = new Error("Authentication popup was closed by user");
|
|
66
|
+
error.name = "POPUP_CLOSED";
|
|
63
67
|
cleanup();
|
|
64
68
|
log("Authentication popup closed by user");
|
|
65
|
-
reject(
|
|
69
|
+
reject(error);
|
|
66
70
|
}, 1e3);
|
|
67
71
|
const cleanup = () => {
|
|
68
72
|
window.removeEventListener("message", handleMessage);
|
|
@@ -75,7 +79,9 @@ function authenticateWithPopup(token, options = {}) {
|
|
|
75
79
|
}
|
|
76
80
|
cleanup();
|
|
77
81
|
log("Authentication popup was blocked or closed immediately");
|
|
78
|
-
|
|
82
|
+
const error = new Error("Popup was blocked or closed immediately");
|
|
83
|
+
error.name = "POPUP_BLOCKED";
|
|
84
|
+
reject(error);
|
|
79
85
|
}, 100);
|
|
80
86
|
});
|
|
81
87
|
}
|