supertokens-website
Advanced tools
Comparing version 14.0.1 to 14.0.2
@@ -10,2 +10,9 @@ # Changelog | ||
## [14.0.2] - 2022-10-24 | ||
### Fixes | ||
- XMLHttpRequest event dispatching should now work in Safari. | ||
- A race-condition blocking XMLHttpRequests in Chrome is now fixed. | ||
## [14.0.1] - 2022-10-21 | ||
@@ -12,0 +19,0 @@ |
@@ -1,2 +0,2 @@ | ||
export declare const package_version = "14.0.1"; | ||
export declare const package_version = "14.0.2"; | ||
export declare const supported_fdi: string[]; |
@@ -18,3 +18,3 @@ "use strict"; | ||
*/ | ||
exports.package_version = "14.0.1"; | ||
exports.package_version = "14.0.2"; | ||
exports.supported_fdi = ["1.8", "1.9", "1.10", "1.11", "1.12", "1.13", "1.14", "1.15"]; |
@@ -154,3 +154,8 @@ "use strict"; | ||
var processState_1 = require("./processState"); | ||
var XHR_EVENTS = ["readystatechange", "abort", "error", "load", "loadend", "loadstart", "progress", "timeout"]; | ||
function addInterceptorsToXMLHttpRequest() { | ||
var firstEventLoopDone = false; | ||
setTimeout(function() { | ||
return (firstEventLoopDone = true); | ||
}, 0); | ||
var oldXMLHttpRequest = XMLHttpRequest; | ||
@@ -162,2 +167,12 @@ (0, logger_1.logDebugMessage)("addInterceptorsToXMLHttpRequest called"); | ||
var actual = new oldXMLHttpRequest(); | ||
var delayActualCalls = !firstEventLoopDone; | ||
function delayIfNecessary(cb) { | ||
if (delayActualCalls) { | ||
setTimeout(function() { | ||
cb(); | ||
}, 0); | ||
} else { | ||
cb(); | ||
} | ||
} | ||
var self = this; | ||
@@ -168,2 +183,3 @@ var listOfFunctionCallsInProxy = []; | ||
var customResponseHeaders; | ||
var eventHandlers = new Map(); | ||
// We define these during open | ||
@@ -183,8 +199,30 @@ // let method: string = ""; | ||
self.onloadend = null; | ||
var eventTarget = new EventTarget(); | ||
self.addEventListener = eventTarget.addEventListener.bind(eventTarget); | ||
self.removeEventListener = eventTarget.removeEventListener.bind(eventTarget); | ||
function redispatchEvent(ev) { | ||
(0, logger_1.logDebugMessage)("XHRInterceptor redispatching ".concat(ev.type)); | ||
eventTarget.dispatchEvent(new ev.constructor(ev.type, ev)); | ||
// TODO: add support for other event listener options | ||
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#parameters | ||
self.addEventListener = function(type, listener, _options) { | ||
var handlers = eventHandlers.get(type); | ||
if (handlers === undefined) { | ||
handlers = new Set(); | ||
eventHandlers.set(type, handlers); | ||
} | ||
handlers.add(listener); | ||
}; | ||
self.removeEventListener = function(type, listener) { | ||
var handlers = eventHandlers.get(type); | ||
if (handlers === undefined) { | ||
handlers = new Set(); | ||
eventHandlers.set(type, handlers); | ||
} | ||
handlers.delete(listener); | ||
}; | ||
function redispatchEvent(name, ev) { | ||
var handlers = eventHandlers.get(name); | ||
(0, logger_1.logDebugMessage)( | ||
"XHRInterceptor dispatching ".concat(ev.type, " to ").concat(handlers ? handlers.size : 0, " listeners") | ||
); | ||
if (handlers) { | ||
Array.from(handlers).forEach(function(handler) { | ||
return handler.apply(self, [ev]); | ||
}); | ||
} | ||
} | ||
@@ -237,3 +275,3 @@ function handleRetryPostRefreshing() { | ||
return __awaiter(this, void 0, void 0, function() { | ||
var status_1, headers, idRefreshToken, antiCsrfToken, tok, frontToken, err_1, resp, event_1; | ||
var status_1, headers, idRefreshToken, antiCsrfToken, tok, frontToken, err_1, resp; | ||
return __generator(this, function(_a) { | ||
@@ -358,4 +396,5 @@ switch (_a.label) { | ||
case 22: | ||
event_1 = new Event("error"); | ||
eventTarget.dispatchEvent(event_1); | ||
// Here we only need to handle fetch related errors, from the refresh endpoint called by the retry | ||
// So we should only get network level errors here | ||
redispatchEvent("error", new Event("error")); | ||
_a.label = 23; | ||
@@ -371,2 +410,3 @@ case 23: | ||
self.open = function(_, u) { | ||
(0, logger_1.logDebugMessage)("XHRInterceptor.open called"); | ||
var args = arguments; | ||
@@ -409,3 +449,5 @@ listOfFunctionCallsInProxy.push(function(xhr) { | ||
// can be passed by the user. | ||
actual.open.apply(actual, args); | ||
delayIfNecessary(function() { | ||
return actual.open.apply(actual, args); | ||
}); | ||
}; | ||
@@ -418,3 +460,5 @@ self.send = function(inputBody) { | ||
if (doNotDoInterception) { | ||
actual.setRequestHeader(name, value); | ||
delayIfNecessary(function() { | ||
return actual.setRequestHeader(name, value); | ||
}); | ||
return; | ||
@@ -432,3 +476,5 @@ } | ||
requestHeaders.push({ name: name, value: value }); | ||
actual.setRequestHeader(name, value); | ||
delayIfNecessary(function() { | ||
return actual.setRequestHeader(name, value); | ||
}); | ||
}; | ||
@@ -440,21 +486,14 @@ var copiedProps = undefined; | ||
var delayedEvents = ["load", "loadend", "readystatechange"]; | ||
var xhrEvents = [ | ||
"readystatechange", | ||
"abort", | ||
"error", | ||
"load", | ||
"loadend", | ||
"loadstart", | ||
"progress", | ||
"timeout" | ||
]; | ||
(0, logger_1.logDebugMessage)("XHRInterceptor.setUpXHR called"); | ||
var _loop_1 = function(name_1) { | ||
(0, logger_1.logDebugMessage)("XHRInterceptor added listener for event ".concat(name_1)); | ||
xhr.addEventListener(name_1, function(ev) { | ||
(0, logger_1.logDebugMessage)("XHRInterceptor got event ".concat(name_1)); | ||
if (!delayedEvents.includes(name_1)) { | ||
redispatchEvent(ev); | ||
redispatchEvent(name_1, ev); | ||
} | ||
}); | ||
}; | ||
for (var _i = 0, xhrEvents_1 = xhrEvents; _i < xhrEvents_1.length; _i++) { | ||
var name_1 = xhrEvents_1[_i]; | ||
for (var _i = 0, XHR_EVENTS_1 = XHR_EVENTS; _i < XHR_EVENTS_1.length; _i++) { | ||
var name_1 = XHR_EVENTS_1[_i]; | ||
_loop_1(name_1); | ||
@@ -473,3 +512,3 @@ } | ||
} | ||
redispatchEvent(ev); | ||
redispatchEvent("load", ev); | ||
}); | ||
@@ -479,3 +518,3 @@ }; | ||
// In local files, status is 0 upon success in Mozilla Firefox | ||
if (xhr.readyState === XMLHttpRequest.DONE) { | ||
if (xhr.readyState === oldXMLHttpRequest.DONE) { | ||
if (responseProcessed === undefined) { | ||
@@ -489,3 +528,3 @@ responseProcessed = handleResponse(xhr); | ||
if (self.onreadystatechange) self.onreadystatechange(ev); | ||
redispatchEvent(ev); | ||
redispatchEvent("readystatechange", ev); | ||
}); | ||
@@ -496,3 +535,3 @@ } else { | ||
} | ||
redispatchEvent(ev); | ||
redispatchEvent("readystatechange", ev); | ||
} | ||
@@ -511,3 +550,3 @@ }; | ||
} | ||
redispatchEvent(ev); | ||
redispatchEvent("loadend", ev); | ||
}); | ||
@@ -584,2 +623,3 @@ }; | ||
} | ||
(0, logger_1.logDebugMessage)("XHRInterceptor.set[".concat(prop, "] = ").concat(val)); | ||
xhr[prop] = val; | ||
@@ -596,2 +636,3 @@ } | ||
function sendXHR(xhr, body) { | ||
var _this = this; | ||
(0, logger_1.logDebugMessage)("XHRInterceptor.send: called"); | ||
@@ -601,3 +642,6 @@ (0, logger_1.logDebugMessage)("XHRInterceptor.send: Value of doNotDoInterception: " + doNotDoInterception); | ||
(0, logger_1.logDebugMessage)("XHRInterceptor.send: Returning without interception"); | ||
return xhr.send(body); | ||
delayIfNecessary(function() { | ||
return xhr.send(body); | ||
}); | ||
return; | ||
} | ||
@@ -608,4 +652,4 @@ (0, logger_1.logDebugMessage)("XHRInterceptor.send: Interception started"); | ||
); | ||
(function() { | ||
return __awaiter(this, void 0, void 0, function() { | ||
delayIfNecessary(function() { | ||
return __awaiter(_this, void 0, void 0, function() { | ||
var antiCsrfToken; | ||
@@ -651,3 +695,3 @@ return __generator(this, function(_a) { | ||
}); | ||
})(); | ||
}); | ||
} | ||
@@ -654,0 +698,0 @@ }; |
{ | ||
"name": "supertokens-website", | ||
"version": "14.0.1", | ||
"version": "14.0.2", | ||
"description": "frontend sdk for website to be used for auth solution.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
343829
6860