oidc-client-rx
Version:
ReactiveX enhanced OIDC and OAuth2 protocol support for browser-based JavaScript applications
51 lines (50 loc) • 2.45 kB
JavaScript
import { inject } from "@outposts/injection-js";
import { DOCUMENT } from "../dom/index.js";
class AbstractRouter {
}
const ROUTER_ABS_PATH_PATTERN = /^\//;
class VanillaLocationRouter extends AbstractRouter {
get location() {
var _this_document_defaultView_window, _this_document_defaultView;
const location = null == (_this_document_defaultView = this.document.defaultView) ? void 0 : null == (_this_document_defaultView_window = _this_document_defaultView.window) ? void 0 : _this_document_defaultView_window.location;
if (!location) throw new Error('current document do not support Location API');
return location;
}
navigateByUrl(url) {
this.location.href = ROUTER_ABS_PATH_PATTERN.test(url) ? url : `/${url}`;
}
getCurrentNavigation() {
return {
extractedUrl: `${this.location.pathname}${this.location.search}${this.location.hash}`
};
}
constructor(...args){
super(...args), this.document = inject(DOCUMENT);
}
}
class VanillaHistoryRouter extends AbstractRouter {
get history() {
var _this_document_defaultView_window, _this_document_defaultView;
const history = null == (_this_document_defaultView = this.document.defaultView) ? void 0 : null == (_this_document_defaultView_window = _this_document_defaultView.window) ? void 0 : _this_document_defaultView_window.history;
if (!history) throw new Error('current document do not support History API');
return history;
}
get location() {
var _this_document_defaultView_window, _this_document_defaultView;
const location = null == (_this_document_defaultView = this.document.defaultView) ? void 0 : null == (_this_document_defaultView_window = _this_document_defaultView.window) ? void 0 : _this_document_defaultView_window.location;
if (!location) throw new Error('current document do not support Location API');
return location;
}
navigateByUrl(url) {
this.history.pushState({}, '', ROUTER_ABS_PATH_PATTERN.test(url) ? url : `/${url}`);
}
getCurrentNavigation() {
return {
extractedUrl: `${this.location.pathname}${this.location.search}${this.location.hash}`
};
}
constructor(...args){
super(...args), this.document = inject(DOCUMENT);
}
}
export { AbstractRouter, ROUTER_ABS_PATH_PATTERN, VanillaHistoryRouter, VanillaLocationRouter };