@frontegg/angular 6.7.0-alpha.6655826001 → 6.7.0-alpha.6655897396
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 +30 -25
- package/bundles/frontegg-angular.umd.js.map +1 -1
- package/esm2015/lib/frontegg-entitlements.service.js +28 -27
- package/fesm2015/frontegg-angular.js +28 -26
- package/fesm2015/frontegg-angular.js.map +1 -1
- package/lib/frontegg-entitlements.service.d.ts +12 -9
- package/lib/frontegg-entitlements.service.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1219,13 +1219,13 @@
|
|
|
1219
1219
|
function FronteggEntitlementsService(fronteggAppService) {
|
|
1220
1220
|
var _this = this;
|
|
1221
1221
|
this.fronteggAppService = fronteggAppService;
|
|
1222
|
-
this.
|
|
1222
|
+
this.userStateSubject = new rxjs.BehaviorSubject(undefined);
|
|
1223
1223
|
var state = this.fronteggAppService.fronteggApp.store.getState();
|
|
1224
|
-
this.
|
|
1224
|
+
this.updateUserStateIfNeeded(state.auth);
|
|
1225
1225
|
// Memoized entitlements State
|
|
1226
1226
|
this.fronteggAppService.fronteggApp.store.subscribe(function () {
|
|
1227
1227
|
var newState = _this.fronteggAppService.fronteggApp.store.getState();
|
|
1228
|
-
_this.
|
|
1228
|
+
_this.updateUserStateIfNeeded(newState.auth);
|
|
1229
1229
|
});
|
|
1230
1230
|
}
|
|
1231
1231
|
/**
|
|
@@ -1233,64 +1233,69 @@
|
|
|
1233
1233
|
* No need for deep equal because we already check it internally
|
|
1234
1234
|
* @param authState
|
|
1235
1235
|
*/
|
|
1236
|
-
FronteggEntitlementsService.prototype.
|
|
1237
|
-
var
|
|
1238
|
-
|
|
1239
|
-
if (this.entitlementsStateSubject.value === entitlementsState) {
|
|
1236
|
+
FronteggEntitlementsService.prototype.updateUserStateIfNeeded = function (authState) {
|
|
1237
|
+
var entitlementsState = authState.user;
|
|
1238
|
+
if (this.userStateSubject.value === entitlementsState) {
|
|
1240
1239
|
return;
|
|
1241
1240
|
}
|
|
1242
|
-
this.
|
|
1241
|
+
this.userStateSubject.next(entitlementsState);
|
|
1243
1242
|
};
|
|
1244
1243
|
/**
|
|
1245
|
-
* The function gives the ability to return a manipulated data of the
|
|
1244
|
+
* The function gives the ability to return a manipulated data of the user state as a subscription.
|
|
1246
1245
|
*
|
|
1247
|
-
* @param dataManipulator Manipulator function that receives
|
|
1246
|
+
* @param dataManipulator Manipulator function that receives user state and returns a manipulated data
|
|
1248
1247
|
* @param observer For receiving manipulated data result
|
|
1249
1248
|
* @returns a subscription to be able to unsubscribe
|
|
1250
1249
|
*/
|
|
1251
|
-
FronteggEntitlementsService.prototype.
|
|
1250
|
+
FronteggEntitlementsService.prototype.getUserManipulatorSubscription = function (dataManipulator, observer) {
|
|
1252
1251
|
// used for computing the entitlements result because we don't return the state itself, but a calculated one
|
|
1253
|
-
var
|
|
1254
|
-
var stateSubscription = this.
|
|
1255
|
-
|
|
1252
|
+
var userSubject = new rxjs.BehaviorSubject(undefined);
|
|
1253
|
+
var stateSubscription = this.userStateSubject.subscribe(function (user) {
|
|
1254
|
+
userSubject.next(dataManipulator(user));
|
|
1256
1255
|
});
|
|
1257
1256
|
// subscribing the consumer observer
|
|
1258
|
-
var
|
|
1259
|
-
// monkey patched to manage both un-subscriptions: state and
|
|
1260
|
-
var originalUnsubscribe =
|
|
1261
|
-
|
|
1257
|
+
var userResultSubscription = userSubject.asObservable().subscribe(observer);
|
|
1258
|
+
// monkey patched to manage both un-subscriptions: state and user manipulated result
|
|
1259
|
+
var originalUnsubscribe = userResultSubscription.unsubscribe.bind(userResultSubscription);
|
|
1260
|
+
userResultSubscription.unsubscribe = function () {
|
|
1262
1261
|
originalUnsubscribe();
|
|
1263
1262
|
stateSubscription.unsubscribe();
|
|
1264
1263
|
};
|
|
1265
|
-
return
|
|
1264
|
+
return userResultSubscription;
|
|
1266
1265
|
};
|
|
1267
1266
|
/**
|
|
1268
1267
|
* @param feature
|
|
1269
1268
|
* @param observer For receiving the feature entitlements result including if the user is entitled to the given feature.
|
|
1270
1269
|
* Attaching the justification if not entitled
|
|
1270
|
+
* @param customAttributes consumer attributes
|
|
1271
1271
|
* @returns a subscription to be able to unsubscribe
|
|
1272
1272
|
* @throws when entitlement is not enabled via frontegg options
|
|
1273
1273
|
*/
|
|
1274
|
-
FronteggEntitlementsService.prototype.featureEntitlements$ = function (feature, observer) {
|
|
1275
|
-
|
|
1274
|
+
FronteggEntitlementsService.prototype.featureEntitlements$ = function (feature, observer, customAttributes) {
|
|
1275
|
+
var _this = this;
|
|
1276
|
+
return this.getUserManipulatorSubscription(function () { return _this.fronteggAppService.fronteggApp.getFeatureEntitlements(feature, customAttributes); }, observer);
|
|
1276
1277
|
};
|
|
1277
1278
|
/**
|
|
1278
1279
|
* @param permission
|
|
1279
1280
|
* @param observer For receiving the permission entitlements result including if the user is entitled to the given permission.
|
|
1280
1281
|
* Attaching the justification if not entitled
|
|
1282
|
+
* @param customAttributes consumer attributes
|
|
1281
1283
|
* @returns a subscription to be able to unsubscribe
|
|
1282
1284
|
*/
|
|
1283
|
-
FronteggEntitlementsService.prototype.permissionEntitlements$ = function (permission, observer) {
|
|
1284
|
-
|
|
1285
|
+
FronteggEntitlementsService.prototype.permissionEntitlements$ = function (permission, observer, customAttributes) {
|
|
1286
|
+
var _this = this;
|
|
1287
|
+
return this.getUserManipulatorSubscription(function () { return _this.fronteggAppService.fronteggApp.getPermissionEntitlements(permission, customAttributes); }, observer);
|
|
1285
1288
|
};
|
|
1286
1289
|
/**
|
|
1287
1290
|
* @param options permissionKey or featureKey in an options object
|
|
1288
1291
|
* @param observer For receiving the permission entitlements result including if the user is entitled to the given permission.
|
|
1289
1292
|
* Attaching the justification if not entitled
|
|
1293
|
+
* @param customAttributes consumer attributes
|
|
1290
1294
|
* @returns a subscription to be able to unsubscribe
|
|
1291
1295
|
*/
|
|
1292
|
-
FronteggEntitlementsService.prototype.entitlements$ = function (options, observer) {
|
|
1293
|
-
|
|
1296
|
+
FronteggEntitlementsService.prototype.entitlements$ = function (options, observer, customAttributes) {
|
|
1297
|
+
var _this = this;
|
|
1298
|
+
return this.getUserManipulatorSubscription(function () { return _this.fronteggAppService.fronteggApp.getEntitlements(options, customAttributes); }, observer);
|
|
1294
1299
|
};
|
|
1295
1300
|
/**
|
|
1296
1301
|
* Load entitlements data on demand
|