@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/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 }\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) {
|
|
@@ -3586,7 +3594,7 @@ var PopupHandler = /** @class */ (function () {
|
|
|
3586
3594
|
iframe.setAttribute("width", "600");
|
|
3587
3595
|
iframe.setAttribute("height", "600");
|
|
3588
3596
|
iframe.setAttribute("frameborder", "0");
|
|
3589
|
-
var dialogContent = document.querySelector("#".concat(
|
|
3597
|
+
var dialogContent = document.querySelector("#".concat(CONTENT_ID));
|
|
3590
3598
|
if (dialogContent) {
|
|
3591
3599
|
dialogContent.appendChild(iframe);
|
|
3592
3600
|
}
|
|
@@ -3601,29 +3609,28 @@ var PopupHandler = /** @class */ (function () {
|
|
|
3601
3609
|
return PopupHandler;
|
|
3602
3610
|
}());
|
|
3603
3611
|
|
|
3604
|
-
function
|
|
3605
|
-
var client = new
|
|
3612
|
+
function authsignalBrowser(publishableKey, options) {
|
|
3613
|
+
var client = new AuthsignalBrowser();
|
|
3606
3614
|
client.init(publishableKey, options);
|
|
3607
3615
|
return client;
|
|
3608
3616
|
}
|
|
3609
|
-
var
|
|
3610
|
-
function
|
|
3617
|
+
var AuthsignalBrowser = /** @class */ (function () {
|
|
3618
|
+
function AuthsignalBrowser() {
|
|
3611
3619
|
this.anonymousId = "";
|
|
3612
|
-
this.initialized = false;
|
|
3613
3620
|
this.publishableKey = "";
|
|
3614
3621
|
this.cookieDomain = "";
|
|
3615
3622
|
this.idCookieName = "";
|
|
3616
3623
|
this.trackingHost = "";
|
|
3617
3624
|
}
|
|
3618
|
-
|
|
3625
|
+
AuthsignalBrowser.prototype.init = function (publishableKey, options) {
|
|
3619
3626
|
return __awaiter(this, void 0, void 0, function () {
|
|
3620
3627
|
var _a, anonymousId, isGeneratedAnonymousId, agent, registerAnonymousIdRequest;
|
|
3621
3628
|
return __generator(this, function (_b) {
|
|
3622
3629
|
switch (_b.label) {
|
|
3623
3630
|
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.
|
|
3631
|
+
this.cookieDomain = (options === null || options === void 0 ? void 0 : options.cookieDomain) || getCookieDomain();
|
|
3632
|
+
this.idCookieName = (options === null || options === void 0 ? void 0 : options.cookieName) || "__as_aid";
|
|
3633
|
+
this.trackingHost = getHostWithProtocol((options === null || options === void 0 ? void 0 : options.trackingHost) || "t.authsignal.com");
|
|
3627
3634
|
_a = this;
|
|
3628
3635
|
return [4 /*yield*/, load({
|
|
3629
3636
|
monitoring: false
|
|
@@ -3647,14 +3654,12 @@ var AuthsignalClient = /** @class */ (function () {
|
|
|
3647
3654
|
case 3:
|
|
3648
3655
|
_b.sent();
|
|
3649
3656
|
_b.label = 4;
|
|
3650
|
-
case 4:
|
|
3651
|
-
this.initialized = true;
|
|
3652
|
-
return [2 /*return*/];
|
|
3657
|
+
case 4: return [2 /*return*/];
|
|
3653
3658
|
}
|
|
3654
3659
|
});
|
|
3655
3660
|
});
|
|
3656
3661
|
};
|
|
3657
|
-
|
|
3662
|
+
AuthsignalBrowser.prototype.identify = function (props) {
|
|
3658
3663
|
return __awaiter(this, void 0, void 0, function () {
|
|
3659
3664
|
var request;
|
|
3660
3665
|
return __generator(this, function (_a) {
|
|
@@ -3668,7 +3673,7 @@ var AuthsignalClient = /** @class */ (function () {
|
|
|
3668
3673
|
});
|
|
3669
3674
|
});
|
|
3670
3675
|
};
|
|
3671
|
-
|
|
3676
|
+
AuthsignalBrowser.prototype.getAnonymousId = function () {
|
|
3672
3677
|
var idCookie = getCookie(this.idCookieName);
|
|
3673
3678
|
if (idCookie) {
|
|
3674
3679
|
return { idCookie: idCookie, generated: false };
|
|
@@ -3677,29 +3682,34 @@ var AuthsignalClient = /** @class */ (function () {
|
|
|
3677
3682
|
setCookie("__as_aid", newId, Infinity, this.cookieDomain, document.location.protocol !== "http:");
|
|
3678
3683
|
return { idCookie: newId, generated: true };
|
|
3679
3684
|
};
|
|
3680
|
-
|
|
3681
|
-
var
|
|
3682
|
-
window.location.href =
|
|
3685
|
+
AuthsignalBrowser.prototype.mfa = function (_a) {
|
|
3686
|
+
var url = _a.url;
|
|
3687
|
+
window.location.href = url;
|
|
3683
3688
|
};
|
|
3684
|
-
|
|
3685
|
-
var challengeUrl = _a.challengeUrl;
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3689
|
+
AuthsignalBrowser.prototype.challenge = function (_a) {
|
|
3690
|
+
var challengeUrl = _a.challengeUrl, _b = _a.mode, mode = _b === void 0 ? "redirect" : _b;
|
|
3691
|
+
if (mode === "redirect") {
|
|
3692
|
+
window.location.href = challengeUrl;
|
|
3693
|
+
}
|
|
3694
|
+
else {
|
|
3695
|
+
var Popup_1 = new PopupHandler();
|
|
3696
|
+
Popup_1.show({ challengeUrl: challengeUrl });
|
|
3697
|
+
return new Promise(function (resolve, reject) {
|
|
3698
|
+
var handleChallenge = function (event) {
|
|
3699
|
+
if (event.data === "authsignal-challenge-success") {
|
|
3700
|
+
Popup_1.close();
|
|
3701
|
+
resolve(true);
|
|
3702
|
+
}
|
|
3703
|
+
else if (event.data === "authsignal-challenge-failure") {
|
|
3704
|
+
Popup_1.close();
|
|
3705
|
+
reject(false);
|
|
3706
|
+
}
|
|
3707
|
+
};
|
|
3708
|
+
window.addEventListener("message", handleChallenge, false);
|
|
3709
|
+
});
|
|
3710
|
+
}
|
|
3701
3711
|
};
|
|
3702
|
-
|
|
3712
|
+
AuthsignalBrowser.prototype.registerIdentity = function (request) {
|
|
3703
3713
|
return __awaiter(this, void 0, void 0, function () {
|
|
3704
3714
|
var result;
|
|
3705
3715
|
return __generator(this, function (_a) {
|
|
@@ -3714,7 +3724,7 @@ var AuthsignalClient = /** @class */ (function () {
|
|
|
3714
3724
|
});
|
|
3715
3725
|
});
|
|
3716
3726
|
};
|
|
3717
|
-
|
|
3727
|
+
AuthsignalBrowser.prototype.registerAnonymousId = function (request) {
|
|
3718
3728
|
return __awaiter(this, void 0, void 0, function () {
|
|
3719
3729
|
var result;
|
|
3720
3730
|
return __generator(this, function (_a) {
|
|
@@ -3729,7 +3739,7 @@ var AuthsignalClient = /** @class */ (function () {
|
|
|
3729
3739
|
});
|
|
3730
3740
|
});
|
|
3731
3741
|
};
|
|
3732
|
-
|
|
3742
|
+
AuthsignalBrowser.prototype.buildRegisterAnonymousIdRequest = function () {
|
|
3733
3743
|
var now = new Date();
|
|
3734
3744
|
return {
|
|
3735
3745
|
deviceFingerprint: this.deviceFingerprint || "",
|
|
@@ -3748,14 +3758,14 @@ var AuthsignalClient = /** @class */ (function () {
|
|
|
3748
3758
|
}
|
|
3749
3759
|
};
|
|
3750
3760
|
};
|
|
3751
|
-
|
|
3761
|
+
AuthsignalBrowser.prototype.sendJson = function (path, payload) {
|
|
3752
3762
|
var jsonString = JSON.stringify(payload);
|
|
3753
3763
|
var url = "".concat(this.trackingHost, "/api/v1/client/").concat(path, "?publishableKey=").concat(this.publishableKey);
|
|
3754
3764
|
// Think about encapsulating the payloads around a message contract
|
|
3755
3765
|
// SDK client versions, additional meta data
|
|
3756
3766
|
return this.xmlHttpReqTransport(url, jsonString);
|
|
3757
3767
|
};
|
|
3758
|
-
|
|
3768
|
+
AuthsignalBrowser.prototype.xmlHttpReqTransport = function (url, json) {
|
|
3759
3769
|
var req = new XMLHttpRequest();
|
|
3760
3770
|
return new Promise(function (resolve, reject) {
|
|
3761
3771
|
req.onerror = function () {
|
|
@@ -3772,9 +3782,9 @@ var AuthsignalClient = /** @class */ (function () {
|
|
|
3772
3782
|
req.send(json);
|
|
3773
3783
|
});
|
|
3774
3784
|
};
|
|
3775
|
-
return
|
|
3785
|
+
return AuthsignalBrowser;
|
|
3776
3786
|
}());
|
|
3777
3787
|
|
|
3778
|
-
exports.
|
|
3779
|
-
exports.
|
|
3788
|
+
exports.AuthsignalBrowser = AuthsignalBrowser;
|
|
3789
|
+
exports.authsignalBrowser = authsignalBrowser;
|
|
3780
3790
|
//# sourceMappingURL=index.js.map
|