@frontegg/angular 5.37.0-alpha.5638298020 → 5.37.0-alpha.5642735229

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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/router'), require('@frontegg/js'), require('rxjs'), require('@frontegg/rest-api'), require('@frontegg/redux-store'), require('rxjs/operators'), require('fast-deep-equal')) :
3
- typeof define === 'function' && define.amd ? define('@frontegg/angular', ['exports', '@angular/core', '@angular/common', '@angular/router', '@frontegg/js', 'rxjs', '@frontegg/rest-api', '@frontegg/redux-store', 'rxjs/operators', 'fast-deep-equal'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.frontegg = global.frontegg || {}, global.frontegg.angular = {}), global.ng.core, global.ng.common, global.ng.router, global.FronteggJS, global.rxjs, global.FronteggRestApi, global.FronteggReduxStore, global.rxjs.operators, global.FastDeepEqual));
5
- }(this, (function (exports, i0, common, i1, js, rxjs, restApi, reduxStore, operators, FastDeepEqual) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/router'), require('@frontegg/js'), require('@frontegg/redux-store'), require('rxjs'), require('@frontegg/rest-api'), require('rxjs/operators'), require('fast-deep-equal')) :
3
+ typeof define === 'function' && define.amd ? define('@frontegg/angular', ['exports', '@angular/core', '@angular/common', '@angular/router', '@frontegg/js', '@frontegg/redux-store', 'rxjs', '@frontegg/rest-api', 'rxjs/operators', 'fast-deep-equal'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.frontegg = global.frontegg || {}, global.frontegg.angular = {}), global.ng.core, global.ng.common, global.ng.router, global.FronteggJS, global.FronteggReduxStore, global.rxjs, global.FronteggRestApi, global.rxjs.operators, global.FastDeepEqual));
5
+ }(this, (function (exports, i0, common, i1, js, reduxStore, rxjs, restApi, operators, FastDeepEqual) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -1215,6 +1215,108 @@
1215
1215
  { type: FronteggAppService }
1216
1216
  ]; };
1217
1217
 
1218
+ /**
1219
+ * An entitlements service for:
1220
+ * 1. Managing state subscription.
1221
+ * 2. Querying about feature and permission entitlements state.
1222
+ * 3. Load entitlements on demand.
1223
+ */
1224
+ var FronteggEntitlementsService = /** @class */ (function () {
1225
+ function FronteggEntitlementsService(fronteggAppService) {
1226
+ var _this = this;
1227
+ this.fronteggAppService = fronteggAppService;
1228
+ this.entitlementsStateSubject = new rxjs.BehaviorSubject(undefined);
1229
+ var state = this.fronteggAppService.fronteggApp.store.getState();
1230
+ this.updateEntitlementsStateIfNeeded(state.auth);
1231
+ // Memoized entitlements State
1232
+ this.fronteggAppService.fronteggApp.store.subscribe(function () {
1233
+ var newState = _this.fronteggAppService.fronteggApp.store.getState();
1234
+ _this.updateEntitlementsStateIfNeeded(newState.auth);
1235
+ });
1236
+ }
1237
+ /**
1238
+ * Trigger entitlements subject change event if the entitlements reference changes
1239
+ * No need for deep equal because we already check it internally
1240
+ * @param authState
1241
+ */
1242
+ FronteggEntitlementsService.prototype.updateEntitlementsStateIfNeeded = function (authState) {
1243
+ var _a;
1244
+ var entitlementsState = (_a = authState.user) === null || _a === void 0 ? void 0 : _a.entitlements;
1245
+ if (this.entitlementsStateSubject.value === entitlementsState) {
1246
+ return;
1247
+ }
1248
+ this.entitlementsStateSubject.next(entitlementsState);
1249
+ };
1250
+ /**
1251
+ * The function gives the ability to return a manipulated data of the entitlements state as a subscription.
1252
+ *
1253
+ * @param dataManipulator Manipulator function that receives entitlements state and returns a manipulated data
1254
+ * @param observer For receiving manipulated data result
1255
+ * @returns a subscription to be able to unsubscribe
1256
+ */
1257
+ FronteggEntitlementsService.prototype.getEntitlementsManipulatorSubscription = function (dataManipulator, observer) {
1258
+ // used for computing the entitlements result because we don't return the state itself, but a calculated one
1259
+ var entitlementsSubject = new rxjs.BehaviorSubject(undefined);
1260
+ var stateSubscription = this.entitlementsStateSubject.subscribe(function (entitlements) {
1261
+ entitlementsSubject.next(dataManipulator(entitlements));
1262
+ });
1263
+ // subscribing the consumer observer
1264
+ var entitlementsResultSubscription = entitlementsSubject.asObservable().subscribe(observer);
1265
+ // monkey patched to manage both un-subscriptions: state and entitlements manipulated result
1266
+ var originalUnsubscribe = entitlementsResultSubscription.unsubscribe.bind(entitlementsResultSubscription);
1267
+ entitlementsResultSubscription.unsubscribe = function () {
1268
+ originalUnsubscribe();
1269
+ stateSubscription.unsubscribe();
1270
+ };
1271
+ return entitlementsResultSubscription;
1272
+ };
1273
+ /**
1274
+ * @param feature
1275
+ * @param observer For receiving the feature entitlements result including if the user is entitled to the given feature.
1276
+ * Attaching the justification if not entitled
1277
+ * @returns a subscription to be able to unsubscribe
1278
+ * @throws when entitlement is not enabled via frontegg options
1279
+ */
1280
+ FronteggEntitlementsService.prototype.featureEntitlements$ = function (feature, observer) {
1281
+ return this.getEntitlementsManipulatorSubscription(function (entitlements) { return reduxStore.getFeatureEntitlements(entitlements, feature); }, observer);
1282
+ };
1283
+ /**
1284
+ * @param permission
1285
+ * @param observer For receiving the permission entitlements result including if the user is entitled to the given permission.
1286
+ * Attaching the justification if not entitled
1287
+ * @returns a subscription to be able to unsubscribe
1288
+ */
1289
+ FronteggEntitlementsService.prototype.permissionEntitlements$ = function (permission, observer) {
1290
+ return this.getEntitlementsManipulatorSubscription(function (entitlements) { return reduxStore.getPermissionEntitlements(entitlements, permission); }, observer);
1291
+ };
1292
+ /**
1293
+ * @param options permissionKey or featureKey in an options object
1294
+ * @param observer For receiving the permission entitlements result including if the user is entitled to the given permission.
1295
+ * Attaching the justification if not entitled
1296
+ * @returns a subscription to be able to unsubscribe
1297
+ */
1298
+ FronteggEntitlementsService.prototype.entitlements$ = function (options, observer) {
1299
+ return this.getEntitlementsManipulatorSubscription(function (entitlements) { return reduxStore.getEntitlements(entitlements, options); }, observer);
1300
+ };
1301
+ /**
1302
+ * Load entitlements data on demand
1303
+ * @param callback called on request completed with true if succeeded, false if failed
1304
+ */
1305
+ FronteggEntitlementsService.prototype.loadEntitlements = function (callback) {
1306
+ this.fronteggAppService.fronteggApp.loadEntitlements(callback);
1307
+ };
1308
+ return FronteggEntitlementsService;
1309
+ }());
1310
+ FronteggEntitlementsService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function FronteggEntitlementsService_Factory() { return new FronteggEntitlementsService(i0__namespace.ɵɵinject(FronteggAppService)); }, token: FronteggEntitlementsService, providedIn: "root" });
1311
+ FronteggEntitlementsService.decorators = [
1312
+ { type: i0.Injectable, args: [{
1313
+ providedIn: 'root',
1314
+ },] }
1315
+ ];
1316
+ FronteggEntitlementsService.ctorParameters = function () { return [
1317
+ { type: FronteggAppService }
1318
+ ]; };
1319
+
1218
1320
  var FronteggAppModule = /** @class */ (function () {
1219
1321
  function FronteggAppModule() {
1220
1322
  }
@@ -1226,6 +1328,7 @@
1226
1328
  FronteggAuthGuard,
1227
1329
  FronteggLoadGuard,
1228
1330
  FronteggAuthService,
1331
+ FronteggEntitlementsService,
1229
1332
  FronteggSubscriptionService,
1230
1333
  {
1231
1334
  provide: FronteggAppOptionsClass,
@@ -1264,6 +1367,7 @@
1264
1367
  exports.FronteggAuthGuard = FronteggAuthGuard;
1265
1368
  exports.FronteggAuthService = FronteggAuthService;
1266
1369
  exports.FronteggComponent = FronteggComponent;
1370
+ exports.FronteggEntitlementsService = FronteggEntitlementsService;
1267
1371
  exports.FronteggLoadGuard = FronteggLoadGuard;
1268
1372
  exports.FronteggSubscriptionService = FronteggSubscriptionService;
1269
1373
  exports.ɵa = FronteggAppOptionsClass;