@authsignal/browser 0.0.2 → 0.0.3
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/README.md +0 -37
- package/dist/cjs/index.js +68 -58
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +67 -57
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +18 -15
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -3534,40 +3534,48 @@ if (typeof document !== 'undefined') {
|
|
|
3534
3534
|
}
|
|
3535
3535
|
}
|
|
3536
3536
|
|
|
3537
|
-
var
|
|
3538
|
-
var
|
|
3537
|
+
var CONTAINER_ID = "__authsignal-popup-container";
|
|
3538
|
+
var CONTENT_ID = "__authsignal-popup-content";
|
|
3539
|
+
var OVERLAY_ID = "__authsignal-popup-overlay";
|
|
3540
|
+
var STYLE_ID = "__authsignal-popup-style";
|
|
3539
3541
|
var PopupHandler = /** @class */ (function () {
|
|
3540
3542
|
function PopupHandler() {
|
|
3541
3543
|
this.popup = null;
|
|
3542
|
-
if (document.querySelector("#".concat(
|
|
3544
|
+
if (document.querySelector("#".concat(CONTAINER_ID))) {
|
|
3543
3545
|
throw new Error("Multiple instances of Authsignal popup is not supported.");
|
|
3544
3546
|
}
|
|
3545
3547
|
this.create();
|
|
3546
3548
|
}
|
|
3547
3549
|
PopupHandler.prototype.create = function () {
|
|
3548
|
-
//
|
|
3550
|
+
// Create dialog container
|
|
3549
3551
|
var container = document.createElement("div");
|
|
3550
|
-
container.setAttribute("id",
|
|
3552
|
+
container.setAttribute("id", CONTAINER_ID);
|
|
3551
3553
|
container.setAttribute("aria-hidden", "true");
|
|
3552
|
-
|
|
3553
|
-
// Dialog overlay
|
|
3554
|
+
// Create dialog overlay
|
|
3554
3555
|
var overlay = document.createElement("div");
|
|
3555
|
-
overlay.setAttribute("
|
|
3556
|
+
overlay.setAttribute("id", OVERLAY_ID);
|
|
3556
3557
|
overlay.setAttribute("data-a11y-dialog-hide", "true");
|
|
3557
|
-
|
|
3558
|
-
// Dialog content
|
|
3558
|
+
// Create dialog content
|
|
3559
3559
|
var content = document.createElement("div");
|
|
3560
|
-
content.setAttribute("
|
|
3561
|
-
content.setAttribute("id", DIALOG_CONTENT_ID);
|
|
3562
|
-
container.appendChild(content);
|
|
3560
|
+
content.setAttribute("id", CONTENT_ID);
|
|
3563
3561
|
document.body.appendChild(container);
|
|
3562
|
+
// Create CSS for dialog
|
|
3563
|
+
var style = document.createElement("style");
|
|
3564
|
+
style.setAttribute("id", STYLE_ID);
|
|
3565
|
+
style.textContent = "\n #".concat(CONTAINER_ID, ",\n #").concat(OVERLAY_ID, " {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n }\n\n #").concat(CONTAINER_ID, " {\n z-index: 2;\n display: flex;\n }\n\n #").concat(CONTAINER_ID, "[aria-hidden='true'] {\n display: none;\n }\n\n #").concat(OVERLAY_ID, " {\n background-color: rgba(43, 46, 56, 0.9);\n }\n\n #").concat(CONTENT_ID, " {\n margin: auto;\n z-index: 2;\n position: relative;\n background-color: white;\n }\n ");
|
|
3566
|
+
// Attach the created elements
|
|
3567
|
+
document.head.insertAdjacentElement("beforeend", style);
|
|
3568
|
+
container.appendChild(overlay);
|
|
3569
|
+
container.appendChild(content);
|
|
3564
3570
|
this.popup = new A11yDialog(container);
|
|
3565
3571
|
this.popup.on("hide", this.destroy);
|
|
3566
3572
|
};
|
|
3567
3573
|
PopupHandler.prototype.destroy = function () {
|
|
3568
|
-
var dialogEl = document.querySelector("#".concat(
|
|
3569
|
-
|
|
3574
|
+
var dialogEl = document.querySelector("#".concat(CONTAINER_ID));
|
|
3575
|
+
var styleEl = document.querySelector("#".concat(STYLE_ID));
|
|
3576
|
+
if (dialogEl && styleEl) {
|
|
3570
3577
|
document.body.removeChild(dialogEl);
|
|
3578
|
+
document.head.removeChild(styleEl);
|
|
3571
3579
|
}
|
|
3572
3580
|
};
|
|
3573
3581
|
PopupHandler.prototype.show = function (_a) {
|
|
@@ -3582,7 +3590,7 @@ var PopupHandler = /** @class */ (function () {
|
|
|
3582
3590
|
iframe.setAttribute("width", "600");
|
|
3583
3591
|
iframe.setAttribute("height", "600");
|
|
3584
3592
|
iframe.setAttribute("frameborder", "0");
|
|
3585
|
-
var dialogContent = document.querySelector("#".concat(
|
|
3593
|
+
var dialogContent = document.querySelector("#".concat(CONTENT_ID));
|
|
3586
3594
|
if (dialogContent) {
|
|
3587
3595
|
dialogContent.appendChild(iframe);
|
|
3588
3596
|
}
|
|
@@ -3597,29 +3605,28 @@ var PopupHandler = /** @class */ (function () {
|
|
|
3597
3605
|
return PopupHandler;
|
|
3598
3606
|
}());
|
|
3599
3607
|
|
|
3600
|
-
function
|
|
3601
|
-
var client = new
|
|
3608
|
+
function authsignalBrowser(publishableKey, options) {
|
|
3609
|
+
var client = new AuthsignalBrowser();
|
|
3602
3610
|
client.init(publishableKey, options);
|
|
3603
3611
|
return client;
|
|
3604
3612
|
}
|
|
3605
|
-
var
|
|
3606
|
-
function
|
|
3613
|
+
var AuthsignalBrowser = /** @class */ (function () {
|
|
3614
|
+
function AuthsignalBrowser() {
|
|
3607
3615
|
this.anonymousId = "";
|
|
3608
|
-
this.initialized = false;
|
|
3609
3616
|
this.publishableKey = "";
|
|
3610
3617
|
this.cookieDomain = "";
|
|
3611
3618
|
this.idCookieName = "";
|
|
3612
3619
|
this.trackingHost = "";
|
|
3613
3620
|
}
|
|
3614
|
-
|
|
3621
|
+
AuthsignalBrowser.prototype.init = function (publishableKey, options) {
|
|
3615
3622
|
return __awaiter(this, void 0, void 0, function () {
|
|
3616
3623
|
var _a, anonymousId, isGeneratedAnonymousId, agent, registerAnonymousIdRequest;
|
|
3617
3624
|
return __generator(this, function (_b) {
|
|
3618
3625
|
switch (_b.label) {
|
|
3619
3626
|
case 0:
|
|
3620
|
-
this.cookieDomain = (options === null || options === void 0 ? void 0 : options.
|
|
3621
|
-
this.idCookieName = (options === null || options === void 0 ? void 0 : options.
|
|
3622
|
-
this.trackingHost = getHostWithProtocol((options === null || options === void 0 ? void 0 : options.
|
|
3627
|
+
this.cookieDomain = (options === null || options === void 0 ? void 0 : options.cookieDomain) || getCookieDomain();
|
|
3628
|
+
this.idCookieName = (options === null || options === void 0 ? void 0 : options.cookieName) || "__as_aid";
|
|
3629
|
+
this.trackingHost = getHostWithProtocol((options === null || options === void 0 ? void 0 : options.trackingHost) || "t.authsignal.com");
|
|
3623
3630
|
_a = this;
|
|
3624
3631
|
return [4 /*yield*/, load({
|
|
3625
3632
|
monitoring: false
|
|
@@ -3643,14 +3650,12 @@ var AuthsignalClient = /** @class */ (function () {
|
|
|
3643
3650
|
case 3:
|
|
3644
3651
|
_b.sent();
|
|
3645
3652
|
_b.label = 4;
|
|
3646
|
-
case 4:
|
|
3647
|
-
this.initialized = true;
|
|
3648
|
-
return [2 /*return*/];
|
|
3653
|
+
case 4: return [2 /*return*/];
|
|
3649
3654
|
}
|
|
3650
3655
|
});
|
|
3651
3656
|
});
|
|
3652
3657
|
};
|
|
3653
|
-
|
|
3658
|
+
AuthsignalBrowser.prototype.identify = function (props) {
|
|
3654
3659
|
return __awaiter(this, void 0, void 0, function () {
|
|
3655
3660
|
var request;
|
|
3656
3661
|
return __generator(this, function (_a) {
|
|
@@ -3664,7 +3669,7 @@ var AuthsignalClient = /** @class */ (function () {
|
|
|
3664
3669
|
});
|
|
3665
3670
|
});
|
|
3666
3671
|
};
|
|
3667
|
-
|
|
3672
|
+
AuthsignalBrowser.prototype.getAnonymousId = function () {
|
|
3668
3673
|
var idCookie = getCookie(this.idCookieName);
|
|
3669
3674
|
if (idCookie) {
|
|
3670
3675
|
return { idCookie: idCookie, generated: false };
|
|
@@ -3673,29 +3678,34 @@ var AuthsignalClient = /** @class */ (function () {
|
|
|
3673
3678
|
setCookie("__as_aid", newId, Infinity, this.cookieDomain, document.location.protocol !== "http:");
|
|
3674
3679
|
return { idCookie: newId, generated: true };
|
|
3675
3680
|
};
|
|
3676
|
-
|
|
3677
|
-
var
|
|
3678
|
-
window.location.href =
|
|
3681
|
+
AuthsignalBrowser.prototype.mfa = function (_a) {
|
|
3682
|
+
var url = _a.url;
|
|
3683
|
+
window.location.href = url;
|
|
3679
3684
|
};
|
|
3680
|
-
|
|
3681
|
-
var challengeUrl = _a.challengeUrl;
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3685
|
+
AuthsignalBrowser.prototype.challenge = function (_a) {
|
|
3686
|
+
var challengeUrl = _a.challengeUrl, _b = _a.mode, mode = _b === void 0 ? "redirect" : _b;
|
|
3687
|
+
if (mode === "redirect") {
|
|
3688
|
+
window.location.href = challengeUrl;
|
|
3689
|
+
}
|
|
3690
|
+
else {
|
|
3691
|
+
var Popup_1 = new PopupHandler();
|
|
3692
|
+
Popup_1.show({ challengeUrl: challengeUrl });
|
|
3693
|
+
return new Promise(function (resolve, reject) {
|
|
3694
|
+
var handleChallenge = function (event) {
|
|
3695
|
+
if (event.data === "authsignal-challenge-success") {
|
|
3696
|
+
Popup_1.close();
|
|
3697
|
+
resolve(true);
|
|
3698
|
+
}
|
|
3699
|
+
else if (event.data === "authsignal-challenge-failure") {
|
|
3700
|
+
Popup_1.close();
|
|
3701
|
+
reject(false);
|
|
3702
|
+
}
|
|
3703
|
+
};
|
|
3704
|
+
window.addEventListener("message", handleChallenge, false);
|
|
3705
|
+
});
|
|
3706
|
+
}
|
|
3697
3707
|
};
|
|
3698
|
-
|
|
3708
|
+
AuthsignalBrowser.prototype.registerIdentity = function (request) {
|
|
3699
3709
|
return __awaiter(this, void 0, void 0, function () {
|
|
3700
3710
|
var result;
|
|
3701
3711
|
return __generator(this, function (_a) {
|
|
@@ -3710,7 +3720,7 @@ var AuthsignalClient = /** @class */ (function () {
|
|
|
3710
3720
|
});
|
|
3711
3721
|
});
|
|
3712
3722
|
};
|
|
3713
|
-
|
|
3723
|
+
AuthsignalBrowser.prototype.registerAnonymousId = function (request) {
|
|
3714
3724
|
return __awaiter(this, void 0, void 0, function () {
|
|
3715
3725
|
var result;
|
|
3716
3726
|
return __generator(this, function (_a) {
|
|
@@ -3725,7 +3735,7 @@ var AuthsignalClient = /** @class */ (function () {
|
|
|
3725
3735
|
});
|
|
3726
3736
|
});
|
|
3727
3737
|
};
|
|
3728
|
-
|
|
3738
|
+
AuthsignalBrowser.prototype.buildRegisterAnonymousIdRequest = function () {
|
|
3729
3739
|
var now = new Date();
|
|
3730
3740
|
return {
|
|
3731
3741
|
deviceFingerprint: this.deviceFingerprint || "",
|
|
@@ -3744,14 +3754,14 @@ var AuthsignalClient = /** @class */ (function () {
|
|
|
3744
3754
|
}
|
|
3745
3755
|
};
|
|
3746
3756
|
};
|
|
3747
|
-
|
|
3757
|
+
AuthsignalBrowser.prototype.sendJson = function (path, payload) {
|
|
3748
3758
|
var jsonString = JSON.stringify(payload);
|
|
3749
3759
|
var url = "".concat(this.trackingHost, "/api/v1/client/").concat(path, "?publishableKey=").concat(this.publishableKey);
|
|
3750
3760
|
// Think about encapsulating the payloads around a message contract
|
|
3751
3761
|
// SDK client versions, additional meta data
|
|
3752
3762
|
return this.xmlHttpReqTransport(url, jsonString);
|
|
3753
3763
|
};
|
|
3754
|
-
|
|
3764
|
+
AuthsignalBrowser.prototype.xmlHttpReqTransport = function (url, json) {
|
|
3755
3765
|
var req = new XMLHttpRequest();
|
|
3756
3766
|
return new Promise(function (resolve, reject) {
|
|
3757
3767
|
req.onerror = function () {
|
|
@@ -3768,8 +3778,8 @@ var AuthsignalClient = /** @class */ (function () {
|
|
|
3768
3778
|
req.send(json);
|
|
3769
3779
|
});
|
|
3770
3780
|
};
|
|
3771
|
-
return
|
|
3781
|
+
return AuthsignalBrowser;
|
|
3772
3782
|
}());
|
|
3773
3783
|
|
|
3774
|
-
export {
|
|
3784
|
+
export { AuthsignalBrowser, authsignalBrowser };
|
|
3775
3785
|
//# sourceMappingURL=index.js.map
|