@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
|
@@ -6,7 +6,7 @@ import { DefaultUrlSerializer, RouterModule } from '@angular/router';
|
|
|
6
6
|
import { initialize } from '@frontegg/js';
|
|
7
7
|
import { isAuthRoute, authStoreName, subscriptionsStoreName } from '@frontegg/redux-store';
|
|
8
8
|
import { BehaviorSubject, Observable } from 'rxjs';
|
|
9
|
-
import { FronteggFrameworks, ContextHolder } from '@frontegg/rest-api';
|
|
9
|
+
import { FronteggFrameworks, ContextHolder, NotEntitledJustification } from '@frontegg/rest-api';
|
|
10
10
|
export { ContextHolder } from '@frontegg/rest-api';
|
|
11
11
|
import angularCoreVersion from '@angular/core/package.json';
|
|
12
12
|
import { __awaiter } from 'tslib';
|
|
@@ -243,10 +243,72 @@ const runNgZoneIfNeeded = (ngZone, fn) => {
|
|
|
243
243
|
}
|
|
244
244
|
};
|
|
245
245
|
|
|
246
|
+
/**
|
|
247
|
+
* A service for managing user state subscription
|
|
248
|
+
* The service gives the ability to subscribe to user state change and get a manipulated data when the user state changes
|
|
249
|
+
*/
|
|
250
|
+
class FronteggUserSubscriptionService {
|
|
251
|
+
constructor(fronteggAppService) {
|
|
252
|
+
this.fronteggAppService = fronteggAppService;
|
|
253
|
+
this.userStateSubject = new BehaviorSubject(undefined);
|
|
254
|
+
const state = this.fronteggAppService.fronteggApp.store.getState();
|
|
255
|
+
this.updateUserStateIfNeeded(state.auth);
|
|
256
|
+
// Memoized user State
|
|
257
|
+
this.fronteggAppService.fronteggApp.store.subscribe(() => {
|
|
258
|
+
const newState = this.fronteggAppService.fronteggApp.store.getState();
|
|
259
|
+
this.updateUserStateIfNeeded(newState.auth);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Trigger user subject change event if the user reference changes
|
|
264
|
+
* No need for deep equal because we already check it internally
|
|
265
|
+
* @param authState
|
|
266
|
+
*/
|
|
267
|
+
updateUserStateIfNeeded(authState) {
|
|
268
|
+
const userState = authState.user;
|
|
269
|
+
if (this.userStateSubject.value === userState) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
this.userStateSubject.next(userState);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* The function gives the ability to return a manipulated data of the user state as a subscription.
|
|
276
|
+
*
|
|
277
|
+
* @param dataManipulator Manipulator function that receives user state and returns a manipulated data
|
|
278
|
+
* @param observer For receiving manipulated data result
|
|
279
|
+
* @returns a subscription to be able to unsubscribe
|
|
280
|
+
*/
|
|
281
|
+
getUserManipulatorSubscription(dataManipulator, observer) {
|
|
282
|
+
// used for computing the end user result because we don't return the state itself, but a calculated one
|
|
283
|
+
const userSubject = new BehaviorSubject(undefined);
|
|
284
|
+
const stateSubscription = this.userStateSubject.subscribe(user => {
|
|
285
|
+
userSubject.next(dataManipulator(user));
|
|
286
|
+
});
|
|
287
|
+
// subscribing the consumer observer
|
|
288
|
+
const userResultSubscription = userSubject.asObservable().subscribe(observer);
|
|
289
|
+
// monkey patched to manage both un-subscriptions: state and user manipulated result
|
|
290
|
+
const originalUnsubscribe = userResultSubscription.unsubscribe.bind(userResultSubscription);
|
|
291
|
+
userResultSubscription.unsubscribe = () => {
|
|
292
|
+
originalUnsubscribe();
|
|
293
|
+
stateSubscription.unsubscribe();
|
|
294
|
+
};
|
|
295
|
+
return userResultSubscription;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
FronteggUserSubscriptionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FronteggUserSubscriptionService, deps: [{ token: FronteggAppService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
299
|
+
FronteggUserSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FronteggUserSubscriptionService, providedIn: 'root' });
|
|
300
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FronteggUserSubscriptionService, decorators: [{
|
|
301
|
+
type: Injectable,
|
|
302
|
+
args: [{
|
|
303
|
+
providedIn: 'root',
|
|
304
|
+
}]
|
|
305
|
+
}], ctorParameters: function () { return [{ type: FronteggAppService }]; } });
|
|
306
|
+
|
|
246
307
|
class FronteggAuthService {
|
|
247
|
-
constructor(fronteggAppService, router) {
|
|
308
|
+
constructor(fronteggAppService, router, fronteggUserSubscriptionService) {
|
|
248
309
|
this.fronteggAppService = fronteggAppService;
|
|
249
310
|
this.router = router;
|
|
311
|
+
this.fronteggUserSubscriptionService = fronteggUserSubscriptionService;
|
|
250
312
|
this.authStateSubject = new BehaviorSubject({ isAuthenticated: false, isLoading: true });
|
|
251
313
|
this.acceptInvitationStateSubject = new BehaviorSubject({});
|
|
252
314
|
this.accountSettingsStateSubject = new BehaviorSubject({});
|
|
@@ -269,6 +331,11 @@ class FronteggAuthService {
|
|
|
269
331
|
this.isLoadingSubject = new BehaviorSubject(true);
|
|
270
332
|
this.isSSOAuthSubject = new BehaviorSubject(false);
|
|
271
333
|
this.ssoACSSubject = new BehaviorSubject('');
|
|
334
|
+
/**
|
|
335
|
+
* Triggers step up flow
|
|
336
|
+
* @param options.maxAge optional max age
|
|
337
|
+
*/
|
|
338
|
+
this.stepUp = (options) => this.fronteggAppService.fronteggApp.stepUp(options);
|
|
272
339
|
// Root Actions
|
|
273
340
|
this.setState = (state) => this.dispatchAction('setState', state);
|
|
274
341
|
this.resetState = () => this.dispatchAction('resetState');
|
|
@@ -547,15 +614,22 @@ class FronteggAuthService {
|
|
|
547
614
|
const hostedLoginRedirectUrl = this.fronteggAppService.authRoutes.hostedLoginRedirectUrl;
|
|
548
615
|
return path.startsWith(hostedLoginRedirectUrl !== null && hostedLoginRedirectUrl !== void 0 ? hostedLoginRedirectUrl : '/oauth/callback');
|
|
549
616
|
}
|
|
617
|
+
/**
|
|
618
|
+
* @param options.maxAge optional max age
|
|
619
|
+
* @returns A subscription for step up state - true when user is stepped up, false otherwise
|
|
620
|
+
*/
|
|
621
|
+
isSteppedUp$(observer, options) {
|
|
622
|
+
return this.fronteggUserSubscriptionService.getUserManipulatorSubscription(() => { return this.fronteggAppService.fronteggApp.isSteppedUp(options); }, observer);
|
|
623
|
+
}
|
|
550
624
|
}
|
|
551
|
-
FronteggAuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FronteggAuthService, deps: [{ token: FronteggAppService }, { token: i1.Router }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
625
|
+
FronteggAuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FronteggAuthService, deps: [{ token: FronteggAppService }, { token: i1.Router }, { token: FronteggUserSubscriptionService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
552
626
|
FronteggAuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FronteggAuthService, providedIn: 'root' });
|
|
553
627
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FronteggAuthService, decorators: [{
|
|
554
628
|
type: Injectable,
|
|
555
629
|
args: [{
|
|
556
630
|
providedIn: 'root',
|
|
557
631
|
}]
|
|
558
|
-
}], ctorParameters: function () { return [{ type: FronteggAppService }, { type: i1.Router }]; } });
|
|
632
|
+
}], ctorParameters: function () { return [{ type: FronteggAppService }, { type: i1.Router }, { type: FronteggUserSubscriptionService }]; } });
|
|
559
633
|
|
|
560
634
|
class FronteggAuthGuard extends FronteggBaseGuard {
|
|
561
635
|
constructor(fronteggAppService, fronteggAuthService, router, ngZone) {
|
|
@@ -738,51 +812,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
|
|
|
738
812
|
* 3. Load entitlements on demand.
|
|
739
813
|
*/
|
|
740
814
|
class FronteggEntitlementsService {
|
|
741
|
-
constructor(fronteggAppService) {
|
|
815
|
+
constructor(fronteggAppService, fronteggUserSubscriptionService) {
|
|
742
816
|
this.fronteggAppService = fronteggAppService;
|
|
743
|
-
this.
|
|
744
|
-
const state = this.fronteggAppService.fronteggApp.store.getState();
|
|
745
|
-
this.updateUserStateIfNeeded(state.auth);
|
|
746
|
-
// Memoized entitlements State
|
|
747
|
-
this.fronteggAppService.fronteggApp.store.subscribe(() => {
|
|
748
|
-
const newState = this.fronteggAppService.fronteggApp.store.getState();
|
|
749
|
-
this.updateUserStateIfNeeded(newState.auth);
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
/**
|
|
753
|
-
* Trigger entitlements subject change event if the entitlements reference changes
|
|
754
|
-
* No need for deep equal because we already check it internally
|
|
755
|
-
* @param authState
|
|
756
|
-
*/
|
|
757
|
-
updateUserStateIfNeeded(authState) {
|
|
758
|
-
const entitlementsState = authState.user;
|
|
759
|
-
if (this.userStateSubject.value === entitlementsState) {
|
|
760
|
-
return;
|
|
761
|
-
}
|
|
762
|
-
this.userStateSubject.next(entitlementsState);
|
|
763
|
-
}
|
|
764
|
-
/**
|
|
765
|
-
* The function gives the ability to return a manipulated data of the user state as a subscription.
|
|
766
|
-
*
|
|
767
|
-
* @param dataManipulator Manipulator function that receives user state and returns a manipulated data
|
|
768
|
-
* @param observer For receiving manipulated data result
|
|
769
|
-
* @returns a subscription to be able to unsubscribe
|
|
770
|
-
*/
|
|
771
|
-
getUserManipulatorSubscription(dataManipulator, observer) {
|
|
772
|
-
// used for computing the entitlements result because we don't return the state itself, but a calculated one
|
|
773
|
-
const userSubject = new BehaviorSubject(undefined);
|
|
774
|
-
const stateSubscription = this.userStateSubject.subscribe(user => {
|
|
775
|
-
userSubject.next(dataManipulator(user));
|
|
776
|
-
});
|
|
777
|
-
// subscribing the consumer observer
|
|
778
|
-
const userResultSubscription = userSubject.asObservable().subscribe(observer);
|
|
779
|
-
// monkey patched to manage both un-subscriptions: state and user manipulated result
|
|
780
|
-
const originalUnsubscribe = userResultSubscription.unsubscribe.bind(userResultSubscription);
|
|
781
|
-
userResultSubscription.unsubscribe = () => {
|
|
782
|
-
originalUnsubscribe();
|
|
783
|
-
stateSubscription.unsubscribe();
|
|
784
|
-
};
|
|
785
|
-
return userResultSubscription;
|
|
817
|
+
this.fronteggUserSubscriptionService = fronteggUserSubscriptionService;
|
|
786
818
|
}
|
|
787
819
|
/**
|
|
788
820
|
* @param feature
|
|
@@ -793,7 +825,13 @@ class FronteggEntitlementsService {
|
|
|
793
825
|
* @throws when entitlement is not enabled via frontegg options
|
|
794
826
|
*/
|
|
795
827
|
featureEntitlements$(feature, observer, customAttributes) {
|
|
796
|
-
return this.getUserManipulatorSubscription(() => {
|
|
828
|
+
return this.fronteggUserSubscriptionService.getUserManipulatorSubscription((user) => {
|
|
829
|
+
// the entitlemenets-common npm doesn't know to overcome the case of signed out user, then we get console errors
|
|
830
|
+
if (user) {
|
|
831
|
+
return this.fronteggAppService.fronteggApp.getFeatureEntitlements(feature, customAttributes);
|
|
832
|
+
}
|
|
833
|
+
return { isEntitled: false, justification: NotEntitledJustification.MISSING_FEATURE };
|
|
834
|
+
}, observer);
|
|
797
835
|
}
|
|
798
836
|
/**
|
|
799
837
|
* @param permission
|
|
@@ -803,7 +841,12 @@ class FronteggEntitlementsService {
|
|
|
803
841
|
* @returns a subscription to be able to unsubscribe
|
|
804
842
|
*/
|
|
805
843
|
permissionEntitlements$(permission, observer, customAttributes) {
|
|
806
|
-
return this.getUserManipulatorSubscription(() =>
|
|
844
|
+
return this.fronteggUserSubscriptionService.getUserManipulatorSubscription((user) => {
|
|
845
|
+
if (user) {
|
|
846
|
+
return this.fronteggAppService.fronteggApp.getPermissionEntitlements(permission, customAttributes);
|
|
847
|
+
}
|
|
848
|
+
return { isEntitled: false, justification: NotEntitledJustification.MISSING_PERMISSION };
|
|
849
|
+
}, observer);
|
|
807
850
|
}
|
|
808
851
|
/**
|
|
809
852
|
* @param options permissionKey or featureKey in an options object
|
|
@@ -813,7 +856,13 @@ class FronteggEntitlementsService {
|
|
|
813
856
|
* @returns a subscription to be able to unsubscribe
|
|
814
857
|
*/
|
|
815
858
|
entitlements$(options, observer, customAttributes) {
|
|
816
|
-
return this.getUserManipulatorSubscription(() =>
|
|
859
|
+
return this.fronteggUserSubscriptionService.getUserManipulatorSubscription((user) => {
|
|
860
|
+
if (user) {
|
|
861
|
+
return this.fronteggAppService.fronteggApp.getEntitlements(options, customAttributes);
|
|
862
|
+
}
|
|
863
|
+
const justification = 'featureKey' in options ? NotEntitledJustification.MISSING_FEATURE : NotEntitledJustification.MISSING_PERMISSION;
|
|
864
|
+
return { isEntitled: false, justification };
|
|
865
|
+
}, observer);
|
|
817
866
|
}
|
|
818
867
|
/**
|
|
819
868
|
* Load entitlements data on demand
|
|
@@ -823,14 +872,14 @@ class FronteggEntitlementsService {
|
|
|
823
872
|
this.fronteggAppService.fronteggApp.loadEntitlements(callback);
|
|
824
873
|
}
|
|
825
874
|
}
|
|
826
|
-
FronteggEntitlementsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FronteggEntitlementsService, deps: [{ token: FronteggAppService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
875
|
+
FronteggEntitlementsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FronteggEntitlementsService, deps: [{ token: FronteggAppService }, { token: FronteggUserSubscriptionService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
827
876
|
FronteggEntitlementsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FronteggEntitlementsService, providedIn: 'root' });
|
|
828
877
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FronteggEntitlementsService, decorators: [{
|
|
829
878
|
type: Injectable,
|
|
830
879
|
args: [{
|
|
831
880
|
providedIn: 'root',
|
|
832
881
|
}]
|
|
833
|
-
}], ctorParameters: function () { return [{ type: FronteggAppService }]; } });
|
|
882
|
+
}], ctorParameters: function () { return [{ type: FronteggAppService }, { type: FronteggUserSubscriptionService }]; } });
|
|
834
883
|
|
|
835
884
|
class FronteggAppModule {
|
|
836
885
|
static forRoot(config) {
|
|
@@ -843,6 +892,7 @@ class FronteggAppModule {
|
|
|
843
892
|
FronteggAuthService,
|
|
844
893
|
FronteggEntitlementsService,
|
|
845
894
|
FronteggSubscriptionService,
|
|
895
|
+
FronteggUserSubscriptionService,
|
|
846
896
|
{
|
|
847
897
|
provide: FronteggAppOptionsClass,
|
|
848
898
|
useValue: config,
|