@stytch/vanilla-js 5.10.2 → 5.10.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/CHANGELOG.md +8 -0
- package/dist/adminPortal/index.esm.js +1 -1
- package/dist/adminPortal/index.js +1 -1
- package/dist/b2b/StytchB2BHeadlessClient.d.ts +2 -1
- package/dist/b2b/index.esm.js +3 -3
- package/dist/b2b/index.headless.esm.js +4 -3
- package/dist/b2b/index.headless.js +3 -2
- package/dist/b2b/index.js +2 -2
- package/dist/{extractErrorMessage-C3sgO9Ia.js → extractErrorMessage-BknCxzwo.js} +1 -1
- package/dist/{extractErrorMessage-BThIxj3y.js → extractErrorMessage-OC-PmjS9.js} +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.headless.esm.js +91 -90
- package/dist/index.headless.js +91 -90
- package/dist/index.js +1 -1
- package/dist/{internal-Bq-MGoJK.js → internal-BYc78wap.js} +103 -49
- package/dist/{internal-DhpbqDn_.js → internal-vZlpQSCD.js} +103 -50
- package/package.json +2 -2
|
@@ -365,9 +365,12 @@ var NoCurrentSessionError = /*#__PURE__*/function (_StytchSDKError) {
|
|
|
365
365
|
}(StytchSDKError);
|
|
366
366
|
var InternalError = /*#__PURE__*/function (_StytchSDKError2) {
|
|
367
367
|
_inherits$1(InternalError, _StytchSDKError2);
|
|
368
|
-
function InternalError(
|
|
368
|
+
function InternalError(error) {
|
|
369
|
+
var _this9;
|
|
369
370
|
_classCallCheck$1(this, InternalError);
|
|
370
|
-
|
|
371
|
+
_this9 = _callSuper$1(this, InternalError, [error.name ? error.name : 'Internal Error', error.message ? error.message : 'An internal error has occurred. Please contact Stytch if this occurs.']);
|
|
372
|
+
_this9.nativeStack = error.nativeStackAndroid || error.nativeStackIOS;
|
|
373
|
+
return _this9;
|
|
371
374
|
}
|
|
372
375
|
return _createClass$1(InternalError);
|
|
373
376
|
}(StytchSDKError);
|
|
@@ -613,8 +616,6 @@ var SignInWithAppleMisconfigured = /*#__PURE__*/function (_StytchSDKError32) {
|
|
|
613
616
|
}(StytchSDKError);
|
|
614
617
|
function errorToStytchError(error) {
|
|
615
618
|
switch (error.message) {
|
|
616
|
-
case 'internal_error':
|
|
617
|
-
return new InternalError(error.message);
|
|
618
619
|
case 'no_current_session':
|
|
619
620
|
return new NoCurrentSessionError();
|
|
620
621
|
case 'no_biometrics_registration':
|
|
@@ -688,7 +689,7 @@ function errorToStytchError(error) {
|
|
|
688
689
|
case 'signinwithapple_misconfigured':
|
|
689
690
|
return new SignInWithAppleMisconfigured();
|
|
690
691
|
default:
|
|
691
|
-
return new
|
|
692
|
+
return new InternalError(error);
|
|
692
693
|
}
|
|
693
694
|
}
|
|
694
695
|
exports.B2BProducts = void 0;
|
|
@@ -5376,6 +5377,58 @@ var HeadlessB2BRBACClient = /*#__PURE__*/function () {
|
|
|
5376
5377
|
}]);
|
|
5377
5378
|
return HeadlessB2BRBACClient;
|
|
5378
5379
|
}();
|
|
5380
|
+
var HeadlessB2BImpersonationClient = /*#__PURE__*/_createClass(function HeadlessB2BImpersonationClient(_networkClient, _subscriptionService, dfpProtectedAuth) {
|
|
5381
|
+
var _this23 = this;
|
|
5382
|
+
_classCallCheck(this, HeadlessB2BImpersonationClient);
|
|
5383
|
+
this._networkClient = _networkClient;
|
|
5384
|
+
this._subscriptionService = _subscriptionService;
|
|
5385
|
+
this.dfpProtectedAuth = dfpProtectedAuth;
|
|
5386
|
+
this.authenticate = function (data) {
|
|
5387
|
+
return __awaiter$1(_this23, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee140() {
|
|
5388
|
+
var _yield$this$dfpProtec43, dfp_telemetry_id, captcha_token, resp;
|
|
5389
|
+
return _regeneratorRuntime().wrap(function _callee140$(_context140) {
|
|
5390
|
+
while (1) switch (_context140.prev = _context140.next) {
|
|
5391
|
+
case 0:
|
|
5392
|
+
validate('stytch.impersonation.authenticate').isString('token', data.token);
|
|
5393
|
+
_context140.next = 3;
|
|
5394
|
+
return this.dfpProtectedAuth.getDFPTelemetryIDAndCaptcha();
|
|
5395
|
+
case 3:
|
|
5396
|
+
_yield$this$dfpProtec43 = _context140.sent;
|
|
5397
|
+
dfp_telemetry_id = _yield$this$dfpProtec43.dfp_telemetry_id;
|
|
5398
|
+
captcha_token = _yield$this$dfpProtec43.captcha_token;
|
|
5399
|
+
_context140.next = 8;
|
|
5400
|
+
return this._networkClient.retriableFetchSDK({
|
|
5401
|
+
url: '/b2b/impersonation/authenticate',
|
|
5402
|
+
body: Object.assign(Object.assign({}, data), {
|
|
5403
|
+
dfp_telemetry_id: dfp_telemetry_id,
|
|
5404
|
+
captcha_token: captcha_token
|
|
5405
|
+
}),
|
|
5406
|
+
method: 'POST',
|
|
5407
|
+
retryCallback: this.dfpProtectedAuth.retryWithCaptchaAndDFP
|
|
5408
|
+
});
|
|
5409
|
+
case 8:
|
|
5410
|
+
resp = _context140.sent;
|
|
5411
|
+
if (resp.member_session) {
|
|
5412
|
+
this._subscriptionService.updateStateAndTokens({
|
|
5413
|
+
state: {
|
|
5414
|
+
session: resp.member_session,
|
|
5415
|
+
member: resp.member,
|
|
5416
|
+
organization: resp.organization
|
|
5417
|
+
},
|
|
5418
|
+
session_token: resp.session_token,
|
|
5419
|
+
session_jwt: resp.session_jwt,
|
|
5420
|
+
intermediate_session_token: null
|
|
5421
|
+
});
|
|
5422
|
+
}
|
|
5423
|
+
return _context140.abrupt("return", resp);
|
|
5424
|
+
case 11:
|
|
5425
|
+
case "end":
|
|
5426
|
+
return _context140.stop();
|
|
5427
|
+
}
|
|
5428
|
+
}, _callee140, this);
|
|
5429
|
+
}));
|
|
5430
|
+
};
|
|
5431
|
+
});
|
|
5379
5432
|
var IframeHostClient = /*#__PURE__*/function () {
|
|
5380
5433
|
function IframeHostClient(iframeURL) {
|
|
5381
5434
|
_classCallCheck(this, IframeHostClient);
|
|
@@ -5413,18 +5466,18 @@ var IframeHostClient = /*#__PURE__*/function () {
|
|
|
5413
5466
|
}, {
|
|
5414
5467
|
key: "call",
|
|
5415
5468
|
value: function call(method, args) {
|
|
5416
|
-
return __awaiter$1(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
5417
|
-
var
|
|
5469
|
+
return __awaiter$1(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee141() {
|
|
5470
|
+
var _this24 = this;
|
|
5418
5471
|
var frame, channel;
|
|
5419
|
-
return _regeneratorRuntime().wrap(function
|
|
5420
|
-
while (1) switch (
|
|
5472
|
+
return _regeneratorRuntime().wrap(function _callee141$(_context141) {
|
|
5473
|
+
while (1) switch (_context141.prev = _context141.next) {
|
|
5421
5474
|
case 0:
|
|
5422
|
-
|
|
5475
|
+
_context141.next = 2;
|
|
5423
5476
|
return this.frame;
|
|
5424
5477
|
case 2:
|
|
5425
|
-
frame =
|
|
5478
|
+
frame = _context141.sent;
|
|
5426
5479
|
channel = new MessageChannel();
|
|
5427
|
-
return
|
|
5480
|
+
return _context141.abrupt("return", new Promise(function (resolve, reject) {
|
|
5428
5481
|
var _a;
|
|
5429
5482
|
channel.port1.onmessage = function (event) {
|
|
5430
5483
|
var resp = event.data;
|
|
@@ -5439,13 +5492,13 @@ var IframeHostClient = /*#__PURE__*/function () {
|
|
|
5439
5492
|
method: method,
|
|
5440
5493
|
args: args
|
|
5441
5494
|
};
|
|
5442
|
-
(_a = frame.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(message,
|
|
5495
|
+
(_a = frame.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(message, _this24.iframeURL, [channel.port2]);
|
|
5443
5496
|
}));
|
|
5444
5497
|
case 5:
|
|
5445
5498
|
case "end":
|
|
5446
|
-
return
|
|
5499
|
+
return _context141.stop();
|
|
5447
5500
|
}
|
|
5448
|
-
},
|
|
5501
|
+
}, _callee141, this);
|
|
5449
5502
|
}));
|
|
5450
5503
|
}
|
|
5451
5504
|
}]);
|
|
@@ -5460,11 +5513,11 @@ var SearchDataManager = /*#__PURE__*/function () {
|
|
|
5460
5513
|
_createClass(SearchDataManager, [{
|
|
5461
5514
|
key: "searchUser",
|
|
5462
5515
|
value: function searchUser(email) {
|
|
5463
|
-
var
|
|
5516
|
+
var _this26 = this;
|
|
5464
5517
|
return this.dfpProtectedAuth.getDFPTelemetryIDAndCaptcha().then(function (_ref7) {
|
|
5465
5518
|
var dfp_telemetry_id = _ref7.dfp_telemetry_id,
|
|
5466
5519
|
captcha_token = _ref7.captcha_token;
|
|
5467
|
-
return
|
|
5520
|
+
return _this26._networkClient.fetchSDK({
|
|
5468
5521
|
url: "/users/search",
|
|
5469
5522
|
method: 'POST',
|
|
5470
5523
|
body: {
|
|
@@ -5495,52 +5548,52 @@ var shouldTryRefresh = function shouldTryRefresh(state) {
|
|
|
5495
5548
|
};
|
|
5496
5549
|
var SessionManager = /*#__PURE__*/function () {
|
|
5497
5550
|
function SessionManager(_subscriptionService, _headlessSessionClient) {
|
|
5498
|
-
var
|
|
5551
|
+
var _this27 = this;
|
|
5499
5552
|
_classCallCheck(this, SessionManager);
|
|
5500
5553
|
this._subscriptionService = _subscriptionService;
|
|
5501
5554
|
this._headlessSessionClient = _headlessSessionClient;
|
|
5502
5555
|
this._onDataChange = function (state) {
|
|
5503
5556
|
if (shouldTryRefresh(state)) {
|
|
5504
|
-
|
|
5557
|
+
_this27.scheduleBackgroundRefresh();
|
|
5505
5558
|
} else {
|
|
5506
|
-
|
|
5559
|
+
_this27.cancelBackgroundRefresh();
|
|
5507
5560
|
}
|
|
5508
5561
|
};
|
|
5509
5562
|
this._reauthenticateWithBackoff = function () {
|
|
5510
|
-
return __awaiter$1(
|
|
5563
|
+
return __awaiter$1(_this27, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee143() {
|
|
5511
5564
|
var count;
|
|
5512
|
-
return _regeneratorRuntime().wrap(function
|
|
5513
|
-
while (1) switch (
|
|
5565
|
+
return _regeneratorRuntime().wrap(function _callee143$(_context143) {
|
|
5566
|
+
while (1) switch (_context143.prev = _context143.next) {
|
|
5514
5567
|
case 0:
|
|
5515
5568
|
count = 0;
|
|
5516
5569
|
case 1:
|
|
5517
|
-
|
|
5518
|
-
|
|
5570
|
+
_context143.prev = 2;
|
|
5571
|
+
_context143.next = 5;
|
|
5519
5572
|
return this._headlessSessionClient.authenticate();
|
|
5520
5573
|
case 5:
|
|
5521
|
-
return
|
|
5574
|
+
return _context143.abrupt("return", _context143.sent);
|
|
5522
5575
|
case 8:
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
if (!SessionManager.isUnrecoverableError(
|
|
5526
|
-
|
|
5576
|
+
_context143.prev = 8;
|
|
5577
|
+
_context143.t0 = _context143["catch"](2);
|
|
5578
|
+
if (!SessionManager.isUnrecoverableError(_context143.t0)) {
|
|
5579
|
+
_context143.next = 12;
|
|
5527
5580
|
break;
|
|
5528
5581
|
}
|
|
5529
|
-
return
|
|
5582
|
+
return _context143.abrupt("return", Promise.reject(_context143.t0));
|
|
5530
5583
|
case 12:
|
|
5531
5584
|
count++;
|
|
5532
|
-
|
|
5585
|
+
_context143.next = 15;
|
|
5533
5586
|
return new Promise(function (done) {
|
|
5534
5587
|
return setTimeout(done, SessionManager.timeoutForAttempt(count));
|
|
5535
5588
|
});
|
|
5536
5589
|
case 15:
|
|
5537
|
-
|
|
5590
|
+
_context143.next = 1;
|
|
5538
5591
|
break;
|
|
5539
5592
|
case 17:
|
|
5540
5593
|
case "end":
|
|
5541
|
-
return
|
|
5594
|
+
return _context143.stop();
|
|
5542
5595
|
}
|
|
5543
|
-
},
|
|
5596
|
+
}, _callee143, this, [[2, 8]]);
|
|
5544
5597
|
}));
|
|
5545
5598
|
};
|
|
5546
5599
|
this.timeout = null;
|
|
@@ -5549,23 +5602,23 @@ var SessionManager = /*#__PURE__*/function () {
|
|
|
5549
5602
|
_createClass(SessionManager, [{
|
|
5550
5603
|
key: "performBackgroundRefresh",
|
|
5551
5604
|
value: function performBackgroundRefresh() {
|
|
5552
|
-
var
|
|
5605
|
+
var _this28 = this;
|
|
5553
5606
|
this._reauthenticateWithBackoff().then(function () {
|
|
5554
|
-
|
|
5607
|
+
_this28.scheduleBackgroundRefresh();
|
|
5555
5608
|
})["catch"](function (error) {
|
|
5556
5609
|
logger.warn('Session background refresh failed. Signalling to app that user is logged out.', {
|
|
5557
5610
|
error: error
|
|
5558
5611
|
});
|
|
5559
|
-
|
|
5612
|
+
_this28._subscriptionService.destroySession();
|
|
5560
5613
|
});
|
|
5561
5614
|
}
|
|
5562
5615
|
}, {
|
|
5563
5616
|
key: "scheduleBackgroundRefresh",
|
|
5564
5617
|
value: function scheduleBackgroundRefresh() {
|
|
5565
|
-
var
|
|
5618
|
+
var _this29 = this;
|
|
5566
5619
|
this.cancelBackgroundRefresh();
|
|
5567
5620
|
this.timeout = setTimeout(function () {
|
|
5568
|
-
|
|
5621
|
+
_this29.performBackgroundRefresh();
|
|
5569
5622
|
}, SessionManager.REFRESH_INTERVAL_MS);
|
|
5570
5623
|
}
|
|
5571
5624
|
}, {
|
|
@@ -5594,34 +5647,34 @@ var SessionManager = /*#__PURE__*/function () {
|
|
|
5594
5647
|
}();
|
|
5595
5648
|
SessionManager.REFRESH_INTERVAL_MS = 1000 * 60 * 3;
|
|
5596
5649
|
var StateChangeClient = /*#__PURE__*/_createClass(function StateChangeClient(_subscriptionService, emptyState) {
|
|
5597
|
-
var
|
|
5650
|
+
var _this30 = this;
|
|
5598
5651
|
_classCallCheck(this, StateChangeClient);
|
|
5599
5652
|
this._subscriptionService = _subscriptionService;
|
|
5600
5653
|
this.emptyState = emptyState;
|
|
5601
5654
|
this.onStateChange = function (callback) {
|
|
5602
|
-
return
|
|
5603
|
-
callback(state !== null && state !== void 0 ? state :
|
|
5655
|
+
return _this30._subscriptionService.subscribeToState(function (state) {
|
|
5656
|
+
callback(state !== null && state !== void 0 ? state : _this30.emptyState);
|
|
5604
5657
|
});
|
|
5605
5658
|
};
|
|
5606
5659
|
});
|
|
5607
5660
|
var WILDCARD_ACTION = '*';
|
|
5608
5661
|
var RBACPolicy = /*#__PURE__*/function () {
|
|
5609
5662
|
function RBACPolicy(roles, resources) {
|
|
5610
|
-
var
|
|
5663
|
+
var _this36 = this;
|
|
5611
5664
|
_classCallCheck(this, RBACPolicy);
|
|
5612
5665
|
this.roles = roles;
|
|
5613
5666
|
this.resources = resources;
|
|
5614
5667
|
this.rolesByID = {};
|
|
5615
5668
|
roles.forEach(function (role) {
|
|
5616
|
-
return
|
|
5669
|
+
return _this36.rolesByID[role.role_id] = role;
|
|
5617
5670
|
});
|
|
5618
5671
|
}
|
|
5619
5672
|
_createClass(RBACPolicy, [{
|
|
5620
5673
|
key: "callerIsAuthorized",
|
|
5621
5674
|
value: function callerIsAuthorized(memberRoles, resourceId, action) {
|
|
5622
|
-
var
|
|
5675
|
+
var _this37 = this;
|
|
5623
5676
|
return !!memberRoles.map(function (roleId) {
|
|
5624
|
-
return
|
|
5677
|
+
return _this37.rolesByID[roleId];
|
|
5625
5678
|
}).filter(function (v) {
|
|
5626
5679
|
return v;
|
|
5627
5680
|
}).flatMap(function (role) {
|
|
@@ -5635,12 +5688,12 @@ var RBACPolicy = /*#__PURE__*/function () {
|
|
|
5635
5688
|
}, {
|
|
5636
5689
|
key: "allPermissionsForCaller",
|
|
5637
5690
|
value: function allPermissionsForCaller(memberRoles) {
|
|
5638
|
-
var
|
|
5691
|
+
var _this38 = this;
|
|
5639
5692
|
var allPermsMap = Object.create(null);
|
|
5640
5693
|
this.resources.forEach(function (resource) {
|
|
5641
5694
|
allPermsMap[resource.resource_id] = {};
|
|
5642
5695
|
resource.actions.forEach(function (action) {
|
|
5643
|
-
allPermsMap[resource.resource_id][action] =
|
|
5696
|
+
allPermsMap[resource.resource_id][action] = _this38.callerIsAuthorized(memberRoles, resource.resource_id, action);
|
|
5644
5697
|
});
|
|
5645
5698
|
});
|
|
5646
5699
|
return allPermsMap;
|
|
@@ -5790,6 +5843,7 @@ exports.FailedToDecryptDataError = FailedToDecryptDataError;
|
|
|
5790
5843
|
exports.GOOGLE_ONE_TAP_HOST = GOOGLE_ONE_TAP_HOST;
|
|
5791
5844
|
exports.GOOGLE_ONE_TAP_SCRIPT_URL = GOOGLE_ONE_TAP_SCRIPT_URL;
|
|
5792
5845
|
exports.HeadlessB2BDiscoveryClient = HeadlessB2BDiscoveryClient;
|
|
5846
|
+
exports.HeadlessB2BImpersonationClient = HeadlessB2BImpersonationClient;
|
|
5793
5847
|
exports.HeadlessB2BMagicLinksClient = HeadlessB2BMagicLinksClient;
|
|
5794
5848
|
exports.HeadlessB2BOAuthClient = HeadlessB2BOAuthClient$1;
|
|
5795
5849
|
exports.HeadlessB2BOTPsClient = HeadlessB2BOTPsClient;
|
|
@@ -363,9 +363,12 @@ var NoCurrentSessionError = /*#__PURE__*/function (_StytchSDKError) {
|
|
|
363
363
|
}(StytchSDKError);
|
|
364
364
|
var InternalError = /*#__PURE__*/function (_StytchSDKError2) {
|
|
365
365
|
_inherits$1(InternalError, _StytchSDKError2);
|
|
366
|
-
function InternalError(
|
|
366
|
+
function InternalError(error) {
|
|
367
|
+
var _this9;
|
|
367
368
|
_classCallCheck$1(this, InternalError);
|
|
368
|
-
|
|
369
|
+
_this9 = _callSuper$1(this, InternalError, [error.name ? error.name : 'Internal Error', error.message ? error.message : 'An internal error has occurred. Please contact Stytch if this occurs.']);
|
|
370
|
+
_this9.nativeStack = error.nativeStackAndroid || error.nativeStackIOS;
|
|
371
|
+
return _this9;
|
|
369
372
|
}
|
|
370
373
|
return _createClass$1(InternalError);
|
|
371
374
|
}(StytchSDKError);
|
|
@@ -611,8 +614,6 @@ var SignInWithAppleMisconfigured = /*#__PURE__*/function (_StytchSDKError32) {
|
|
|
611
614
|
}(StytchSDKError);
|
|
612
615
|
function errorToStytchError(error) {
|
|
613
616
|
switch (error.message) {
|
|
614
|
-
case 'internal_error':
|
|
615
|
-
return new InternalError(error.message);
|
|
616
617
|
case 'no_current_session':
|
|
617
618
|
return new NoCurrentSessionError();
|
|
618
619
|
case 'no_biometrics_registration':
|
|
@@ -686,7 +687,7 @@ function errorToStytchError(error) {
|
|
|
686
687
|
case 'signinwithapple_misconfigured':
|
|
687
688
|
return new SignInWithAppleMisconfigured();
|
|
688
689
|
default:
|
|
689
|
-
return new
|
|
690
|
+
return new InternalError(error);
|
|
690
691
|
}
|
|
691
692
|
}
|
|
692
693
|
var B2BProducts;
|
|
@@ -5374,6 +5375,58 @@ var HeadlessB2BRBACClient = /*#__PURE__*/function () {
|
|
|
5374
5375
|
}]);
|
|
5375
5376
|
return HeadlessB2BRBACClient;
|
|
5376
5377
|
}();
|
|
5378
|
+
var HeadlessB2BImpersonationClient = /*#__PURE__*/_createClass(function HeadlessB2BImpersonationClient(_networkClient, _subscriptionService, dfpProtectedAuth) {
|
|
5379
|
+
var _this23 = this;
|
|
5380
|
+
_classCallCheck(this, HeadlessB2BImpersonationClient);
|
|
5381
|
+
this._networkClient = _networkClient;
|
|
5382
|
+
this._subscriptionService = _subscriptionService;
|
|
5383
|
+
this.dfpProtectedAuth = dfpProtectedAuth;
|
|
5384
|
+
this.authenticate = function (data) {
|
|
5385
|
+
return __awaiter$1(_this23, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee140() {
|
|
5386
|
+
var _yield$this$dfpProtec43, dfp_telemetry_id, captcha_token, resp;
|
|
5387
|
+
return _regeneratorRuntime().wrap(function _callee140$(_context140) {
|
|
5388
|
+
while (1) switch (_context140.prev = _context140.next) {
|
|
5389
|
+
case 0:
|
|
5390
|
+
validate('stytch.impersonation.authenticate').isString('token', data.token);
|
|
5391
|
+
_context140.next = 3;
|
|
5392
|
+
return this.dfpProtectedAuth.getDFPTelemetryIDAndCaptcha();
|
|
5393
|
+
case 3:
|
|
5394
|
+
_yield$this$dfpProtec43 = _context140.sent;
|
|
5395
|
+
dfp_telemetry_id = _yield$this$dfpProtec43.dfp_telemetry_id;
|
|
5396
|
+
captcha_token = _yield$this$dfpProtec43.captcha_token;
|
|
5397
|
+
_context140.next = 8;
|
|
5398
|
+
return this._networkClient.retriableFetchSDK({
|
|
5399
|
+
url: '/b2b/impersonation/authenticate',
|
|
5400
|
+
body: Object.assign(Object.assign({}, data), {
|
|
5401
|
+
dfp_telemetry_id: dfp_telemetry_id,
|
|
5402
|
+
captcha_token: captcha_token
|
|
5403
|
+
}),
|
|
5404
|
+
method: 'POST',
|
|
5405
|
+
retryCallback: this.dfpProtectedAuth.retryWithCaptchaAndDFP
|
|
5406
|
+
});
|
|
5407
|
+
case 8:
|
|
5408
|
+
resp = _context140.sent;
|
|
5409
|
+
if (resp.member_session) {
|
|
5410
|
+
this._subscriptionService.updateStateAndTokens({
|
|
5411
|
+
state: {
|
|
5412
|
+
session: resp.member_session,
|
|
5413
|
+
member: resp.member,
|
|
5414
|
+
organization: resp.organization
|
|
5415
|
+
},
|
|
5416
|
+
session_token: resp.session_token,
|
|
5417
|
+
session_jwt: resp.session_jwt,
|
|
5418
|
+
intermediate_session_token: null
|
|
5419
|
+
});
|
|
5420
|
+
}
|
|
5421
|
+
return _context140.abrupt("return", resp);
|
|
5422
|
+
case 11:
|
|
5423
|
+
case "end":
|
|
5424
|
+
return _context140.stop();
|
|
5425
|
+
}
|
|
5426
|
+
}, _callee140, this);
|
|
5427
|
+
}));
|
|
5428
|
+
};
|
|
5429
|
+
});
|
|
5377
5430
|
var IframeHostClient = /*#__PURE__*/function () {
|
|
5378
5431
|
function IframeHostClient(iframeURL) {
|
|
5379
5432
|
_classCallCheck(this, IframeHostClient);
|
|
@@ -5411,18 +5464,18 @@ var IframeHostClient = /*#__PURE__*/function () {
|
|
|
5411
5464
|
}, {
|
|
5412
5465
|
key: "call",
|
|
5413
5466
|
value: function call(method, args) {
|
|
5414
|
-
return __awaiter$1(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
5415
|
-
var
|
|
5467
|
+
return __awaiter$1(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee141() {
|
|
5468
|
+
var _this24 = this;
|
|
5416
5469
|
var frame, channel;
|
|
5417
|
-
return _regeneratorRuntime().wrap(function
|
|
5418
|
-
while (1) switch (
|
|
5470
|
+
return _regeneratorRuntime().wrap(function _callee141$(_context141) {
|
|
5471
|
+
while (1) switch (_context141.prev = _context141.next) {
|
|
5419
5472
|
case 0:
|
|
5420
|
-
|
|
5473
|
+
_context141.next = 2;
|
|
5421
5474
|
return this.frame;
|
|
5422
5475
|
case 2:
|
|
5423
|
-
frame =
|
|
5476
|
+
frame = _context141.sent;
|
|
5424
5477
|
channel = new MessageChannel();
|
|
5425
|
-
return
|
|
5478
|
+
return _context141.abrupt("return", new Promise(function (resolve, reject) {
|
|
5426
5479
|
var _a;
|
|
5427
5480
|
channel.port1.onmessage = function (event) {
|
|
5428
5481
|
var resp = event.data;
|
|
@@ -5437,13 +5490,13 @@ var IframeHostClient = /*#__PURE__*/function () {
|
|
|
5437
5490
|
method: method,
|
|
5438
5491
|
args: args
|
|
5439
5492
|
};
|
|
5440
|
-
(_a = frame.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(message,
|
|
5493
|
+
(_a = frame.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(message, _this24.iframeURL, [channel.port2]);
|
|
5441
5494
|
}));
|
|
5442
5495
|
case 5:
|
|
5443
5496
|
case "end":
|
|
5444
|
-
return
|
|
5497
|
+
return _context141.stop();
|
|
5445
5498
|
}
|
|
5446
|
-
},
|
|
5499
|
+
}, _callee141, this);
|
|
5447
5500
|
}));
|
|
5448
5501
|
}
|
|
5449
5502
|
}]);
|
|
@@ -5458,11 +5511,11 @@ var SearchDataManager = /*#__PURE__*/function () {
|
|
|
5458
5511
|
_createClass(SearchDataManager, [{
|
|
5459
5512
|
key: "searchUser",
|
|
5460
5513
|
value: function searchUser(email) {
|
|
5461
|
-
var
|
|
5514
|
+
var _this26 = this;
|
|
5462
5515
|
return this.dfpProtectedAuth.getDFPTelemetryIDAndCaptcha().then(function (_ref7) {
|
|
5463
5516
|
var dfp_telemetry_id = _ref7.dfp_telemetry_id,
|
|
5464
5517
|
captcha_token = _ref7.captcha_token;
|
|
5465
|
-
return
|
|
5518
|
+
return _this26._networkClient.fetchSDK({
|
|
5466
5519
|
url: "/users/search",
|
|
5467
5520
|
method: 'POST',
|
|
5468
5521
|
body: {
|
|
@@ -5493,52 +5546,52 @@ var shouldTryRefresh = function shouldTryRefresh(state) {
|
|
|
5493
5546
|
};
|
|
5494
5547
|
var SessionManager = /*#__PURE__*/function () {
|
|
5495
5548
|
function SessionManager(_subscriptionService, _headlessSessionClient) {
|
|
5496
|
-
var
|
|
5549
|
+
var _this27 = this;
|
|
5497
5550
|
_classCallCheck(this, SessionManager);
|
|
5498
5551
|
this._subscriptionService = _subscriptionService;
|
|
5499
5552
|
this._headlessSessionClient = _headlessSessionClient;
|
|
5500
5553
|
this._onDataChange = function (state) {
|
|
5501
5554
|
if (shouldTryRefresh(state)) {
|
|
5502
|
-
|
|
5555
|
+
_this27.scheduleBackgroundRefresh();
|
|
5503
5556
|
} else {
|
|
5504
|
-
|
|
5557
|
+
_this27.cancelBackgroundRefresh();
|
|
5505
5558
|
}
|
|
5506
5559
|
};
|
|
5507
5560
|
this._reauthenticateWithBackoff = function () {
|
|
5508
|
-
return __awaiter$1(
|
|
5561
|
+
return __awaiter$1(_this27, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee143() {
|
|
5509
5562
|
var count;
|
|
5510
|
-
return _regeneratorRuntime().wrap(function
|
|
5511
|
-
while (1) switch (
|
|
5563
|
+
return _regeneratorRuntime().wrap(function _callee143$(_context143) {
|
|
5564
|
+
while (1) switch (_context143.prev = _context143.next) {
|
|
5512
5565
|
case 0:
|
|
5513
5566
|
count = 0;
|
|
5514
5567
|
case 1:
|
|
5515
|
-
|
|
5516
|
-
|
|
5568
|
+
_context143.prev = 2;
|
|
5569
|
+
_context143.next = 5;
|
|
5517
5570
|
return this._headlessSessionClient.authenticate();
|
|
5518
5571
|
case 5:
|
|
5519
|
-
return
|
|
5572
|
+
return _context143.abrupt("return", _context143.sent);
|
|
5520
5573
|
case 8:
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
if (!SessionManager.isUnrecoverableError(
|
|
5524
|
-
|
|
5574
|
+
_context143.prev = 8;
|
|
5575
|
+
_context143.t0 = _context143["catch"](2);
|
|
5576
|
+
if (!SessionManager.isUnrecoverableError(_context143.t0)) {
|
|
5577
|
+
_context143.next = 12;
|
|
5525
5578
|
break;
|
|
5526
5579
|
}
|
|
5527
|
-
return
|
|
5580
|
+
return _context143.abrupt("return", Promise.reject(_context143.t0));
|
|
5528
5581
|
case 12:
|
|
5529
5582
|
count++;
|
|
5530
|
-
|
|
5583
|
+
_context143.next = 15;
|
|
5531
5584
|
return new Promise(function (done) {
|
|
5532
5585
|
return setTimeout(done, SessionManager.timeoutForAttempt(count));
|
|
5533
5586
|
});
|
|
5534
5587
|
case 15:
|
|
5535
|
-
|
|
5588
|
+
_context143.next = 1;
|
|
5536
5589
|
break;
|
|
5537
5590
|
case 17:
|
|
5538
5591
|
case "end":
|
|
5539
|
-
return
|
|
5592
|
+
return _context143.stop();
|
|
5540
5593
|
}
|
|
5541
|
-
},
|
|
5594
|
+
}, _callee143, this, [[2, 8]]);
|
|
5542
5595
|
}));
|
|
5543
5596
|
};
|
|
5544
5597
|
this.timeout = null;
|
|
@@ -5547,23 +5600,23 @@ var SessionManager = /*#__PURE__*/function () {
|
|
|
5547
5600
|
_createClass(SessionManager, [{
|
|
5548
5601
|
key: "performBackgroundRefresh",
|
|
5549
5602
|
value: function performBackgroundRefresh() {
|
|
5550
|
-
var
|
|
5603
|
+
var _this28 = this;
|
|
5551
5604
|
this._reauthenticateWithBackoff().then(function () {
|
|
5552
|
-
|
|
5605
|
+
_this28.scheduleBackgroundRefresh();
|
|
5553
5606
|
})["catch"](function (error) {
|
|
5554
5607
|
logger.warn('Session background refresh failed. Signalling to app that user is logged out.', {
|
|
5555
5608
|
error: error
|
|
5556
5609
|
});
|
|
5557
|
-
|
|
5610
|
+
_this28._subscriptionService.destroySession();
|
|
5558
5611
|
});
|
|
5559
5612
|
}
|
|
5560
5613
|
}, {
|
|
5561
5614
|
key: "scheduleBackgroundRefresh",
|
|
5562
5615
|
value: function scheduleBackgroundRefresh() {
|
|
5563
|
-
var
|
|
5616
|
+
var _this29 = this;
|
|
5564
5617
|
this.cancelBackgroundRefresh();
|
|
5565
5618
|
this.timeout = setTimeout(function () {
|
|
5566
|
-
|
|
5619
|
+
_this29.performBackgroundRefresh();
|
|
5567
5620
|
}, SessionManager.REFRESH_INTERVAL_MS);
|
|
5568
5621
|
}
|
|
5569
5622
|
}, {
|
|
@@ -5592,34 +5645,34 @@ var SessionManager = /*#__PURE__*/function () {
|
|
|
5592
5645
|
}();
|
|
5593
5646
|
SessionManager.REFRESH_INTERVAL_MS = 1000 * 60 * 3;
|
|
5594
5647
|
var StateChangeClient = /*#__PURE__*/_createClass(function StateChangeClient(_subscriptionService, emptyState) {
|
|
5595
|
-
var
|
|
5648
|
+
var _this30 = this;
|
|
5596
5649
|
_classCallCheck(this, StateChangeClient);
|
|
5597
5650
|
this._subscriptionService = _subscriptionService;
|
|
5598
5651
|
this.emptyState = emptyState;
|
|
5599
5652
|
this.onStateChange = function (callback) {
|
|
5600
|
-
return
|
|
5601
|
-
callback(state !== null && state !== void 0 ? state :
|
|
5653
|
+
return _this30._subscriptionService.subscribeToState(function (state) {
|
|
5654
|
+
callback(state !== null && state !== void 0 ? state : _this30.emptyState);
|
|
5602
5655
|
});
|
|
5603
5656
|
};
|
|
5604
5657
|
});
|
|
5605
5658
|
var WILDCARD_ACTION = '*';
|
|
5606
5659
|
var RBACPolicy = /*#__PURE__*/function () {
|
|
5607
5660
|
function RBACPolicy(roles, resources) {
|
|
5608
|
-
var
|
|
5661
|
+
var _this36 = this;
|
|
5609
5662
|
_classCallCheck(this, RBACPolicy);
|
|
5610
5663
|
this.roles = roles;
|
|
5611
5664
|
this.resources = resources;
|
|
5612
5665
|
this.rolesByID = {};
|
|
5613
5666
|
roles.forEach(function (role) {
|
|
5614
|
-
return
|
|
5667
|
+
return _this36.rolesByID[role.role_id] = role;
|
|
5615
5668
|
});
|
|
5616
5669
|
}
|
|
5617
5670
|
_createClass(RBACPolicy, [{
|
|
5618
5671
|
key: "callerIsAuthorized",
|
|
5619
5672
|
value: function callerIsAuthorized(memberRoles, resourceId, action) {
|
|
5620
|
-
var
|
|
5673
|
+
var _this37 = this;
|
|
5621
5674
|
return !!memberRoles.map(function (roleId) {
|
|
5622
|
-
return
|
|
5675
|
+
return _this37.rolesByID[roleId];
|
|
5623
5676
|
}).filter(function (v) {
|
|
5624
5677
|
return v;
|
|
5625
5678
|
}).flatMap(function (role) {
|
|
@@ -5633,12 +5686,12 @@ var RBACPolicy = /*#__PURE__*/function () {
|
|
|
5633
5686
|
}, {
|
|
5634
5687
|
key: "allPermissionsForCaller",
|
|
5635
5688
|
value: function allPermissionsForCaller(memberRoles) {
|
|
5636
|
-
var
|
|
5689
|
+
var _this38 = this;
|
|
5637
5690
|
var allPermsMap = Object.create(null);
|
|
5638
5691
|
this.resources.forEach(function (resource) {
|
|
5639
5692
|
allPermsMap[resource.resource_id] = {};
|
|
5640
5693
|
resource.actions.forEach(function (action) {
|
|
5641
|
-
allPermsMap[resource.resource_id][action] =
|
|
5694
|
+
allPermsMap[resource.resource_id][action] = _this38.callerIsAuthorized(memberRoles, resource.resource_id, action);
|
|
5642
5695
|
});
|
|
5643
5696
|
});
|
|
5644
5697
|
return allPermsMap;
|
|
@@ -5772,4 +5825,4 @@ var readB2BInternals = function readB2BInternals(obj) {
|
|
|
5772
5825
|
}
|
|
5773
5826
|
return casted[internalSymB2B];
|
|
5774
5827
|
};
|
|
5775
|
-
export { SDKNotConfiguredError as $, AuthFlowType as A, B2BMFAProducts as B, COUNTRIES_LIST as C, DEFAULT_SESSION_DURATION_MINUTES as D, EMAIL_REGEX as E, FailedCodeChallengeError as F, MissingUrlError as G, NoBiometricsRegistrationError as H, InternalError as I, JSONDataNotConvertibleToStringError as J, KeyInvalidatedError as K, NoCredentialsPresentError as L, MissingAttestationObjectError as M, NoBiometricsEnrolledError as N, OAuthProviders as O, Products as P, NoCurrentSessionError as Q, RedirectURLType as R, StytchEventType as S, PasskeysInvalidEncoding as T, PasskeysMisconfigured as U, PasskeysUnsupportedError as V, Wallets as W, RNUIProducts as X, RandomNumberGenerationFailed as Y, SDKAPIUnreachableError as Z, __rest as _, B2BProducts as a, SignInWithAppleMisconfigured as a0, StytchAPISchemaError as a1, StytchAPIUnreachableError as a2, StytchError as a3, StytchSDKAPIError as a4, StytchSDKSchemaError as a5, StytchSDKUsageError as a6, UNRECOVERABLE_ERROR_TYPES as a7, UserCancellationError as a8, UserLockedOutError as a9, HeadlessB2BSessionClient as aA, HeadlessB2BMagicLinksClient as aB, HeadlessB2BSSOClient as aC, HeadlessB2BDiscoveryClient as aD, HeadlessB2BPasswordsClient as aE, HeadlessB2BOTPsClient as aF, HeadlessB2BTOTPsClient as aG, HeadlessB2BRecoveryCodesClient as aH, HeadlessB2BRBACClient as aI, HeadlessB2BSCIMClient as aJ,
|
|
5828
|
+
export { SDKNotConfiguredError as $, AuthFlowType as A, B2BMFAProducts as B, COUNTRIES_LIST as C, DEFAULT_SESSION_DURATION_MINUTES as D, EMAIL_REGEX as E, FailedCodeChallengeError as F, MissingUrlError as G, NoBiometricsRegistrationError as H, InternalError as I, JSONDataNotConvertibleToStringError as J, KeyInvalidatedError as K, NoCredentialsPresentError as L, MissingAttestationObjectError as M, NoBiometricsEnrolledError as N, OAuthProviders as O, Products as P, NoCurrentSessionError as Q, RedirectURLType as R, StytchEventType as S, PasskeysInvalidEncoding as T, PasskeysMisconfigured as U, PasskeysUnsupportedError as V, Wallets as W, RNUIProducts as X, RandomNumberGenerationFailed as Y, SDKAPIUnreachableError as Z, __rest as _, B2BProducts as a, SignInWithAppleMisconfigured as a0, StytchAPISchemaError as a1, StytchAPIUnreachableError as a2, StytchError as a3, StytchSDKAPIError as a4, StytchSDKSchemaError as a5, StytchSDKUsageError as a6, UNRECOVERABLE_ERROR_TYPES as a7, UserCancellationError as a8, UserLockedOutError as a9, HeadlessB2BSessionClient as aA, HeadlessB2BMagicLinksClient as aB, HeadlessB2BSSOClient as aC, HeadlessB2BDiscoveryClient as aD, HeadlessB2BPasswordsClient as aE, HeadlessB2BOTPsClient as aF, HeadlessB2BTOTPsClient as aG, HeadlessB2BRecoveryCodesClient as aH, HeadlessB2BRBACClient as aI, HeadlessB2BSCIMClient as aJ, HeadlessB2BImpersonationClient as aK, SessionManager as aL, SearchDataManager as aM, writeB2BInternals as aN, errorToStytchError as aa, createDeepEqual as ab, getPersistentStorageKey as ac, HeadlessB2BOAuthClient$1 as ad, loadESModule as ae, IframeHostClient as af, validate as ag, hasMultipleCookies as ah, isLocalhost as ai, GOOGLE_ONE_TAP_HOST as aj, GOOGLE_ONE_TAP_SCRIPT_URL as ak, EventLogger as al, DEFAULT_MAX_BATCH_SIZE as am, DEFAULT_INTERVAL_DURATION_MS as an, createEventId as ao, createAppSessionId as ap, createPersistentId as aq, baseFetchSDK as ar, retriableFetchSDK as as, checkB2BNotSSR as at, checkPublicToken as au, buildFinalConfig as av, StateChangeClient as aw, DFPProtectedAuthProvider as ax, HeadlessB2BOrganizationClient as ay, HeadlessB2BSelfClient as az, OTPMethods as b, B2BOAuthProviders as c, __awaiter as d, StytchAPIError as e, OneTapPositions as f, debounce as g, StytchSDKError as h, isTestPublicToken as i, checkNotSSR as j, BiometricsFailedError as k, logger as l, BiometricsUnavailableError as m, ChallengeSigningFailedError as n, DeviceCredentialsNotAllowedError as o, FailedToDecryptDataError as p, InvalidAuthorizationCredentialError as q, readB2BInternals as r, InvalidCredentialTypeError as s, InvalidRedirectSchemeError as t, InvalidStartUrlError as u, KeystoreUnavailableError as v, MissingAuthorizationCredentialIDTokenError as w, MissingGoogleClientIDError as x, MissingPKCEError as y, MissingPublicKeyError as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stytch/vanilla-js",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.3",
|
|
4
4
|
"description": "Stytch's official Javascript Client Library",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"hoistingLimits": "workspaces"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@stytch/core": "2.
|
|
42
|
+
"@stytch/core": "2.35.0",
|
|
43
43
|
"@types/google-one-tap": "^1.2.0",
|
|
44
44
|
"type-fest": "4.15.0"
|
|
45
45
|
},
|