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