@frontegg/vue 3.0.7-alpha.6656170342 → 3.0.7-alpha.6719799225
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/dist/auth/entitlements.d.ts +8 -5
- package/dist/auth/mapAuthState.d.ts +10 -9
- package/dist/index.js +77 -17
- package/dist/index.min.js +2 -2
- package/dist/index.ssr.js +76 -20
- package/dist/types.d.ts +9 -6
- package/package.json +1 -1
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { EntitledToOptions, Entitlement } from '@frontegg/types';
|
|
2
2
|
/**
|
|
3
|
-
@param key feature
|
|
3
|
+
@param key feature key
|
|
4
|
+
@param customAttributes consumer attributes
|
|
4
5
|
@returns if the user is entitled to the given feature. Attaching the justification if not
|
|
5
6
|
@throws when entitlement is not enabled via frontegg options
|
|
6
7
|
*/
|
|
7
|
-
export declare const useFeatureEntitlements: (key: string) => Entitlement;
|
|
8
|
+
export declare const useFeatureEntitlements: (key: string, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
|
|
8
9
|
/**
|
|
9
|
-
@param key permission
|
|
10
|
+
@param key permission key
|
|
11
|
+
@param customAttributes consumer attributes
|
|
10
12
|
@returns if the user is entitled to the given permission. Attaching the justification if not
|
|
11
13
|
@throws when entitlement is not enabled via frontegg options
|
|
12
14
|
*/
|
|
13
|
-
export declare const usePermissionEntitlements: (key: string) => Entitlement;
|
|
15
|
+
export declare const usePermissionEntitlements: (key: string, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
|
|
14
16
|
/**
|
|
15
17
|
@param entitledToOptions - including permission or feature key
|
|
18
|
+
@param customAttributes consumer attributes
|
|
16
19
|
@returns if the user is entitled to the given permission or feature. Attaching the justification if not
|
|
17
20
|
@throws when entitlement is not enabled via frontegg options
|
|
18
21
|
*/
|
|
19
|
-
export declare const useEntitlements: (entitledToOptions: EntitledToOptions) => Entitlement;
|
|
22
|
+
export declare const useEntitlements: (entitledToOptions: EntitledToOptions, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
|
|
@@ -160,10 +160,10 @@ export declare const mapSocialLoginActions: <K extends "setSocialLoginsState" |
|
|
|
160
160
|
}[K];
|
|
161
161
|
export declare const mapSsoActions: <K extends "loadSSOConfigurationsV2" | "saveSSOConfigurationV2" | "updateSSOConfiguration" | "deleteSSOConfiguration" | "deleteSSODomain" | "saveSSODomain" | "validateSSODomainV2" | "setSSODefaultRoles" | "setSSOGroups" | "updateSSOGroups" | "saveSSOConfigurationByMetadata" | "updateSSOConfigurationByMetadata" | "saveSSOConfigurationByData" | "saveSSOConfigurationByUrl" | "setSSOLoader" | "setSSOError" | "setSSOState" | "resetSSOState" | "loadSSOConfigurations" | "loadSSOAuthorizationRoles" | "saveSSOConfigurations" | "saveSSOConfigurationsFile" | "saveSSOConfigurationsFileWithCallback" | "validateSSODomain" | "updateSSOAuthorizationRoles" | "deleteSamlGroup" | "createSamlGroup" | "oidcPostlogin">(action: K) => {
|
|
162
162
|
loadSSOConfigurationsV2: () => void;
|
|
163
|
-
saveSSOConfigurationV2: (payload: import("@frontegg/redux-store").WithCallback<Partial<Pick<import("@frontegg/
|
|
164
|
-
updateSSOConfiguration: (payload: import("@frontegg/redux-store").WithCallback<Partial<Pick<import("@frontegg/
|
|
163
|
+
saveSSOConfigurationV2: (payload: import("@frontegg/redux-store").WithCallback<Partial<Pick<import("@frontegg/rest-api").ISSOConfiguration, "groups" | "enabled" | "generatedVerification" | "ssoEndpoint" | "publicCertificate" | "signRequest" | "acsUrl" | "type" | "spEntityId" | "oidcClientId" | "oidcSecret" | "roleIds" | "skipEmailDomainValidation">>, import("@frontegg/rest-api").ISSOConfiguration>) => void;
|
|
164
|
+
updateSSOConfiguration: (payload: import("@frontegg/redux-store").WithCallback<Partial<Pick<import("@frontegg/rest-api").ISSOConfiguration, "groups" | "enabled" | "generatedVerification" | "ssoEndpoint" | "publicCertificate" | "signRequest" | "acsUrl" | "type" | "spEntityId" | "oidcClientId" | "oidcSecret" | "roleIds" | "skipEmailDomainValidation">> & {
|
|
165
165
|
ssoConfigId: string;
|
|
166
|
-
}, import("@frontegg/
|
|
166
|
+
}, import("@frontegg/rest-api").ISSOConfiguration>) => void;
|
|
167
167
|
deleteSSOConfiguration: (payload: import("@frontegg/redux-store").WithCallback<{
|
|
168
168
|
ssoConfigId: string;
|
|
169
169
|
}, boolean>) => void;
|
|
@@ -173,7 +173,7 @@ export declare const mapSsoActions: <K extends "loadSSOConfigurationsV2" | "save
|
|
|
173
173
|
}, boolean>) => void;
|
|
174
174
|
saveSSODomain: (payload: import("@frontegg/redux-store").WithCallback<import("@frontegg/rest-api").ICreateSSODomain & {
|
|
175
175
|
ssoConfigId: string;
|
|
176
|
-
}, import("@frontegg/
|
|
176
|
+
}, import("@frontegg/rest-api").ISSODomain>) => void;
|
|
177
177
|
validateSSODomainV2: (payload: import("@frontegg/redux-store").WithCallback<{
|
|
178
178
|
domainId: string;
|
|
179
179
|
ssoConfigId: string;
|
|
@@ -193,20 +193,20 @@ export declare const mapSsoActions: <K extends "loadSSOConfigurationsV2" | "save
|
|
|
193
193
|
}, boolean>) => void;
|
|
194
194
|
saveSSOConfigurationByMetadata: (payload: import("@frontegg/redux-store").WithCallback<{
|
|
195
195
|
configFile: File;
|
|
196
|
-
}, import("@frontegg/
|
|
196
|
+
}, import("@frontegg/rest-api").ISSOConfiguration>) => void;
|
|
197
197
|
updateSSOConfigurationByMetadata: (payload: import("@frontegg/redux-store").WithCallback<{
|
|
198
198
|
configFile: File;
|
|
199
199
|
ssoConfigId: string;
|
|
200
|
-
}, import("@frontegg/
|
|
201
|
-
saveSSOConfigurationByData: (payload: import("@frontegg/redux-store").WithCallback<Partial<import("@frontegg/
|
|
200
|
+
}, import("@frontegg/rest-api").ISSOConfiguration>) => void;
|
|
201
|
+
saveSSOConfigurationByData: (payload: import("@frontegg/redux-store").WithCallback<Partial<import("@frontegg/rest-api").ISSOConfiguration> & {
|
|
202
202
|
ssoConfigId?: string | undefined;
|
|
203
203
|
configMetadata?: Record<string, string> | undefined;
|
|
204
|
-
}, import("@frontegg/
|
|
204
|
+
}, import("@frontegg/rest-api").ISSOConfiguration>) => void;
|
|
205
205
|
saveSSOConfigurationByUrl: (payload: import("@frontegg/redux-store").WithCallback<{
|
|
206
206
|
ssoConfigId?: string | undefined;
|
|
207
207
|
configMetadata?: Record<string, string> | undefined;
|
|
208
208
|
metadataUrl: string;
|
|
209
|
-
}, import("@frontegg/
|
|
209
|
+
}, import("@frontegg/rest-api").ISSOConfiguration>) => void;
|
|
210
210
|
setSSOLoader: (payload: import("@frontegg/redux-store").SSOStateIndicator) => void;
|
|
211
211
|
setSSOError: (payload: import("@frontegg/redux-store").SSOStateIndicator) => void;
|
|
212
212
|
setSSOState: (state: Partial<import("@frontegg/redux-store").SSOState>) => void;
|
|
@@ -298,6 +298,7 @@ export declare const useAuthState: () => AuthState;
|
|
|
298
298
|
export declare const useFronteggStore: () => any;
|
|
299
299
|
export declare const useFronteggAuth: () => FronteggAuthService;
|
|
300
300
|
export declare const useLoadEntitlements: () => any;
|
|
301
|
+
export declare const useFeatureFlag: (keys: string[]) => boolean[];
|
|
301
302
|
export declare const useFrontegg: () => {
|
|
302
303
|
fronteggLoaded: boolean;
|
|
303
304
|
authState: AuthState;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Vue from 'vue';
|
|
2
2
|
import { inject, onBeforeUnmount, onMounted, onUpdated, reactive, computed, ref } from 'vue';
|
|
3
|
-
import { ContextHolder, FronteggFrameworks } from '@frontegg/rest-api';
|
|
3
|
+
import { ContextHolder, FeatureFlags, USE_ENTITLEMENTS_V2_ENDPOINT_FF, FronteggFrameworks } from '@frontegg/rest-api';
|
|
4
4
|
export { ContextHolder } from '@frontegg/rest-api';
|
|
5
5
|
import set from 'set-value';
|
|
6
6
|
import { isAuthRoute, authInitialState, loginActions, socialLoginsActions, activateAccountActions, acceptInvitationActions, forgotPasswordActions, signUpActions, profileActions, ssoActions, mfaActions, teamActions, apiTokensActions, securityPolicyActions, tenantsActions, bindActionCreators, authActions, getFeatureEntitlements, getPermissionEntitlements, getEntitlements } from '@frontegg/redux-store';
|
|
@@ -417,6 +417,12 @@ const useFronteggAuth = () => {
|
|
|
417
417
|
const useLoadEntitlements = () => {
|
|
418
418
|
return inject(loadEntitlementsKey);
|
|
419
419
|
};
|
|
420
|
+
const useFeatureFlag = keys => {
|
|
421
|
+
const {
|
|
422
|
+
appName
|
|
423
|
+
} = useFronteggStore();
|
|
424
|
+
return FeatureFlags.getFeatureFlags(keys, appName);
|
|
425
|
+
};
|
|
420
426
|
const useFrontegg = () => {
|
|
421
427
|
const fronteggLoaded = useFronteggLoaded();
|
|
422
428
|
const unsubscribeFronteggStore = useUnsubscribeFronteggStore();
|
|
@@ -663,40 +669,94 @@ var VuePkg = {
|
|
|
663
669
|
};
|
|
664
670
|
|
|
665
671
|
// @ts-ignore
|
|
672
|
+
/**
|
|
673
|
+
* @returns user state
|
|
674
|
+
*/
|
|
666
675
|
|
|
667
|
-
const
|
|
668
|
-
var _a;
|
|
669
|
-
|
|
676
|
+
const useGetUserState = () => {
|
|
670
677
|
const authState = inject(authStateKey);
|
|
671
|
-
return
|
|
678
|
+
return authState.user;
|
|
679
|
+
};
|
|
680
|
+
/**
|
|
681
|
+
* @returns true when need to use entitlements V2 API
|
|
682
|
+
*/
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
const useIsV2API = () => {
|
|
686
|
+
const [useEntitlementsV2] = useFeatureFlag([USE_ENTITLEMENTS_V2_ENDPOINT_FF]);
|
|
687
|
+
return useEntitlementsV2;
|
|
688
|
+
};
|
|
689
|
+
/**
|
|
690
|
+
* @param customAttributes consumer attributes
|
|
691
|
+
* @returns is entitled query data including: entitltments state, final attributes (consumer and frontegg) and API version to use
|
|
692
|
+
*/
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
const useEntitlementsQueryData = customAttributes => {
|
|
696
|
+
const user = useGetUserState();
|
|
697
|
+
const entitlements = user === null || user === void 0 ? void 0 : user.entitlements;
|
|
698
|
+
const isV2 = useIsV2API();
|
|
699
|
+
const attributes = {
|
|
700
|
+
custom: customAttributes,
|
|
701
|
+
jwt: user
|
|
702
|
+
};
|
|
703
|
+
return {
|
|
704
|
+
entitlements,
|
|
705
|
+
attributes,
|
|
706
|
+
isV2
|
|
707
|
+
};
|
|
672
708
|
};
|
|
673
709
|
/**
|
|
674
|
-
@param key feature
|
|
710
|
+
@param key feature key
|
|
711
|
+
@param customAttributes consumer attributes
|
|
675
712
|
@returns if the user is entitled to the given feature. Attaching the justification if not
|
|
676
713
|
@throws when entitlement is not enabled via frontegg options
|
|
677
714
|
*/
|
|
678
715
|
|
|
679
716
|
|
|
680
|
-
const useFeatureEntitlements = key => {
|
|
681
|
-
return computed(() =>
|
|
717
|
+
const useFeatureEntitlements = (key, customAttributes) => {
|
|
718
|
+
return computed(() => {
|
|
719
|
+
const {
|
|
720
|
+
entitlements,
|
|
721
|
+
attributes,
|
|
722
|
+
isV2
|
|
723
|
+
} = useEntitlementsQueryData(customAttributes);
|
|
724
|
+
return getFeatureEntitlements(entitlements, key, attributes, isV2);
|
|
725
|
+
});
|
|
682
726
|
};
|
|
683
727
|
/**
|
|
684
|
-
@param key permission
|
|
728
|
+
@param key permission key
|
|
729
|
+
@param customAttributes consumer attributes
|
|
685
730
|
@returns if the user is entitled to the given permission. Attaching the justification if not
|
|
686
731
|
@throws when entitlement is not enabled via frontegg options
|
|
687
732
|
*/
|
|
688
733
|
|
|
689
|
-
const usePermissionEntitlements = key => {
|
|
690
|
-
return computed(() =>
|
|
734
|
+
const usePermissionEntitlements = (key, customAttributes) => {
|
|
735
|
+
return computed(() => {
|
|
736
|
+
const {
|
|
737
|
+
entitlements,
|
|
738
|
+
attributes,
|
|
739
|
+
isV2
|
|
740
|
+
} = useEntitlementsQueryData(customAttributes);
|
|
741
|
+
return getPermissionEntitlements(entitlements, key, attributes, isV2);
|
|
742
|
+
});
|
|
691
743
|
};
|
|
692
744
|
/**
|
|
693
745
|
@param entitledToOptions - including permission or feature key
|
|
746
|
+
@param customAttributes consumer attributes
|
|
694
747
|
@returns if the user is entitled to the given permission or feature. Attaching the justification if not
|
|
695
748
|
@throws when entitlement is not enabled via frontegg options
|
|
696
749
|
*/
|
|
697
750
|
|
|
698
|
-
const useEntitlements = entitledToOptions => {
|
|
699
|
-
return computed(() =>
|
|
751
|
+
const useEntitlements = (entitledToOptions, customAttributes) => {
|
|
752
|
+
return computed(() => {
|
|
753
|
+
const {
|
|
754
|
+
entitlements,
|
|
755
|
+
attributes,
|
|
756
|
+
isV2
|
|
757
|
+
} = useEntitlementsQueryData(customAttributes);
|
|
758
|
+
return getEntitlements(entitlements, entitledToOptions, attributes, isV2);
|
|
759
|
+
});
|
|
700
760
|
};
|
|
701
761
|
|
|
702
762
|
const isAuthenticatedGuard = function (_to, _from, next) {
|
|
@@ -940,13 +1000,13 @@ const Frontegg = {
|
|
|
940
1000
|
beforeCreate() {
|
|
941
1001
|
setStoreKey(this, store);
|
|
942
1002
|
this.fronteggAuth = Vue.fronteggAuth;
|
|
943
|
-
this.loginWithRedirect = loginWithRedirect.bind(this); //
|
|
1003
|
+
this.loginWithRedirect = loginWithRedirect.bind(this); // _user was added for to make the computed property reactive, then it will get updated
|
|
944
1004
|
|
|
945
|
-
this.getFeatureEntitlements = (
|
|
1005
|
+
this.getFeatureEntitlements = (_user, key, customAttributes) => fronteggApp.getFeatureEntitlements(key, customAttributes);
|
|
946
1006
|
|
|
947
|
-
this.getPermissionEntitlements = (
|
|
1007
|
+
this.getPermissionEntitlements = (_user, key, customAttributes) => fronteggApp.getPermissionEntitlements(key, customAttributes);
|
|
948
1008
|
|
|
949
|
-
this.getEntitlements = (
|
|
1009
|
+
this.getEntitlements = (_user, entitledToOptions, customAttributes) => fronteggApp.getEntitlements(entitledToOptions, customAttributes);
|
|
950
1010
|
|
|
951
1011
|
this.loadEntitlements = loadEntitlements;
|
|
952
1012
|
connectMapState(this);
|
package/dist/index.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var FronteggCore=function(t,e,n,r,o,i,u){"use strict";function a(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function s(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var c=s(e),l=a(r),f=a(i);function d(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function g(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function h(t,e,n){return e&&g(t.prototype,e),n&&g(t,n),t}function v(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function p(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var n=[],r=!0,o=!1,i=void 0;try{for(var u,a=t[Symbol.iterator]();!(r=(u=a.next()).done)&&(n.push(u.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return n}(t,e)||b(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function b(t,e){if(t){if("string"==typeof t)return
|
|
1
|
+
var FronteggCore=function(t,e,n,r,o,i,u){"use strict";function a(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function s(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var c=s(e),l=a(r),f=a(i);function d(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function g(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function h(t,e,n){return e&&g(t.prototype,e),n&&g(t,n),t}function v(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function p(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var n=[],r=!0,o=!1,i=void 0;try{for(var u,a=t[Symbol.iterator]();!(r=(u=a.next()).done)&&(n.push(u.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return n}(t,e)||b(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function b(t,e){if(t){if("string"==typeof t)return m(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?m(t,e):void 0}}function m(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation.
|
|
4
4
|
|
|
@@ -13,4 +13,4 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
15
|
***************************************************************************** */
|
|
16
|
-
function m(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}var S=Symbol("fronteggLoade"),y=Symbol("authState"),O=Symbol("unsubscribeFronteggStore"),E=Symbol("fronteggAuth"),j=Symbol("loadEntitlements"),R=Symbol("router"),I=Symbol("fronteggOptions"),P=Symbol("fronteggStore"),T=function(t,e){var n;return t.FRONTEGG_STORE_KEY=null!==(n=t.FRONTEGG_STORE_KEY)&&void 0!==n?n:e},w=function(t){return t.FRONTEGG_STORE_KEY},U=function(t){return t.FRONTEGG_REDUX_BINDINGS},L=function(){function t(){d(this,t)}return h(t,null,[{key:"getInstance",value:function(){return t.instance||(t.instance=new t),t.instance}},{key:"setStore",value:function(e){t.getInstance().store=e}},{key:"getStore",value:function(){return t.getInstance().store}},{key:"setBasename",value:function(e){t.getInstance().baseName=e}},{key:"getBasename",value:function(){return t.getInstance().baseName}}]),t}(),k=function(t){return function(e){return f.default(e,t)}},F=function(t,e,n){return function(){var r,o=this,i=Object.keys(e),u=f.default(w(o).getState(),t),a=function(t,e,n,r,o){return n.reduce((function(n,i){return Object.assign({},n,v({},e,Object.assign(Object.assign({},n[e]),v({},i,function(t,e,n){return"function"==typeof e?e.bind(t):n(e)}(t,r[i],o)))))}),U(t)||{})}(o,t,i,e,n);return r=a,o.FRONTEGG_REDUX_BINDINGS=r,i.reduce((function(t,r){return Object.assign({},t,v({},r,function(t,e,n,r){return"function"==typeof e?e.call(t,r):n(e)(r)}(o,e[r],n,u)))}),{})}},_=function(){function t(){d(this,t)}return h(t,null,[{key:"getInstance",value:function(){return t.instance||(t.instance=new t),t.instance}},{key:"setActions",value:function(e){t.getInstance().actions=e}},{key:"getAction",value:function(e){return t.getInstance().actions[e]}}]),t}(),G=function(){function t(e){var n=this;d(this,t);var r=e.router,i=m(e,["router"]);this.state=o.authInitialState,this.userRef=void 0,this.init=function(t,e){n.store=e,Object.entries({loginActions:o.loginActions,socialLoginsActions:o.socialLoginsActions,activateAccountActions:o.activateAccountActions,acceptInvitationActions:o.acceptInvitationActions,forgotPasswordActions:o.forgotPasswordActions,signUpActions:o.signUpActions,profileActions:o.profileActions,ssoActions:o.ssoActions,mfaActions:o.mfaActions,teamActions:o.teamActions,apiTokensActions:o.apiTokensActions,securityPolicyActions:o.securityPolicyActions,tenantsActions:o.tenantsActions}).forEach((function(t){var e=p(t,2),r=e[0],i=e[1];Object.assign(n,v({},r,o.bindActionCreators(i,n.store.dispatch)))}));var r=o.bindActionCreators(o.authActions,n.store.dispatch);_.setActions(r),t.hostedLoginBox||n.store.subscribe(n.storeSubscriber)},this.storeSubscriber=function(){n.state=n.store.getState().auth;var t=!1;n.state.user!==n.userRef&&(n.userRef=n.state.user,t=!0),n.state.isAuthenticated!==n.isAuthenticatedRef&&(n.isAuthenticatedRef=n.state.isAuthenticated,t=!0),n.userRef&&n.state.isAuthenticated?t&&n.accessTokenUpdater():clearInterval(n.accessTokenUpdaterRef)},this.accessTokenUpdater=function(){var t,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(n.accessTokenUpdaterRef&&clearInterval(n.accessTokenUpdaterRef),e)n.loginActions.requestAuthorize(!0);else if(n.isAuthenticated){var r=1e3*((null===(t=n.user)||void 0===t?void 0:t.expiresIn)||20)*.8;n.accessTokenUpdaterRef=setInterval(n.loginActions.requestAuthorize,r)}},this._routes=Object.assign(Object.assign({},o.authInitialState.routes),i.routes),this.router=r}return h(t,[{key:"loading",get:function(){var t,e;return null===(e=null===(t=this.store)||void 0===t?void 0:t.getState().auth.isLoading)||void 0===e||e}},{key:"routes",get:function(){var t,e;return null!==(e=null===(t=this.store)||void 0===t?void 0:t.getState().auth.routes)&&void 0!==e?e:this._routes}},{key:"isAuthenticated",get:function(){var t,e;return null!==(e=null===(t=this.store)||void 0===t?void 0:t.getState().auth.isAuthenticated)&&void 0!==e&&e}},{key:"user",get:function(){var t;return null===(t=this.store)||void 0===t?void 0:t.getState().auth.user}}]),t}(),N=function(t,e){return function(){var n=v({},null!=e?e:t.substring("auth.".length),(function(t){return t}));return F(t,n,k).bind(this)()}},C=function(t){return N("auth","authState").bind(t)},B=function(t){return N("auth.loginState").bind(t)},x=function(t){return N("auth.acceptInvitationState").bind(t)},H=function(t){return N("auth.activateState").bind(t)},z=function(t){return N("auth.apiTokensState").bind(t)},q=function(t){return N("auth.forgotPasswordState").bind(t)},D=function(t){return N("auth.mfaState").bind(t)},W=function(t){return N("auth.profileState").bind(t)},M=function(t){return N("auth.securityPolicyState").bind(t)},V=function(t){return N("auth.signUpState").bind(t)},$=function(t){return N("auth.socialLoginState").bind(t)},K=function(t){return N("auth.ssoState").bind(t)},Y=function(t){return N("auth.teamState").bind(t)},X=function(t){return N("auth.tenantsState").bind(t)},Q=function(t){Object.assign(t,{mapAuthState:C(t),mapLoginState:B(t),mapAcceptInvitationState:x(t),mapActivateAccountState:H(t),mapApiTokensState:z(t),mapForgotPasswordState:q(t),mapMfaState:D(t),mapProfileState:W(t),mapSecurityPolicyState:M(t),mapSignUpState:V(t),mapSocialLoginState:$(t),mapSsoState:K(t),mapTeamState:Y(t),mapTenantsState:X(t)})},J=function(t){return function(){return _.getAction(t).apply(void 0,arguments)}},Z=function(){return e.inject(S)},tt=function(){return e.inject(O)},et=function(){return e.inject(y)},nt=function(){return e.inject(P)},rt=function(){return e.inject(E)},ot="3.0.6",it="2.6.12",ut=function(){var t;return null===(t=e.inject(y).user)||void 0===t?void 0:t.entitlements},at=null,st={install:function(t,r){var i,a,s=null!=r?r:{},d=s.router,g=m(s,["router"]),h=(null!=r?r:{}).contextOptions;if(null==h)throw Error("contextOptions must be passed to Vue.use(Frontegg, { /* OPTIONS */ })");h.requestCredentials=null!==(i=h.requestCredentials)&&void 0!==i?i:"include",h.metadataHeaders={framework:"".concat(n.FronteggFrameworks.Vuejs,"@").concat(it),fronteggSdkVersion:"@frontegg/vuejs@".concat(ot)},n.ContextHolder.setContext(h);var v,A=!1,k=!1,F="3"===t.version.charAt(0);F&&(v=e.ref(!1));var _=new Set,N=d&&function(t,e){var r=t.options.base||"";L.setBasename(r);var i=function(n,i){var u=n;u.startsWith(r)&&"/"!==r&&(u=u.substring(r.length-1)),((null==i?void 0:i.preserveQueryParams)||o.isAuthRoute(u,e))&&(u="".concat(u).concat(window.location.search)),(null==i?void 0:i.refresh)?window.location.href=u:(null==i?void 0:i.replace)?t.replace(u):t.push(u)};return n.ContextHolder.setOnRedirectTo(i),i}(d,null===(a=null==r?void 0:r.authOptions)||void 0===a?void 0:a.routes),C=(at=u.initialize(Object.assign(Object.assign({},g),{onRedirectTo:N,basename:null==d?void 0:d.options.base}))).store;L.setStore(C),t.$fronteggApp=at,t.fronteggAuth||(t.fronteggAuth=new G({router:d}),function(t,e){var n;t.fronteggPlugins=null!==(n=t.fronteggPlugins)&&void 0!==n?n:[],t.fronteggPlugins.push(e)}(t,t.fronteggAuth));var B=function(){var e=(t.fronteggPlugins||[]).reduce((function(t,e){return t&&!e.loading}),!0);if(e!==k){k=e,F&&(v.value=e);var n,r=function(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=b(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,u=!0,a=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return u=t.done,t},e:function(t){a=!0,i=t},f:function(){try{u||null==n.return||n.return()}finally{if(a)throw i}}}}(_);try{for(r.s();!(n=r.n()).done;){(0,n.value)()}}catch(t){r.e(t)}finally{r.f()}}};null==d||d.getRoutes().map((function(t){var e=t.beforeEnter;t.beforeEnter=function(t,n,r){var o=function(){e?e(t,n,r):r()};if(k)o();else var i=setInterval((function(){B(),k&&(clearInterval(i),o())}),1)}}));var x,H=setInterval((function(){B(),k&&clearInterval(H)}),10),z=function(e){var n,o;if(e.authorizedContent&&(n=e.$route.path,o=t.fronteggAuth.routes,!Object.values(o).filter((function(t){return t!=o.authenticatedUrl})).includes(n))&&(!t.fronteggAuth.loading&&!t.fronteggAuth.isAuthenticated))if(null==r?void 0:r.hostedLoginBox)t.fronteggAuth.loginActions.requestHostedLoginAuthorize();else{var i=t.fronteggAuth.routes.loginUrl;e.$router.push(i)}};function q(){this.$route.path.startsWith(t.fronteggAuth.routes.hostedLoginRedirectUrl)||(C.dispatch({type:"auth/setState",payload:{isLoading:!0}}),t.fronteggAuth.loginActions.requestHostedLoginAuthorize())}A||(x=t,A=!0,(t.fronteggPlugins||[]).forEach((function(t){return t.init(g,C)})),T(x,C),x.fronteggAuth=t.fronteggAuth,Q(x));var D=at.loadEntitlements.bind(at);if(F){t.provide(S,v);var W=function(t){var n=t.getState(),r=e.reactive(Object.assign({},n.auth)),o=t.subscribe((function(){var e=t.getState().auth;Object.entries(e).forEach((function(t){var n=p(t,2),o=n[0],i=n[1];r[o]!==e[o]&&(r[o]=i)}))}));return{authState:r,unsubscribe:o}}(C),M=W.authState,V=W.unsubscribe,$=e.reactive(Object.assign({},t.fronteggAuth));t.provide(y,M),t.provide(O,V),t.provide(E,$),t.provide(R,d),t.provide(I,r),t.provide(P,C),t.provide(j,D)}t.mixin({data:function(){return{fronteggLoaded:k}},beforeCreate:function(){T(this,C),this.fronteggAuth=t.fronteggAuth,this.loginWithRedirect=q.bind(this),this.getFeatureEntitlements=function(t,e){return at.getFeatureEntitlements(e)},this.getPermissionEntitlements=function(t,e){return at.getPermissionEntitlements(e)},this.getEntitlements=function(t,e){return at.getEntitlements(e)},this.loadEntitlements=D,Q(this)},updated:function(){z(this)},mounted:function(){z(this)},created:function(){var t,e;U(this)&&function(t,e){t.FRONTEGG_UNSUBSCRIBE=e}(this,C.subscribe((t=this,e=U(this),function(){var n=w(t).getState();Object.keys(e).forEach((function(r){Object.keys(e[r]).forEach((function(o){var i=e[r][o];if(i){var u,a=i(f.default(n,r)),s=Object.assign({},c);s.default&&(u=2),s.version&&"3"===s.version[0]&&(u=3),3===u&&l.default(t.$data,o,a),2===u&&l.default(t._data,o,a)}}))}))}))),function(t,e){t.FRONTEGG_LOADER_UNSUBSCRIBE=e}(this,function(t){var e=function(){t.fronteggLoaded=k};return _.add(e),function(){return _.delete(e)}}(this))},beforeDestroy:function(){!function(t){var e;null===(e=t.FRONTEGG_UNSUBSCRIBE)||void 0===e||e.call(t)}(this),function(t){var e;null===(e=t.FRONTEGG_LOADER_UNSUBSCRIBE)||void 0===e||e.call(t)}(this)}})}};return Object.defineProperty(t,"ContextHolder",{enumerable:!0,get:function(){return n.ContextHolder}}),Object.defineProperty(t,"AdminPortal",{enumerable:!0,get:function(){return u.AdminPortal}}),t.Frontegg=st,t.closeAdminPortal=function(){return u.AdminPortal.hide()},t.isAuthenticatedGuard=function(t,e,n){var r,o,i=function(){var e,r=L.getStore().getState().auth;if(r.isAuthenticated)n();else{var o=null!==(e=L.getBasename())&&void 0!==e?e:"",i=o.endsWith("/")?o.substring(0,o.length-1):"";localStorage.setItem("FRONTEGG_AFTER_AUTH_REDIRECT_URL","".concat(i).concat(t.fullPath)),n({path:r.routes.loginUrl,replace:!0})}},u=null===(o=null===(r=L.getStore())||void 0===r?void 0:r.getState())||void 0===o?void 0:o.auth;if(!u||(null==u?void 0:u.isLoading))var a=setInterval((function(){var t,e;(u=null===(e=null===(t=L.getStore())||void 0===t?void 0:t.getState())||void 0===e?void 0:e.auth)&&!(null==u?void 0:u.isLoading)&&(clearInterval(a),i())}),1);else i()},t.mapAcceptInvitationActions=function(t){return J(t)},t.mapActivateAccountActions=function(t){return J(t)},t.mapApiTokensActions=function(t){return J(t)},t.mapAuthActions=function(t){return J(t)},t.mapForgotPasswordActions=function(t){return J(t)},t.mapLoginActions=function(t){return J("loginWithRedirect"===t?"requestHostedLoginAuthorize":t)},t.mapMfaActions=function(t){return J(t)},t.mapProfileActions=function(t){return J(t)},t.mapSecurityPolicyActions=function(t){return J(t)},t.mapSignupActions=function(t){return J(t)},t.mapSocialLoginActions=function(t){return J(t)},t.mapSsoActions=function(t){return J(t)},t.mapTeamActions=function(t){return J(t)},t.openAdminPortal=function(){return u.AdminPortal.show()},t.useAuthState=et,t.useEntitlements=function(t){return e.computed((function(){return o.getEntitlements(ut(),t)}))},t.useFeatureEntitlements=function(t){return e.computed((function(){return o.getFeatureEntitlements(ut(),t)}))},t.useFrontegg=function(){var t=Z(),n=tt(),r=et(),o=rt(),i=e.inject(j),u=nt();return e.onBeforeUnmount((function(){n()})),{fronteggLoaded:t,authState:r,fronteggAuth:o,loginWithRedirect:function(){var t;(null===(t=o.router)||void 0===t?void 0:t.currentRoute.path.startsWith(r.routes.hostedLoginRedirectUrl))||(u.dispatch({type:"auth/setState",payload:{isLoading:!0}}),o.loginActions.requestHostedLoginAuthorize())},loadEntitlements:i}},t.useFronteggAuthGuard=function(){var t=rt(),n=e.inject(I),r=et(),o=e.inject(R),i=nt(),u=function(){var e,u,a;u=null===(e=t.router)||void 0===e?void 0:e.currentRoute.path,a=r.routes,Object.values(a).filter((function(t){return t!==a.authenticatedUrl})).includes(u)||r.isAuthenticated||r.isLoading||(n.hostedLoginBox?(i.dispatch({type:"auth/setState",payload:{isLoading:!0}}),t.loginActions.requestHostedLoginAuthorize()):o.push(r.routes.loginUrl))};e.onMounted(u),e.onUpdated(u)},t.useFronteggLoaded=Z,t.usePermissionEntitlements=function(t){return e.computed((function(){return o.getPermissionEntitlements(ut(),t)}))},t.useUnsubscribeFronteggStore=tt,Object.defineProperty(t,"__esModule",{value:!0}),t}({},Vue,fronteggRestApi,setValue,fronteggReduxStore,getValue,js);
|
|
16
|
+
function A(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}var S=Symbol("fronteggLoade"),y=Symbol("authState"),O=Symbol("unsubscribeFronteggStore"),E=Symbol("fronteggAuth"),j=Symbol("loadEntitlements"),R=Symbol("router"),I=Symbol("fronteggOptions"),P=Symbol("fronteggStore"),T=function(t,e){var n;return t.FRONTEGG_STORE_KEY=null!==(n=t.FRONTEGG_STORE_KEY)&&void 0!==n?n:e},w=function(t){return t.FRONTEGG_STORE_KEY},U=function(t){return t.FRONTEGG_REDUX_BINDINGS},F=function(){function t(){d(this,t)}return h(t,null,[{key:"getInstance",value:function(){return t.instance||(t.instance=new t),t.instance}},{key:"setStore",value:function(e){t.getInstance().store=e}},{key:"getStore",value:function(){return t.getInstance().store}},{key:"setBasename",value:function(e){t.getInstance().baseName=e}},{key:"getBasename",value:function(){return t.getInstance().baseName}}]),t}(),L=function(t){return function(e){return f.default(e,t)}},k=function(t,e,n){return function(){var r,o=this,i=Object.keys(e),u=f.default(w(o).getState(),t),a=function(t,e,n,r,o){return n.reduce((function(n,i){return Object.assign({},n,v({},e,Object.assign(Object.assign({},n[e]),v({},i,function(t,e,n){return"function"==typeof e?e.bind(t):n(e)}(t,r[i],o)))))}),U(t)||{})}(o,t,i,e,n);return r=a,o.FRONTEGG_REDUX_BINDINGS=r,i.reduce((function(t,r){return Object.assign({},t,v({},r,function(t,e,n,r){return"function"==typeof e?e.call(t,r):n(e)(r)}(o,e[r],n,u)))}),{})}},_=function(){function t(){d(this,t)}return h(t,null,[{key:"getInstance",value:function(){return t.instance||(t.instance=new t),t.instance}},{key:"setActions",value:function(e){t.getInstance().actions=e}},{key:"getAction",value:function(e){return t.getInstance().actions[e]}}]),t}(),N=function(){function t(e){var n=this;d(this,t);var r=e.router,i=A(e,["router"]);this.state=o.authInitialState,this.userRef=void 0,this.init=function(t,e){n.store=e,Object.entries({loginActions:o.loginActions,socialLoginsActions:o.socialLoginsActions,activateAccountActions:o.activateAccountActions,acceptInvitationActions:o.acceptInvitationActions,forgotPasswordActions:o.forgotPasswordActions,signUpActions:o.signUpActions,profileActions:o.profileActions,ssoActions:o.ssoActions,mfaActions:o.mfaActions,teamActions:o.teamActions,apiTokensActions:o.apiTokensActions,securityPolicyActions:o.securityPolicyActions,tenantsActions:o.tenantsActions}).forEach((function(t){var e=p(t,2),r=e[0],i=e[1];Object.assign(n,v({},r,o.bindActionCreators(i,n.store.dispatch)))}));var r=o.bindActionCreators(o.authActions,n.store.dispatch);_.setActions(r),t.hostedLoginBox||n.store.subscribe(n.storeSubscriber)},this.storeSubscriber=function(){n.state=n.store.getState().auth;var t=!1;n.state.user!==n.userRef&&(n.userRef=n.state.user,t=!0),n.state.isAuthenticated!==n.isAuthenticatedRef&&(n.isAuthenticatedRef=n.state.isAuthenticated,t=!0),n.userRef&&n.state.isAuthenticated?t&&n.accessTokenUpdater():clearInterval(n.accessTokenUpdaterRef)},this.accessTokenUpdater=function(){var t,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(n.accessTokenUpdaterRef&&clearInterval(n.accessTokenUpdaterRef),e)n.loginActions.requestAuthorize(!0);else if(n.isAuthenticated){var r=1e3*((null===(t=n.user)||void 0===t?void 0:t.expiresIn)||20)*.8;n.accessTokenUpdaterRef=setInterval(n.loginActions.requestAuthorize,r)}},this._routes=Object.assign(Object.assign({},o.authInitialState.routes),i.routes),this.router=r}return h(t,[{key:"loading",get:function(){var t,e;return null===(e=null===(t=this.store)||void 0===t?void 0:t.getState().auth.isLoading)||void 0===e||e}},{key:"routes",get:function(){var t,e;return null!==(e=null===(t=this.store)||void 0===t?void 0:t.getState().auth.routes)&&void 0!==e?e:this._routes}},{key:"isAuthenticated",get:function(){var t,e;return null!==(e=null===(t=this.store)||void 0===t?void 0:t.getState().auth.isAuthenticated)&&void 0!==e&&e}},{key:"user",get:function(){var t;return null===(t=this.store)||void 0===t?void 0:t.getState().auth.user}}]),t}(),G=function(t,e){return function(){var n=v({},null!=e?e:t.substring("auth.".length),(function(t){return t}));return k(t,n,L).bind(this)()}},C=function(t){return G("auth","authState").bind(t)},B=function(t){return G("auth.loginState").bind(t)},x=function(t){return G("auth.acceptInvitationState").bind(t)},H=function(t){return G("auth.activateState").bind(t)},V=function(t){return G("auth.apiTokensState").bind(t)},z=function(t){return G("auth.forgotPasswordState").bind(t)},D=function(t){return G("auth.mfaState").bind(t)},q=function(t){return G("auth.profileState").bind(t)},M=function(t){return G("auth.securityPolicyState").bind(t)},W=function(t){return G("auth.signUpState").bind(t)},$=function(t){return G("auth.socialLoginState").bind(t)},K=function(t){return G("auth.ssoState").bind(t)},Y=function(t){return G("auth.teamState").bind(t)},X=function(t){return G("auth.tenantsState").bind(t)},Q=function(t){Object.assign(t,{mapAuthState:C(t),mapLoginState:B(t),mapAcceptInvitationState:x(t),mapActivateAccountState:H(t),mapApiTokensState:V(t),mapForgotPasswordState:z(t),mapMfaState:D(t),mapProfileState:q(t),mapSecurityPolicyState:M(t),mapSignUpState:W(t),mapSocialLoginState:$(t),mapSsoState:K(t),mapTeamState:Y(t),mapTenantsState:X(t)})},J=function(t){return function(){return _.getAction(t).apply(void 0,arguments)}},Z=function(){return e.inject(S)},tt=function(){return e.inject(O)},et=function(){return e.inject(y)},nt=function(){return e.inject(P)},rt=function(){return e.inject(E)},ot="3.0.6",it="2.6.12",ut=function(){var t,e;return p((t=[n.USE_ENTITLEMENTS_V2_ENDPOINT_FF],e=nt().appName,n.FeatureFlags.getFeatureFlags(t,e)),1)[0]},at=function(t){var n=e.inject(y).user;return{entitlements:null==n?void 0:n.entitlements,attributes:{custom:t,jwt:n},isV2:ut()}},st=null,ct={install:function(t,r){var i,a,s=null!=r?r:{},d=s.router,g=A(s,["router"]),h=(null!=r?r:{}).contextOptions;if(null==h)throw Error("contextOptions must be passed to Vue.use(Frontegg, { /* OPTIONS */ })");h.requestCredentials=null!==(i=h.requestCredentials)&&void 0!==i?i:"include",h.metadataHeaders={framework:"".concat(n.FronteggFrameworks.Vuejs,"@").concat(it),fronteggSdkVersion:"@frontegg/vuejs@".concat(ot)},n.ContextHolder.setContext(h);var v,m=!1,L=!1,k="3"===t.version.charAt(0);k&&(v=e.ref(!1));var _=new Set,G=d&&function(t,e){var r=t.options.base||"";F.setBasename(r);var i=function(n,i){var u=n;u.startsWith(r)&&"/"!==r&&(u=u.substring(r.length-1)),((null==i?void 0:i.preserveQueryParams)||o.isAuthRoute(u,e))&&(u="".concat(u).concat(window.location.search)),(null==i?void 0:i.refresh)?window.location.href=u:(null==i?void 0:i.replace)?t.replace(u):t.push(u)};return n.ContextHolder.setOnRedirectTo(i),i}(d,null===(a=null==r?void 0:r.authOptions)||void 0===a?void 0:a.routes),C=(st=u.initialize(Object.assign(Object.assign({},g),{onRedirectTo:G,basename:null==d?void 0:d.options.base}))).store;F.setStore(C),t.$fronteggApp=st,t.fronteggAuth||(t.fronteggAuth=new N({router:d}),function(t,e){var n;t.fronteggPlugins=null!==(n=t.fronteggPlugins)&&void 0!==n?n:[],t.fronteggPlugins.push(e)}(t,t.fronteggAuth));var B=function(){var e=(t.fronteggPlugins||[]).reduce((function(t,e){return t&&!e.loading}),!0);if(e!==L){L=e,k&&(v.value=e);var n,r=function(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=b(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,u=!0,a=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return u=t.done,t},e:function(t){a=!0,i=t},f:function(){try{u||null==n.return||n.return()}finally{if(a)throw i}}}}(_);try{for(r.s();!(n=r.n()).done;){(0,n.value)()}}catch(t){r.e(t)}finally{r.f()}}};null==d||d.getRoutes().map((function(t){var e=t.beforeEnter;t.beforeEnter=function(t,n,r){var o=function(){e?e(t,n,r):r()};if(L)o();else var i=setInterval((function(){B(),L&&(clearInterval(i),o())}),1)}}));var x,H=setInterval((function(){B(),L&&clearInterval(H)}),10),V=function(e){var n,o;if(e.authorizedContent&&(n=e.$route.path,o=t.fronteggAuth.routes,!Object.values(o).filter((function(t){return t!=o.authenticatedUrl})).includes(n))&&(!t.fronteggAuth.loading&&!t.fronteggAuth.isAuthenticated))if(null==r?void 0:r.hostedLoginBox)t.fronteggAuth.loginActions.requestHostedLoginAuthorize();else{var i=t.fronteggAuth.routes.loginUrl;e.$router.push(i)}};function z(){this.$route.path.startsWith(t.fronteggAuth.routes.hostedLoginRedirectUrl)||(C.dispatch({type:"auth/setState",payload:{isLoading:!0}}),t.fronteggAuth.loginActions.requestHostedLoginAuthorize())}m||(x=t,m=!0,(t.fronteggPlugins||[]).forEach((function(t){return t.init(g,C)})),T(x,C),x.fronteggAuth=t.fronteggAuth,Q(x));var D=st.loadEntitlements.bind(st);if(k){t.provide(S,v);var q=function(t){var n=t.getState(),r=e.reactive(Object.assign({},n.auth)),o=t.subscribe((function(){var e=t.getState().auth;Object.entries(e).forEach((function(t){var n=p(t,2),o=n[0],i=n[1];r[o]!==e[o]&&(r[o]=i)}))}));return{authState:r,unsubscribe:o}}(C),M=q.authState,W=q.unsubscribe,$=e.reactive(Object.assign({},t.fronteggAuth));t.provide(y,M),t.provide(O,W),t.provide(E,$),t.provide(R,d),t.provide(I,r),t.provide(P,C),t.provide(j,D)}t.mixin({data:function(){return{fronteggLoaded:L}},beforeCreate:function(){T(this,C),this.fronteggAuth=t.fronteggAuth,this.loginWithRedirect=z.bind(this),this.getFeatureEntitlements=function(t,e,n){return st.getFeatureEntitlements(e,n)},this.getPermissionEntitlements=function(t,e,n){return st.getPermissionEntitlements(e,n)},this.getEntitlements=function(t,e,n){return st.getEntitlements(e,n)},this.loadEntitlements=D,Q(this)},updated:function(){V(this)},mounted:function(){V(this)},created:function(){var t,e;U(this)&&function(t,e){t.FRONTEGG_UNSUBSCRIBE=e}(this,C.subscribe((t=this,e=U(this),function(){var n=w(t).getState();Object.keys(e).forEach((function(r){Object.keys(e[r]).forEach((function(o){var i=e[r][o];if(i){var u,a=i(f.default(n,r)),s=Object.assign({},c);s.default&&(u=2),s.version&&"3"===s.version[0]&&(u=3),3===u&&l.default(t.$data,o,a),2===u&&l.default(t._data,o,a)}}))}))}))),function(t,e){t.FRONTEGG_LOADER_UNSUBSCRIBE=e}(this,function(t){var e=function(){t.fronteggLoaded=L};return _.add(e),function(){return _.delete(e)}}(this))},beforeDestroy:function(){!function(t){var e;null===(e=t.FRONTEGG_UNSUBSCRIBE)||void 0===e||e.call(t)}(this),function(t){var e;null===(e=t.FRONTEGG_LOADER_UNSUBSCRIBE)||void 0===e||e.call(t)}(this)}})}};return Object.defineProperty(t,"ContextHolder",{enumerable:!0,get:function(){return n.ContextHolder}}),Object.defineProperty(t,"AdminPortal",{enumerable:!0,get:function(){return u.AdminPortal}}),t.Frontegg=ct,t.closeAdminPortal=function(){return u.AdminPortal.hide()},t.isAuthenticatedGuard=function(t,e,n){var r,o,i=function(){var e,r=F.getStore().getState().auth;if(r.isAuthenticated)n();else{var o=null!==(e=F.getBasename())&&void 0!==e?e:"",i=o.endsWith("/")?o.substring(0,o.length-1):"";localStorage.setItem("FRONTEGG_AFTER_AUTH_REDIRECT_URL","".concat(i).concat(t.fullPath)),n({path:r.routes.loginUrl,replace:!0})}},u=null===(o=null===(r=F.getStore())||void 0===r?void 0:r.getState())||void 0===o?void 0:o.auth;if(!u||(null==u?void 0:u.isLoading))var a=setInterval((function(){var t,e;(u=null===(e=null===(t=F.getStore())||void 0===t?void 0:t.getState())||void 0===e?void 0:e.auth)&&!(null==u?void 0:u.isLoading)&&(clearInterval(a),i())}),1);else i()},t.mapAcceptInvitationActions=function(t){return J(t)},t.mapActivateAccountActions=function(t){return J(t)},t.mapApiTokensActions=function(t){return J(t)},t.mapAuthActions=function(t){return J(t)},t.mapForgotPasswordActions=function(t){return J(t)},t.mapLoginActions=function(t){return J("loginWithRedirect"===t?"requestHostedLoginAuthorize":t)},t.mapMfaActions=function(t){return J(t)},t.mapProfileActions=function(t){return J(t)},t.mapSecurityPolicyActions=function(t){return J(t)},t.mapSignupActions=function(t){return J(t)},t.mapSocialLoginActions=function(t){return J(t)},t.mapSsoActions=function(t){return J(t)},t.mapTeamActions=function(t){return J(t)},t.openAdminPortal=function(){return u.AdminPortal.show()},t.useAuthState=et,t.useEntitlements=function(t,n){return e.computed((function(){var e=at(n),r=e.entitlements,i=e.attributes,u=e.isV2;return o.getEntitlements(r,t,i,u)}))},t.useFeatureEntitlements=function(t,n){return e.computed((function(){var e=at(n),r=e.entitlements,i=e.attributes,u=e.isV2;return o.getFeatureEntitlements(r,t,i,u)}))},t.useFrontegg=function(){var t=Z(),n=tt(),r=et(),o=rt(),i=e.inject(j),u=nt();return e.onBeforeUnmount((function(){n()})),{fronteggLoaded:t,authState:r,fronteggAuth:o,loginWithRedirect:function(){var t;(null===(t=o.router)||void 0===t?void 0:t.currentRoute.path.startsWith(r.routes.hostedLoginRedirectUrl))||(u.dispatch({type:"auth/setState",payload:{isLoading:!0}}),o.loginActions.requestHostedLoginAuthorize())},loadEntitlements:i}},t.useFronteggAuthGuard=function(){var t=rt(),n=e.inject(I),r=et(),o=e.inject(R),i=nt(),u=function(){var e,u,a;u=null===(e=t.router)||void 0===e?void 0:e.currentRoute.path,a=r.routes,Object.values(a).filter((function(t){return t!==a.authenticatedUrl})).includes(u)||r.isAuthenticated||r.isLoading||(n.hostedLoginBox?(i.dispatch({type:"auth/setState",payload:{isLoading:!0}}),t.loginActions.requestHostedLoginAuthorize()):o.push(r.routes.loginUrl))};e.onMounted(u),e.onUpdated(u)},t.useFronteggLoaded=Z,t.usePermissionEntitlements=function(t,n){return e.computed((function(){var e=at(n),r=e.entitlements,i=e.attributes,u=e.isV2;return o.getPermissionEntitlements(r,t,i,u)}))},t.useUnsubscribeFronteggStore=tt,Object.defineProperty(t,"__esModule",{value:!0}),t}({},Vue,fronteggRestApi,setValue,fronteggReduxStore,getValue,js);
|
package/dist/index.ssr.js
CHANGED
|
@@ -653,6 +653,12 @@ var useFronteggAuth = function useFronteggAuth() {
|
|
|
653
653
|
var useLoadEntitlements = function useLoadEntitlements() {
|
|
654
654
|
return Vue.inject(loadEntitlementsKey);
|
|
655
655
|
};
|
|
656
|
+
var useFeatureFlag = function useFeatureFlag(keys) {
|
|
657
|
+
var _useFronteggStore = useFronteggStore(),
|
|
658
|
+
appName = _useFronteggStore.appName;
|
|
659
|
+
|
|
660
|
+
return restApi.FeatureFlags.getFeatureFlags(keys, appName);
|
|
661
|
+
};
|
|
656
662
|
var useFrontegg = function useFrontegg() {
|
|
657
663
|
var fronteggLoaded = useFronteggLoaded();
|
|
658
664
|
var unsubscribeFronteggStore = useUnsubscribeFronteggStore();
|
|
@@ -892,46 +898,96 @@ var VuePkg = {
|
|
|
892
898
|
homepage: homepage,
|
|
893
899
|
devDependencies: devDependencies,
|
|
894
900
|
config: config
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
var _a;
|
|
901
|
+
};/**
|
|
902
|
+
* @returns user state
|
|
903
|
+
*/
|
|
899
904
|
|
|
905
|
+
var useGetUserState = function useGetUserState() {
|
|
900
906
|
var authState = Vue.inject(authStateKey);
|
|
901
|
-
return
|
|
907
|
+
return authState.user;
|
|
908
|
+
};
|
|
909
|
+
/**
|
|
910
|
+
* @returns true when need to use entitlements V2 API
|
|
911
|
+
*/
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
var useIsV2API = function useIsV2API() {
|
|
915
|
+
var _useFeatureFlag = useFeatureFlag([restApi.USE_ENTITLEMENTS_V2_ENDPOINT_FF]),
|
|
916
|
+
_useFeatureFlag2 = _slicedToArray(_useFeatureFlag, 1),
|
|
917
|
+
useEntitlementsV2 = _useFeatureFlag2[0];
|
|
918
|
+
|
|
919
|
+
return useEntitlementsV2;
|
|
902
920
|
};
|
|
903
921
|
/**
|
|
904
|
-
|
|
922
|
+
* @param customAttributes consumer attributes
|
|
923
|
+
* @returns is entitled query data including: entitltments state, final attributes (consumer and frontegg) and API version to use
|
|
924
|
+
*/
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
var useEntitlementsQueryData = function useEntitlementsQueryData(customAttributes) {
|
|
928
|
+
var user = useGetUserState();
|
|
929
|
+
var entitlements = user === null || user === void 0 ? void 0 : user.entitlements;
|
|
930
|
+
var isV2 = useIsV2API();
|
|
931
|
+
var attributes = {
|
|
932
|
+
custom: customAttributes,
|
|
933
|
+
jwt: user
|
|
934
|
+
};
|
|
935
|
+
return {
|
|
936
|
+
entitlements: entitlements,
|
|
937
|
+
attributes: attributes,
|
|
938
|
+
isV2: isV2
|
|
939
|
+
};
|
|
940
|
+
};
|
|
941
|
+
/**
|
|
942
|
+
@param key feature key
|
|
943
|
+
@param customAttributes consumer attributes
|
|
905
944
|
@returns if the user is entitled to the given feature. Attaching the justification if not
|
|
906
945
|
@throws when entitlement is not enabled via frontegg options
|
|
907
946
|
*/
|
|
908
947
|
|
|
909
948
|
|
|
910
|
-
var useFeatureEntitlements = function useFeatureEntitlements(key) {
|
|
949
|
+
var useFeatureEntitlements = function useFeatureEntitlements(key, customAttributes) {
|
|
911
950
|
return Vue.computed(function () {
|
|
912
|
-
|
|
951
|
+
var _useEntitlementsQuery = useEntitlementsQueryData(customAttributes),
|
|
952
|
+
entitlements = _useEntitlementsQuery.entitlements,
|
|
953
|
+
attributes = _useEntitlementsQuery.attributes,
|
|
954
|
+
isV2 = _useEntitlementsQuery.isV2;
|
|
955
|
+
|
|
956
|
+
return reduxStore.getFeatureEntitlements(entitlements, key, attributes, isV2);
|
|
913
957
|
});
|
|
914
958
|
};
|
|
915
959
|
/**
|
|
916
|
-
@param key permission
|
|
960
|
+
@param key permission key
|
|
961
|
+
@param customAttributes consumer attributes
|
|
917
962
|
@returns if the user is entitled to the given permission. Attaching the justification if not
|
|
918
963
|
@throws when entitlement is not enabled via frontegg options
|
|
919
964
|
*/
|
|
920
965
|
|
|
921
|
-
var usePermissionEntitlements = function usePermissionEntitlements(key) {
|
|
966
|
+
var usePermissionEntitlements = function usePermissionEntitlements(key, customAttributes) {
|
|
922
967
|
return Vue.computed(function () {
|
|
923
|
-
|
|
968
|
+
var _useEntitlementsQuery2 = useEntitlementsQueryData(customAttributes),
|
|
969
|
+
entitlements = _useEntitlementsQuery2.entitlements,
|
|
970
|
+
attributes = _useEntitlementsQuery2.attributes,
|
|
971
|
+
isV2 = _useEntitlementsQuery2.isV2;
|
|
972
|
+
|
|
973
|
+
return reduxStore.getPermissionEntitlements(entitlements, key, attributes, isV2);
|
|
924
974
|
});
|
|
925
975
|
};
|
|
926
976
|
/**
|
|
927
977
|
@param entitledToOptions - including permission or feature key
|
|
978
|
+
@param customAttributes consumer attributes
|
|
928
979
|
@returns if the user is entitled to the given permission or feature. Attaching the justification if not
|
|
929
980
|
@throws when entitlement is not enabled via frontegg options
|
|
930
981
|
*/
|
|
931
982
|
|
|
932
|
-
var useEntitlements = function useEntitlements(entitledToOptions) {
|
|
983
|
+
var useEntitlements = function useEntitlements(entitledToOptions, customAttributes) {
|
|
933
984
|
return Vue.computed(function () {
|
|
934
|
-
|
|
985
|
+
var _useEntitlementsQuery3 = useEntitlementsQueryData(customAttributes),
|
|
986
|
+
entitlements = _useEntitlementsQuery3.entitlements,
|
|
987
|
+
attributes = _useEntitlementsQuery3.attributes,
|
|
988
|
+
isV2 = _useEntitlementsQuery3.isV2;
|
|
989
|
+
|
|
990
|
+
return reduxStore.getEntitlements(entitlements, entitledToOptions, attributes, isV2);
|
|
935
991
|
});
|
|
936
992
|
};var isAuthenticatedGuard = function isAuthenticatedGuard(_to, _from, next) {
|
|
937
993
|
var _a, _b;
|
|
@@ -1185,18 +1241,18 @@ var Frontegg = {
|
|
|
1185
1241
|
beforeCreate: function beforeCreate() {
|
|
1186
1242
|
setStoreKey(this, store);
|
|
1187
1243
|
this.fronteggAuth = Vue$1.fronteggAuth;
|
|
1188
|
-
this.loginWithRedirect = loginWithRedirect.bind(this); //
|
|
1244
|
+
this.loginWithRedirect = loginWithRedirect.bind(this); // _user was added for to make the computed property reactive, then it will get updated
|
|
1189
1245
|
|
|
1190
|
-
this.getFeatureEntitlements = function (
|
|
1191
|
-
return fronteggApp.getFeatureEntitlements(key);
|
|
1246
|
+
this.getFeatureEntitlements = function (_user, key, customAttributes) {
|
|
1247
|
+
return fronteggApp.getFeatureEntitlements(key, customAttributes);
|
|
1192
1248
|
};
|
|
1193
1249
|
|
|
1194
|
-
this.getPermissionEntitlements = function (
|
|
1195
|
-
return fronteggApp.getPermissionEntitlements(key);
|
|
1250
|
+
this.getPermissionEntitlements = function (_user, key, customAttributes) {
|
|
1251
|
+
return fronteggApp.getPermissionEntitlements(key, customAttributes);
|
|
1196
1252
|
};
|
|
1197
1253
|
|
|
1198
|
-
this.getEntitlements = function (
|
|
1199
|
-
return fronteggApp.getEntitlements(entitledToOptions);
|
|
1254
|
+
this.getEntitlements = function (_user, entitledToOptions, customAttributes) {
|
|
1255
|
+
return fronteggApp.getEntitlements(entitledToOptions, customAttributes);
|
|
1200
1256
|
};
|
|
1201
1257
|
|
|
1202
1258
|
this.loadEntitlements = loadEntitlements;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EnhancedStore } from '@reduxjs/toolkit';
|
|
2
2
|
import { Unsubscribe } from 'redux';
|
|
3
3
|
import { Entitlement, User } from '@frontegg/redux-store';
|
|
4
|
-
import { EntitledToOptions, LoadEntitlementsCallback } from '@frontegg/types';
|
|
4
|
+
import { EntitledToOptions, LoadEntitlementsCallback, CustomAttributes } from '@frontegg/types';
|
|
5
5
|
import { FronteggPluginService } from './interfaces';
|
|
6
6
|
declare module 'vue/types/vue' {
|
|
7
7
|
interface VueConstructor {
|
|
@@ -17,23 +17,26 @@ declare module 'vue/types/vue' {
|
|
|
17
17
|
fronteggLoaded: boolean;
|
|
18
18
|
loginWithRedirect: () => void;
|
|
19
19
|
/**
|
|
20
|
-
@param key feature
|
|
20
|
+
@param key feature key
|
|
21
|
+
@param customAttributes consumer attributes
|
|
21
22
|
@returns if the user is entitled to the given feature. Attaching the justification if not
|
|
22
23
|
@throws when entitlement is not enabled via frontegg options
|
|
23
24
|
*/
|
|
24
|
-
getFeatureEntitlements: (
|
|
25
|
+
getFeatureEntitlements: (_user: User | undefined | null, key: string, customAttributes?: CustomAttributes) => Entitlement;
|
|
25
26
|
/**
|
|
26
|
-
@param key permission
|
|
27
|
+
@param key permission key
|
|
28
|
+
@param customAttributes consumer attributes
|
|
27
29
|
@returns if the user is entitled to the given permission. Attaching the justification if not
|
|
28
30
|
@throws when entitlement is not enabled via frontegg options
|
|
29
31
|
*/
|
|
30
|
-
getPermissionEntitlements: (
|
|
32
|
+
getPermissionEntitlements: (_user: User | undefined | null, key: string, customAttributes?: CustomAttributes) => Entitlement;
|
|
31
33
|
/**
|
|
32
34
|
@param entitledToOptions - including permission or feature key
|
|
35
|
+
@param customAttributes consumer attributes
|
|
33
36
|
@returns if the user is entitled to the given permission or feature. Attaching the justification if not
|
|
34
37
|
@throws when entitlement is not enabled via frontegg options
|
|
35
38
|
*/
|
|
36
|
-
getEntitlements: (
|
|
39
|
+
getEntitlements: (_user: User | undefined | null, entitledToOptions: EntitledToOptions, customAttributes?: CustomAttributes) => Entitlement;
|
|
37
40
|
/**
|
|
38
41
|
* Load entitlements
|
|
39
42
|
* @param callback called on request completed with true if succeeded, false if failed
|