@frontegg/angular 6.13.0 → 6.14.0-alpha.7371658662
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/bundles/frontegg-angular.umd.js +105 -53
- package/bundles/frontegg-angular.umd.js.map +1 -1
- package/esm2015/lib/frontegg-app.module.js +3 -1
- package/esm2015/lib/frontegg-auth.service.js +18 -4
- package/esm2015/lib/frontegg-entitlements.service.js +27 -51
- package/esm2015/lib/frontegg-user-subscription.service.js +65 -0
- package/fesm2015/frontegg-angular.js +103 -53
- package/fesm2015/frontegg-angular.js.map +1 -1
- package/lib/frontegg-app.module.d.ts.map +1 -1
- package/lib/frontegg-auth.service.d.ts +15 -2
- package/lib/frontegg-auth.service.d.ts.map +1 -1
- package/lib/frontegg-entitlements.service.d.ts +4 -17
- package/lib/frontegg-entitlements.service.d.ts.map +1 -1
- package/lib/frontegg-user-subscription.service.d.ts +31 -0
- package/lib/frontegg-user-subscription.service.d.ts.map +1 -0
- package/package.json +2 -2
- package/CHANGELOG.md +0 -523
|
@@ -624,11 +624,75 @@
|
|
|
624
624
|
}
|
|
625
625
|
};
|
|
626
626
|
|
|
627
|
+
/**
|
|
628
|
+
* A service for managing user state subscription
|
|
629
|
+
* The service gives the ability to subscribe to user state change and get a manipulated data when the user state changes
|
|
630
|
+
*/
|
|
631
|
+
var FronteggUserSubscriptionService = /** @class */ (function () {
|
|
632
|
+
function FronteggUserSubscriptionService(fronteggAppService) {
|
|
633
|
+
var _this = this;
|
|
634
|
+
this.fronteggAppService = fronteggAppService;
|
|
635
|
+
this.userStateSubject = new rxjs.BehaviorSubject(undefined);
|
|
636
|
+
var state = this.fronteggAppService.fronteggApp.store.getState();
|
|
637
|
+
this.updateUserStateIfNeeded(state.auth);
|
|
638
|
+
// Memoized user State
|
|
639
|
+
this.fronteggAppService.fronteggApp.store.subscribe(function () {
|
|
640
|
+
var newState = _this.fronteggAppService.fronteggApp.store.getState();
|
|
641
|
+
_this.updateUserStateIfNeeded(newState.auth);
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Trigger user subject change event if the user reference changes
|
|
646
|
+
* No need for deep equal because we already check it internally
|
|
647
|
+
* @param authState
|
|
648
|
+
*/
|
|
649
|
+
FronteggUserSubscriptionService.prototype.updateUserStateIfNeeded = function (authState) {
|
|
650
|
+
var userState = authState.user;
|
|
651
|
+
if (this.userStateSubject.value === userState) {
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
this.userStateSubject.next(userState);
|
|
655
|
+
};
|
|
656
|
+
/**
|
|
657
|
+
* The function gives the ability to return a manipulated data of the user state as a subscription.
|
|
658
|
+
*
|
|
659
|
+
* @param dataManipulator Manipulator function that receives user state and returns a manipulated data
|
|
660
|
+
* @param observer For receiving manipulated data result
|
|
661
|
+
* @returns a subscription to be able to unsubscribe
|
|
662
|
+
*/
|
|
663
|
+
FronteggUserSubscriptionService.prototype.getUserManipulatorSubscription = function (dataManipulator, observer) {
|
|
664
|
+
// used for computing the end user result because we don't return the state itself, but a calculated one
|
|
665
|
+
var userSubject = new rxjs.BehaviorSubject(undefined);
|
|
666
|
+
var stateSubscription = this.userStateSubject.subscribe(function (user) {
|
|
667
|
+
userSubject.next(dataManipulator(user));
|
|
668
|
+
});
|
|
669
|
+
// subscribing the consumer observer
|
|
670
|
+
var userResultSubscription = userSubject.asObservable().subscribe(observer);
|
|
671
|
+
// monkey patched to manage both un-subscriptions: state and user manipulated result
|
|
672
|
+
var originalUnsubscribe = userResultSubscription.unsubscribe.bind(userResultSubscription);
|
|
673
|
+
userResultSubscription.unsubscribe = function () {
|
|
674
|
+
originalUnsubscribe();
|
|
675
|
+
stateSubscription.unsubscribe();
|
|
676
|
+
};
|
|
677
|
+
return userResultSubscription;
|
|
678
|
+
};
|
|
679
|
+
return FronteggUserSubscriptionService;
|
|
680
|
+
}());
|
|
681
|
+
FronteggUserSubscriptionService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FronteggUserSubscriptionService, deps: [{ token: FronteggAppService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
682
|
+
FronteggUserSubscriptionService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FronteggUserSubscriptionService, providedIn: 'root' });
|
|
683
|
+
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FronteggUserSubscriptionService, decorators: [{
|
|
684
|
+
type: i0.Injectable,
|
|
685
|
+
args: [{
|
|
686
|
+
providedIn: 'root',
|
|
687
|
+
}]
|
|
688
|
+
}], ctorParameters: function () { return [{ type: FronteggAppService }]; } });
|
|
689
|
+
|
|
627
690
|
var FronteggAuthService = /** @class */ (function () {
|
|
628
|
-
function FronteggAuthService(fronteggAppService, router) {
|
|
691
|
+
function FronteggAuthService(fronteggAppService, router, fronteggUserSubscriptionService) {
|
|
629
692
|
var _this = this;
|
|
630
693
|
this.fronteggAppService = fronteggAppService;
|
|
631
694
|
this.router = router;
|
|
695
|
+
this.fronteggUserSubscriptionService = fronteggUserSubscriptionService;
|
|
632
696
|
this.authStateSubject = new rxjs.BehaviorSubject({ isAuthenticated: false, isLoading: true });
|
|
633
697
|
this.acceptInvitationStateSubject = new rxjs.BehaviorSubject({});
|
|
634
698
|
this.accountSettingsStateSubject = new rxjs.BehaviorSubject({});
|
|
@@ -651,6 +715,11 @@
|
|
|
651
715
|
this.isLoadingSubject = new rxjs.BehaviorSubject(true);
|
|
652
716
|
this.isSSOAuthSubject = new rxjs.BehaviorSubject(false);
|
|
653
717
|
this.ssoACSSubject = new rxjs.BehaviorSubject('');
|
|
718
|
+
/**
|
|
719
|
+
* Triggers step up flow
|
|
720
|
+
* @param options.maxAge optional max age
|
|
721
|
+
*/
|
|
722
|
+
this.stepUp = function (options) { return _this.fronteggAppService.fronteggApp.stepUp(options); };
|
|
654
723
|
// Root Actions
|
|
655
724
|
this.setState = function (state) { return _this.dispatchAction('setState', state); };
|
|
656
725
|
this.resetState = function () { return _this.dispatchAction('resetState'); };
|
|
@@ -1036,16 +1105,24 @@
|
|
|
1036
1105
|
var hostedLoginRedirectUrl = this.fronteggAppService.authRoutes.hostedLoginRedirectUrl;
|
|
1037
1106
|
return path.startsWith(hostedLoginRedirectUrl !== null && hostedLoginRedirectUrl !== void 0 ? hostedLoginRedirectUrl : '/oauth/callback');
|
|
1038
1107
|
};
|
|
1108
|
+
/**
|
|
1109
|
+
* @param options.maxAge optional max age
|
|
1110
|
+
* @returns A subscription for step up state - true when user is stepped up, false otherwise
|
|
1111
|
+
*/
|
|
1112
|
+
FronteggAuthService.prototype.isSteppedUp$ = function (observer, options) {
|
|
1113
|
+
var _this = this;
|
|
1114
|
+
return this.fronteggUserSubscriptionService.getUserManipulatorSubscription(function () { return _this.fronteggAppService.fronteggApp.isSteppedUp(options); }, observer);
|
|
1115
|
+
};
|
|
1039
1116
|
return FronteggAuthService;
|
|
1040
1117
|
}());
|
|
1041
|
-
FronteggAuthService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FronteggAuthService, deps: [{ token: FronteggAppService }, { token: i1__namespace.Router }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
1118
|
+
FronteggAuthService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FronteggAuthService, deps: [{ token: FronteggAppService }, { token: i1__namespace.Router }, { token: FronteggUserSubscriptionService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
1042
1119
|
FronteggAuthService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FronteggAuthService, providedIn: 'root' });
|
|
1043
1120
|
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FronteggAuthService, decorators: [{
|
|
1044
1121
|
type: i0.Injectable,
|
|
1045
1122
|
args: [{
|
|
1046
1123
|
providedIn: 'root',
|
|
1047
1124
|
}]
|
|
1048
|
-
}], ctorParameters: function () { return [{ type: FronteggAppService }, { type: i1__namespace.Router }]; } });
|
|
1125
|
+
}], ctorParameters: function () { return [{ type: FronteggAppService }, { type: i1__namespace.Router }, { type: FronteggUserSubscriptionService }]; } });
|
|
1049
1126
|
|
|
1050
1127
|
var FronteggAuthGuard = /** @class */ (function (_super) {
|
|
1051
1128
|
__extends(FronteggAuthGuard, _super);
|
|
@@ -1260,53 +1337,10 @@
|
|
|
1260
1337
|
* 3. Load entitlements on demand.
|
|
1261
1338
|
*/
|
|
1262
1339
|
var FronteggEntitlementsService = /** @class */ (function () {
|
|
1263
|
-
function FronteggEntitlementsService(fronteggAppService) {
|
|
1264
|
-
var _this = this;
|
|
1340
|
+
function FronteggEntitlementsService(fronteggAppService, fronteggUserSubscriptionService) {
|
|
1265
1341
|
this.fronteggAppService = fronteggAppService;
|
|
1266
|
-
this.
|
|
1267
|
-
var state = this.fronteggAppService.fronteggApp.store.getState();
|
|
1268
|
-
this.updateUserStateIfNeeded(state.auth);
|
|
1269
|
-
// Memoized entitlements State
|
|
1270
|
-
this.fronteggAppService.fronteggApp.store.subscribe(function () {
|
|
1271
|
-
var newState = _this.fronteggAppService.fronteggApp.store.getState();
|
|
1272
|
-
_this.updateUserStateIfNeeded(newState.auth);
|
|
1273
|
-
});
|
|
1342
|
+
this.fronteggUserSubscriptionService = fronteggUserSubscriptionService;
|
|
1274
1343
|
}
|
|
1275
|
-
/**
|
|
1276
|
-
* Trigger entitlements subject change event if the entitlements reference changes
|
|
1277
|
-
* No need for deep equal because we already check it internally
|
|
1278
|
-
* @param authState
|
|
1279
|
-
*/
|
|
1280
|
-
FronteggEntitlementsService.prototype.updateUserStateIfNeeded = function (authState) {
|
|
1281
|
-
var entitlementsState = authState.user;
|
|
1282
|
-
if (this.userStateSubject.value === entitlementsState) {
|
|
1283
|
-
return;
|
|
1284
|
-
}
|
|
1285
|
-
this.userStateSubject.next(entitlementsState);
|
|
1286
|
-
};
|
|
1287
|
-
/**
|
|
1288
|
-
* The function gives the ability to return a manipulated data of the user state as a subscription.
|
|
1289
|
-
*
|
|
1290
|
-
* @param dataManipulator Manipulator function that receives user state and returns a manipulated data
|
|
1291
|
-
* @param observer For receiving manipulated data result
|
|
1292
|
-
* @returns a subscription to be able to unsubscribe
|
|
1293
|
-
*/
|
|
1294
|
-
FronteggEntitlementsService.prototype.getUserManipulatorSubscription = function (dataManipulator, observer) {
|
|
1295
|
-
// used for computing the entitlements result because we don't return the state itself, but a calculated one
|
|
1296
|
-
var userSubject = new rxjs.BehaviorSubject(undefined);
|
|
1297
|
-
var stateSubscription = this.userStateSubject.subscribe(function (user) {
|
|
1298
|
-
userSubject.next(dataManipulator(user));
|
|
1299
|
-
});
|
|
1300
|
-
// subscribing the consumer observer
|
|
1301
|
-
var userResultSubscription = userSubject.asObservable().subscribe(observer);
|
|
1302
|
-
// monkey patched to manage both un-subscriptions: state and user manipulated result
|
|
1303
|
-
var originalUnsubscribe = userResultSubscription.unsubscribe.bind(userResultSubscription);
|
|
1304
|
-
userResultSubscription.unsubscribe = function () {
|
|
1305
|
-
originalUnsubscribe();
|
|
1306
|
-
stateSubscription.unsubscribe();
|
|
1307
|
-
};
|
|
1308
|
-
return userResultSubscription;
|
|
1309
|
-
};
|
|
1310
1344
|
/**
|
|
1311
1345
|
* @param feature
|
|
1312
1346
|
* @param observer For receiving the feature entitlements result including if the user is entitled to the given feature.
|
|
@@ -1317,7 +1351,13 @@
|
|
|
1317
1351
|
*/
|
|
1318
1352
|
FronteggEntitlementsService.prototype.featureEntitlements$ = function (feature, observer, customAttributes) {
|
|
1319
1353
|
var _this = this;
|
|
1320
|
-
return this.getUserManipulatorSubscription(function () {
|
|
1354
|
+
return this.fronteggUserSubscriptionService.getUserManipulatorSubscription(function (user) {
|
|
1355
|
+
// the entitlemenets-common npm doesn't know to overcome the case of signed out user, then we get console errors
|
|
1356
|
+
if (user) {
|
|
1357
|
+
return _this.fronteggAppService.fronteggApp.getFeatureEntitlements(feature, customAttributes);
|
|
1358
|
+
}
|
|
1359
|
+
return { isEntitled: false, justification: restApi.NotEntitledJustification.MISSING_FEATURE };
|
|
1360
|
+
}, observer);
|
|
1321
1361
|
};
|
|
1322
1362
|
/**
|
|
1323
1363
|
* @param permission
|
|
@@ -1328,7 +1368,12 @@
|
|
|
1328
1368
|
*/
|
|
1329
1369
|
FronteggEntitlementsService.prototype.permissionEntitlements$ = function (permission, observer, customAttributes) {
|
|
1330
1370
|
var _this = this;
|
|
1331
|
-
return this.getUserManipulatorSubscription(function () {
|
|
1371
|
+
return this.fronteggUserSubscriptionService.getUserManipulatorSubscription(function (user) {
|
|
1372
|
+
if (user) {
|
|
1373
|
+
return _this.fronteggAppService.fronteggApp.getPermissionEntitlements(permission, customAttributes);
|
|
1374
|
+
}
|
|
1375
|
+
return { isEntitled: false, justification: restApi.NotEntitledJustification.MISSING_PERMISSION };
|
|
1376
|
+
}, observer);
|
|
1332
1377
|
};
|
|
1333
1378
|
/**
|
|
1334
1379
|
* @param options permissionKey or featureKey in an options object
|
|
@@ -1339,7 +1384,13 @@
|
|
|
1339
1384
|
*/
|
|
1340
1385
|
FronteggEntitlementsService.prototype.entitlements$ = function (options, observer, customAttributes) {
|
|
1341
1386
|
var _this = this;
|
|
1342
|
-
return this.getUserManipulatorSubscription(function () {
|
|
1387
|
+
return this.fronteggUserSubscriptionService.getUserManipulatorSubscription(function (user) {
|
|
1388
|
+
if (user) {
|
|
1389
|
+
return _this.fronteggAppService.fronteggApp.getEntitlements(options, customAttributes);
|
|
1390
|
+
}
|
|
1391
|
+
var justification = 'featureKey' in options ? restApi.NotEntitledJustification.MISSING_FEATURE : restApi.NotEntitledJustification.MISSING_PERMISSION;
|
|
1392
|
+
return { isEntitled: false, justification: justification };
|
|
1393
|
+
}, observer);
|
|
1343
1394
|
};
|
|
1344
1395
|
/**
|
|
1345
1396
|
* Load entitlements data on demand
|
|
@@ -1350,14 +1401,14 @@
|
|
|
1350
1401
|
};
|
|
1351
1402
|
return FronteggEntitlementsService;
|
|
1352
1403
|
}());
|
|
1353
|
-
FronteggEntitlementsService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FronteggEntitlementsService, deps: [{ token: FronteggAppService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
1404
|
+
FronteggEntitlementsService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FronteggEntitlementsService, deps: [{ token: FronteggAppService }, { token: FronteggUserSubscriptionService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
1354
1405
|
FronteggEntitlementsService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FronteggEntitlementsService, providedIn: 'root' });
|
|
1355
1406
|
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FronteggEntitlementsService, decorators: [{
|
|
1356
1407
|
type: i0.Injectable,
|
|
1357
1408
|
args: [{
|
|
1358
1409
|
providedIn: 'root',
|
|
1359
1410
|
}]
|
|
1360
|
-
}], ctorParameters: function () { return [{ type: FronteggAppService }]; } });
|
|
1411
|
+
}], ctorParameters: function () { return [{ type: FronteggAppService }, { type: FronteggUserSubscriptionService }]; } });
|
|
1361
1412
|
|
|
1362
1413
|
var FronteggAppModule = /** @class */ (function () {
|
|
1363
1414
|
function FronteggAppModule() {
|
|
@@ -1372,6 +1423,7 @@
|
|
|
1372
1423
|
FronteggAuthService,
|
|
1373
1424
|
FronteggEntitlementsService,
|
|
1374
1425
|
FronteggSubscriptionService,
|
|
1426
|
+
FronteggUserSubscriptionService,
|
|
1375
1427
|
{
|
|
1376
1428
|
provide: FronteggAppOptionsClass,
|
|
1377
1429
|
useValue: config,
|