@smart-cloud/gatey-core 1.0.10 → 1.0.11
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/index.cjs +1 -1
- package/dist/index.d.cts +1 -10
- package/dist/index.d.ts +1 -10
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var P=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var H=(e,t)=>{for(var n in t)P(e,n,{get:t[n],enumerable:!0})},$=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Y(t))!q.call(e,r)&&r!==n&&P(e,r,{get:()=>t[r],enumerable:!(o=J(t,r))||o.enumerable});return e};var Q=e=>$(P({},"__esModule",{value:!0}),e);var ce={};H(ce,{TEXT_DOMAIN:()=>D,clearMfaPreferences:()=>O,configureAmplify:()=>A,getAmplifyConfig:()=>h,getGroups:()=>C,getMfaPreferences:()=>w,getPreferredRole:()=>_,getRoles:()=>F,getScopes:()=>L,getStoreDispatch:()=>l,getStoreSelect:()=>
|
|
1
|
+
"use strict";var P=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var H=(e,t)=>{for(var n in t)P(e,n,{get:t[n],enumerable:!0})},$=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Y(t))!q.call(e,r)&&r!==n&&P(e,r,{get:()=>t[r],enumerable:!(o=J(t,r))||o.enumerable});return e};var Q=e=>$(P({},"__esModule",{value:!0}),e);var ce={};H(ce,{TEXT_DOMAIN:()=>D,clearMfaPreferences:()=>O,configureAmplify:()=>A,getAmplifyConfig:()=>h,getGroups:()=>C,getMfaPreferences:()=>w,getPreferredRole:()=>_,getRoles:()=>F,getScopes:()=>L,getStoreDispatch:()=>l,getStoreSelect:()=>x,getUserAttributes:()=>R,isAuthenticated:()=>N,isInGroup:()=>G,loadAuthSession:()=>p,loadMFAPreferences:()=>I,loadUserAttributes:()=>E,login:()=>K,logout:()=>S,observeStore:()=>f,store:()=>j});module.exports=Q(ce);var s=require("aws-amplify/api");var U=require("aws-amplify"),i=require("aws-amplify/auth");var k=require("aws-amplify/auth"),T=require("aws-amplify/utils"),c=require("@wordpress/data"),v=require("@smart-cloud/wpsuite-core");var y="gatey_account",D="gatey";var b;typeof WpSuite<"u"?b=WpSuite.siteSettings:b={};var m=e=>{e?.username?window.localStorage.setItem(y,JSON.stringify(e)):window.localStorage.removeItem(y)},d=async e=>{let t=JSON.parse(window.localStorage.getItem(y)??"{}"),n=!1;if(t?.username)try{let o=await(0,k.fetchAuthSession)();o?.tokens?.accessToken?.payload?.exp&&o.tokens.accessToken.payload.exp>new Date().getTime()/1e3&&(n=!0)}catch(o){console.error(o)}else try{t=await V(!1),t?.username&&(m(t),t.loaded=!0,n=!0)}catch(o){console.error(o)}return!n&&t?.username&&(m({}),Gatey.cognito.store.then(async o=>{await S(e?.signOutHook),l(o).clearAccount()})),t},Z=async e=>{let t=window.location.hostname.toLowerCase().split(":")[0],n=Gatey.settings?.secondaryUserPoolDomains&&t.toLowerCase().match(Gatey.settings.secondaryUserPoolDomains.toLowerCase())&&Gatey.settings?.userPoolConfigurations.secondary?.Auth?.Cognito?.userPoolId?Gatey.settings?.userPoolConfigurations.secondary:Gatey.settings?.userPoolConfigurations.default,o={Auth:{Cognito:{userPoolClientId:"",userPoolId:"",identityPoolId:"",...n.Auth?.Cognito,loginWith:{oauth:{domain:"",scopes:[],responseType:"code",...n.Auth?.Cognito?.loginWith?.oauth,redirectSignIn:[window.location.origin+Gatey?.settings?.signInPage],redirectSignOut:[window.location.origin+Gatey?.settings?.signInPage]}}}},API:{...n.API,REST:{...n.API?.REST,admin:{endpoint:Gatey.restUrl}}}},r=e?.apiConfigurations?.secondary?.domains&&t.toLowerCase().match(e.apiConfigurations.secondary?.domains.toLowerCase())&&e.apiConfigurations?.secondary?.apis?.length?e.apiConfigurations.secondary:e?.apiConfigurations?.default;r?.apis?.forEach(u=>{let g=o.API?.REST;g&&(g[u.name]={endpoint:u.endpoint,region:u.region})}),A(o,{API:{REST:{headers:async u=>{let g=r?.apis?.find(a=>a.name===u.apiName);if(u.apiName==="admin"||g?.authorization==="ID_TOKEN"||g?.authorization==="ACCESS_TOKEN")try{let a=await p();if(a?.tokens?.idToken&&a?.tokens?.accessToken)return{Authorization:`Bearer ${u.apiName==="admin"||g?.authorization==="ID_TOKEN"?a.tokens.idToken.toString():a.tokens.accessToken.toString()}`}}catch(a){console.error(a),Gatey.cognito.store.then(X=>{l(X).clearAccount()})}return{}}}}})},ee=async()=>{let e=null;return Gatey.settings.customTranslationsUrl&&(e=await fetch(Gatey.settings.customTranslationsUrl+(Gatey.settings.customTranslationsUrl.includes("?")?"&":"?")+"t="+b.lastUpdate).then(t=>t.ok?t.text():null).then(t=>t?JSON.parse(t):null).catch(()=>null)),e??null},te=async()=>{let e=await(0,v.getConfig)("gatey");Z(e);let t=window.location.hostname.toLowerCase().split(":")[0],n=e?.apiConfigurations?.secondary?.domains&&t.toLowerCase().match(e.apiConfigurations.secondary?.domains.toLowerCase())&&e.apiConfigurations?.secondary?.apis?.length?e.apiConfigurations.secondary:e?.apiConfigurations?.default,o=await d(n),r=await ee();return{config:e,amplifyConfig:{},account:o,signedIn:!!o?.username&&!o.loaded,nextUrl:void 0,language:void 0,direction:void 0,customTranslations:r,reloadAuthSession:0,reloadUserAttributes:0,reloadMFAPreferences:0}},ne={setAmplifyConfig(e){return{type:"SET_AMPLIFY_CONFIG",amplifyConfig:e}},setAccount(e){return{type:"SET_ACCOUNT",account:e}},clearAccount(){return{type:"CLEAR_ACCOUNT"}},setSignedIn(e){return{type:"SET_SIGNED_IN",signedIn:e}},setNextUrl(e){return{type:"SET_NEXT_URL",nextUrl:e}},setLanguage(e){return!e||e==="system"?T.I18n.setLanguage(""):T.I18n.setLanguage(e),{type:"SET_LANGUAGE",language:e}},setDirection(e){return{type:"SET_DIRECTION",direction:e}},reloadAuthSession(){return{type:"RELOAD_AUTH_SESSION"}},reloadUserAttributes(){return{type:"RELOAD_USER_ATTRIBUTES"}},reloadMFAPreferences(){return{type:"RELOAD_MFA_PREFERENCE"}}},oe={getAmplifyConfig(e){return e.amplifyConfig},getAccount(e){return e.account},getNextUrl(e){return e.nextUrl},isSignedIn(e){return e.signedIn},getConfig(e){return e.config},getCustomTranslations(e){return e.customTranslations},getLanguage(e){return e.language},getDirection(e){return e.direction},getState(e){return e}},re={},l=e=>(0,c.dispatch)(e),x=e=>(0,c.select)(e),W=async()=>{let e=await te(),t=(0,c.createReduxStore)("wpsuite/gatey",{reducer(n=e,o){switch(o.type){case"SET_AMPLIFY_CONFIG":return{...n,amplifyConfig:o.amplifyConfig};case"SET_ACCOUNT":return m(o.account),{...n,account:o.account};case"CLEAR_ACCOUNT":return m({}),{...n,account:{}};case"RELOAD_AUTH_SESSION":{let r=Math.random();return{...n,reloadAuthSession:n.reloadAuthSession!==r?r:r+1}}case"RELOAD_USER_ATTRIBUTES":{let r=Math.random();return{...n,reloadUserAttributes:n.reloadUserAttributes!==r?r:r+1}}case"RELOAD_MFA_PREFERENCE":{let r=Math.random();return{...n,reloadMFAPreferences:n.reloadMFAPreferences!==r?r:r+1}}case"SET_SIGNED_IN":return{...n,signedIn:o.signedIn};case"SET_NEXT_URL":return{...n,nextUrl:o.nextUrl};case"SET_LANGUAGE":return{...n,language:o.language};case"SET_DIRECTION":return{...n,direction:o.direction}}return n},actions:ne,selectors:oe,resolvers:re});return(0,c.register)(t),t},f=(e,t,n)=>{let o;function r(){let u=x(e).getState(),g=t(u);if(g!==o){let a=o;o=g,n(o,a)}}let M=(0,c.subscribe)(r,e);return r(),M};var h=()=>U.Amplify.getConfig(),A=(e,t)=>{U.Amplify.configure(e,t)},p=e=>(0,i.fetchAuthSession)(e),E=()=>(0,i.fetchUserAttributes)(),I=()=>(0,i.fetchMFAPreference)(),V=async(e=!0)=>{let t=e?await d():{};if(t?.username)return t;try{if((await(0,i.fetchAuthSession)()).tokens)return{username:(await(0,i.getCurrentUser)()).username,userAttributes:await E(),mfaPreferences:await I()}}catch(n){console.error(n);try{await(0,i.signOut)()}catch{}}return{}},O=async()=>{await(0,i.updateMFAPreference)({totp:"DISABLED"})},z=()=>d().then(e=>e?.username),R=()=>d().then(e=>e?.userAttributes),w=()=>d().then(e=>e?.mfaPreferences),N=()=>d().then(e=>!!e?.username),G=e=>C().then(t=>t?.includes(e)||!1),C=()=>p().then(e=>e.tokens?.idToken?.payload["cognito:groups"]instanceof Array?e.tokens.idToken.payload["cognito:groups"].map(t=>t):[]).catch(e=>{console.error(e)}),F=async()=>p().then(e=>e.tokens?.idToken?.payload["cognito:roles"]instanceof Array?e.tokens.idToken.payload["cognito:roles"].map(t=>t).map(t=>t.substring(t.indexOf("/")+1)):[]).catch(e=>{console.error(e)}),_=async()=>p().then(e=>{if(!e.tokens?.idToken?.payload["cognito:preferred_role"])return;let t=e.tokens.idToken.payload["cognito:preferred_role"];return t.substring(t.indexOf("/")+1)}).catch(e=>{console.error(e)}),L=()=>p().then(e=>e.tokens?.accessToken.payload.scope?.split(" ")??[]).catch(e=>{console.error(e)}),K=async e=>{let t;return Gatey.settings.integrateWpLogin&&Gatey.restUrl?.startsWith("http")&&(t=await Gatey.cognito.post({apiName:"admin",path:"/login"}).response.then(o=>o.body.json()).then(o=>{if(o instanceof Object&&"redirect"in o)return o?.redirect}).catch(o=>{console.error(o)})),e&&await Gatey.cognito.get({apiName:e.apiName,path:e.path,options:e.options}).response.catch(n=>console.error(n)),Gatey.settings.redirectSignIn??t},S=async e=>{let t;Gatey.settings.integrateWpLogin&&(t=await Gatey.cognito.get({apiName:"admin",path:"/logout"}).response.then(n=>n.body.json()).then(n=>{if(n instanceof Object&&"redirect"in n)return n?.redirect}).catch(n=>{console.error(n)})),e&&await Gatey.cognito.get({apiName:e.apiName,path:e.path,options:e.options}).response.catch(n=>console.error(n));try{await(0,i.signOut)()}catch{}return Gatey.settings.redirectSignOut??t};var ie=()=>{Gatey.cognito.store.then(e=>{f(e,t=>t.nextUrl,async t=>{t&&window.location.assign(t)}),l(e).clearAccount()})},se=e=>{Gatey.cognito.store.then(t=>{l(t).setLanguage(e??"en")})},ae=e=>{Gatey.cognito.store.then(t=>{l(t).setDirection(e??"auto")})};var B=!!Gatey.cognito?.store,j=Gatey.cognito?.store??W();B||(Gatey.cognito={store:j,observeStore:f,setLanguage:se,setDirection:ae,getAmplifyConfig:h,isAuthenticated:N,isInGroup:G,getUsername:z,getUserAttributes:R,getMfaPreferences:w,clearMfaPreferences:O,getGroups:C,getRoles:F,getPreferredRole:_,getScopes:L,signOut:ie,get:s.get,post:s.post,put:s.put,del:s.del,head:s.head,patch:s.patch});B=!0;0&&(module.exports={TEXT_DOMAIN,clearMfaPreferences,configureAmplify,getAmplifyConfig,getGroups,getMfaPreferences,getPreferredRole,getRoles,getScopes,getStoreDispatch,getStoreSelect,getUserAttributes,isAuthenticated,isInGroup,loadAuthSession,loadMFAPreferences,loadUserAttributes,login,logout,observeStore,store});
|
package/dist/index.d.cts
CHANGED
|
@@ -171,13 +171,6 @@ interface Settings {
|
|
|
171
171
|
useRecaptchaEnterprise?: boolean;
|
|
172
172
|
enablePoweredBy?: boolean;
|
|
173
173
|
}
|
|
174
|
-
interface SiteSettings {
|
|
175
|
-
accountId?: string;
|
|
176
|
-
siteId?: string;
|
|
177
|
-
lastUpdate?: number;
|
|
178
|
-
subscriber?: boolean;
|
|
179
|
-
siteKey?: string;
|
|
180
|
-
}
|
|
181
174
|
declare const signOut: () => void;
|
|
182
175
|
declare const setLanguage: (language?: string) => void;
|
|
183
176
|
declare const setDirection: (direction?: "ltr" | "rtl" | "auto") => void;
|
|
@@ -211,12 +204,10 @@ interface Cognito {
|
|
|
211
204
|
interface Gatey {
|
|
212
205
|
cognito: Cognito;
|
|
213
206
|
settings: Settings;
|
|
214
|
-
siteSettings: SiteSettings;
|
|
215
207
|
nonce: string;
|
|
216
208
|
restUrl: string;
|
|
217
|
-
uploadUrl: string;
|
|
218
209
|
}
|
|
219
210
|
|
|
220
211
|
declare const store: Promise<Store>;
|
|
221
212
|
|
|
222
|
-
export { type Account, type AuthenticatorConfig, type Cognito, type CustomTranslations, type FormField, Gatey, type RoleMapping, type Settings, type
|
|
213
|
+
export { type Account, type AuthenticatorConfig, type Cognito, type CustomTranslations, type FormField, Gatey, type RoleMapping, type Settings, type State, type Store, type SubscriptionType, TEXT_DOMAIN, clearMfaPreferences, configureAmplify, getAmplifyConfig, getGroups, getMfaPreferences, getPreferredRole, getRoles, getScopes, getStoreDispatch, getStoreSelect, getUserAttributes, isAuthenticated, isInGroup, loadAuthSession, loadMFAPreferences, loadUserAttributes, login, logout, observeStore, store };
|
package/dist/index.d.ts
CHANGED
|
@@ -171,13 +171,6 @@ interface Settings {
|
|
|
171
171
|
useRecaptchaEnterprise?: boolean;
|
|
172
172
|
enablePoweredBy?: boolean;
|
|
173
173
|
}
|
|
174
|
-
interface SiteSettings {
|
|
175
|
-
accountId?: string;
|
|
176
|
-
siteId?: string;
|
|
177
|
-
lastUpdate?: number;
|
|
178
|
-
subscriber?: boolean;
|
|
179
|
-
siteKey?: string;
|
|
180
|
-
}
|
|
181
174
|
declare const signOut: () => void;
|
|
182
175
|
declare const setLanguage: (language?: string) => void;
|
|
183
176
|
declare const setDirection: (direction?: "ltr" | "rtl" | "auto") => void;
|
|
@@ -211,12 +204,10 @@ interface Cognito {
|
|
|
211
204
|
interface Gatey {
|
|
212
205
|
cognito: Cognito;
|
|
213
206
|
settings: Settings;
|
|
214
|
-
siteSettings: SiteSettings;
|
|
215
207
|
nonce: string;
|
|
216
208
|
restUrl: string;
|
|
217
|
-
uploadUrl: string;
|
|
218
209
|
}
|
|
219
210
|
|
|
220
211
|
declare const store: Promise<Store>;
|
|
221
212
|
|
|
222
|
-
export { type Account, type AuthenticatorConfig, type Cognito, type CustomTranslations, type FormField, Gatey, type RoleMapping, type Settings, type
|
|
213
|
+
export { type Account, type AuthenticatorConfig, type Cognito, type CustomTranslations, type FormField, Gatey, type RoleMapping, type Settings, type State, type Store, type SubscriptionType, TEXT_DOMAIN, clearMfaPreferences, configureAmplify, getAmplifyConfig, getGroups, getMfaPreferences, getPreferredRole, getRoles, getScopes, getStoreDispatch, getStoreSelect, getUserAttributes, isAuthenticated, isInGroup, loadAuthSession, loadMFAPreferences, loadUserAttributes, login, logout, observeStore, store };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{del as ie,get as se,head as ae,patch as ce,post as ue,put as ge}from"aws-amplify/api";import{Amplify as
|
|
1
|
+
import{del as ie,get as se,head as ae,patch as ce,post as ue,put as ge}from"aws-amplify/api";import{Amplify as x}from"aws-amplify";import{fetchAuthSession as U,fetchUserAttributes as ee,fetchMFAPreference as te,getCurrentUser as ne,signOut as E,updateMFAPreference as oe}from"aws-amplify/auth";import{fetchAuthSession as V}from"aws-amplify/auth";import{I18n as C}from"aws-amplify/utils";import{createReduxStore as z,dispatch as K,register as B,select as j,subscribe as X}from"@wordpress/data";import{getConfig as J}from"@smart-cloud/wpsuite-core";var l="gatey_account",W="gatey";var f;typeof WpSuite<"u"?f=WpSuite.siteSettings:f={};var p=e=>{e?.username?window.localStorage.setItem(l,JSON.stringify(e)):window.localStorage.removeItem(l)},c=async e=>{let t=JSON.parse(window.localStorage.getItem(l)??"{}"),n=!1;if(t?.username)try{let o=await V();o?.tokens?.accessToken?.payload?.exp&&o.tokens.accessToken.payload.exp>new Date().getTime()/1e3&&(n=!0)}catch(o){console.error(o)}else try{t=await b(!1),t?.username&&(p(t),t.loaded=!0,n=!0)}catch(o){console.error(o)}return!n&&t?.username&&(p({}),Gatey.cognito.store.then(async o=>{await m(e?.signOutHook),u(o).clearAccount()})),t},Y=async e=>{let t=window.location.hostname.toLowerCase().split(":")[0],n=Gatey.settings?.secondaryUserPoolDomains&&t.toLowerCase().match(Gatey.settings.secondaryUserPoolDomains.toLowerCase())&&Gatey.settings?.userPoolConfigurations.secondary?.Auth?.Cognito?.userPoolId?Gatey.settings?.userPoolConfigurations.secondary:Gatey.settings?.userPoolConfigurations.default,o={Auth:{Cognito:{userPoolClientId:"",userPoolId:"",identityPoolId:"",...n.Auth?.Cognito,loginWith:{oauth:{domain:"",scopes:[],responseType:"code",...n.Auth?.Cognito?.loginWith?.oauth,redirectSignIn:[window.location.origin+Gatey?.settings?.signInPage],redirectSignOut:[window.location.origin+Gatey?.settings?.signInPage]}}}},API:{...n.API,REST:{...n.API?.REST,admin:{endpoint:Gatey.restUrl}}}},r=e?.apiConfigurations?.secondary?.domains&&t.toLowerCase().match(e.apiConfigurations.secondary?.domains.toLowerCase())&&e.apiConfigurations?.secondary?.apis?.length?e.apiConfigurations.secondary:e?.apiConfigurations?.default;r?.apis?.forEach(s=>{let a=o.API?.REST;a&&(a[s.name]={endpoint:s.endpoint,region:s.region})}),y(o,{API:{REST:{headers:async s=>{let a=r?.apis?.find(i=>i.name===s.apiName);if(s.apiName==="admin"||a?.authorization==="ID_TOKEN"||a?.authorization==="ACCESS_TOKEN")try{let i=await g();if(i?.tokens?.idToken&&i?.tokens?.accessToken)return{Authorization:`Bearer ${s.apiName==="admin"||a?.authorization==="ID_TOKEN"?i.tokens.idToken.toString():i.tokens.accessToken.toString()}`}}catch(i){console.error(i),Gatey.cognito.store.then(v=>{u(v).clearAccount()})}return{}}}}})},q=async()=>{let e=null;return Gatey.settings.customTranslationsUrl&&(e=await fetch(Gatey.settings.customTranslationsUrl+(Gatey.settings.customTranslationsUrl.includes("?")?"&":"?")+"t="+f.lastUpdate).then(t=>t.ok?t.text():null).then(t=>t?JSON.parse(t):null).catch(()=>null)),e??null},H=async()=>{let e=await J("gatey");Y(e);let t=window.location.hostname.toLowerCase().split(":")[0],n=e?.apiConfigurations?.secondary?.domains&&t.toLowerCase().match(e.apiConfigurations.secondary?.domains.toLowerCase())&&e.apiConfigurations?.secondary?.apis?.length?e.apiConfigurations.secondary:e?.apiConfigurations?.default,o=await c(n),r=await q();return{config:e,amplifyConfig:{},account:o,signedIn:!!o?.username&&!o.loaded,nextUrl:void 0,language:void 0,direction:void 0,customTranslations:r,reloadAuthSession:0,reloadUserAttributes:0,reloadMFAPreferences:0}},$={setAmplifyConfig(e){return{type:"SET_AMPLIFY_CONFIG",amplifyConfig:e}},setAccount(e){return{type:"SET_ACCOUNT",account:e}},clearAccount(){return{type:"CLEAR_ACCOUNT"}},setSignedIn(e){return{type:"SET_SIGNED_IN",signedIn:e}},setNextUrl(e){return{type:"SET_NEXT_URL",nextUrl:e}},setLanguage(e){return!e||e==="system"?C.setLanguage(""):C.setLanguage(e),{type:"SET_LANGUAGE",language:e}},setDirection(e){return{type:"SET_DIRECTION",direction:e}},reloadAuthSession(){return{type:"RELOAD_AUTH_SESSION"}},reloadUserAttributes(){return{type:"RELOAD_USER_ATTRIBUTES"}},reloadMFAPreferences(){return{type:"RELOAD_MFA_PREFERENCE"}}},Q={getAmplifyConfig(e){return e.amplifyConfig},getAccount(e){return e.account},getNextUrl(e){return e.nextUrl},isSignedIn(e){return e.signedIn},getConfig(e){return e.config},getCustomTranslations(e){return e.customTranslations},getLanguage(e){return e.language},getDirection(e){return e.direction},getState(e){return e}},Z={},u=e=>K(e),P=e=>j(e),T=async()=>{let e=await H(),t=z("wpsuite/gatey",{reducer(n=e,o){switch(o.type){case"SET_AMPLIFY_CONFIG":return{...n,amplifyConfig:o.amplifyConfig};case"SET_ACCOUNT":return p(o.account),{...n,account:o.account};case"CLEAR_ACCOUNT":return p({}),{...n,account:{}};case"RELOAD_AUTH_SESSION":{let r=Math.random();return{...n,reloadAuthSession:n.reloadAuthSession!==r?r:r+1}}case"RELOAD_USER_ATTRIBUTES":{let r=Math.random();return{...n,reloadUserAttributes:n.reloadUserAttributes!==r?r:r+1}}case"RELOAD_MFA_PREFERENCE":{let r=Math.random();return{...n,reloadMFAPreferences:n.reloadMFAPreferences!==r?r:r+1}}case"SET_SIGNED_IN":return{...n,signedIn:o.signedIn};case"SET_NEXT_URL":return{...n,nextUrl:o.nextUrl};case"SET_LANGUAGE":return{...n,language:o.language};case"SET_DIRECTION":return{...n,direction:o.direction}}return n},actions:$,selectors:Q,resolvers:Z});return B(t),t},d=(e,t,n)=>{let o;function r(){let s=P(e).getState(),a=t(s);if(a!==o){let i=o;o=a,n(o,i)}}let h=X(r,e);return r(),h};var A=()=>x.getConfig(),y=(e,t)=>{x.configure(e,t)},g=e=>U(e),I=()=>ee(),O=()=>te(),b=async(e=!0)=>{let t=e?await c():{};if(t?.username)return t;try{if((await U()).tokens)return{username:(await ne()).username,userAttributes:await I(),mfaPreferences:await O()}}catch(n){console.error(n);try{await E()}catch{}}return{}},R=async()=>{await oe({totp:"DISABLED"})},w=()=>c().then(e=>e?.username),N=()=>c().then(e=>e?.userAttributes),G=()=>c().then(e=>e?.mfaPreferences),F=()=>c().then(e=>!!e?.username),_=e=>S().then(t=>t?.includes(e)||!1),S=()=>g().then(e=>e.tokens?.idToken?.payload["cognito:groups"]instanceof Array?e.tokens.idToken.payload["cognito:groups"].map(t=>t):[]).catch(e=>{console.error(e)}),L=async()=>g().then(e=>e.tokens?.idToken?.payload["cognito:roles"]instanceof Array?e.tokens.idToken.payload["cognito:roles"].map(t=>t).map(t=>t.substring(t.indexOf("/")+1)):[]).catch(e=>{console.error(e)}),M=async()=>g().then(e=>{if(!e.tokens?.idToken?.payload["cognito:preferred_role"])return;let t=e.tokens.idToken.payload["cognito:preferred_role"];return t.substring(t.indexOf("/")+1)}).catch(e=>{console.error(e)}),D=()=>g().then(e=>e.tokens?.accessToken.payload.scope?.split(" ")??[]).catch(e=>{console.error(e)}),re=async e=>{let t;return Gatey.settings.integrateWpLogin&&Gatey.restUrl?.startsWith("http")&&(t=await Gatey.cognito.post({apiName:"admin",path:"/login"}).response.then(o=>o.body.json()).then(o=>{if(o instanceof Object&&"redirect"in o)return o?.redirect}).catch(o=>{console.error(o)})),e&&await Gatey.cognito.get({apiName:e.apiName,path:e.path,options:e.options}).response.catch(n=>console.error(n)),Gatey.settings.redirectSignIn??t},m=async e=>{let t;Gatey.settings.integrateWpLogin&&(t=await Gatey.cognito.get({apiName:"admin",path:"/logout"}).response.then(n=>n.body.json()).then(n=>{if(n instanceof Object&&"redirect"in n)return n?.redirect}).catch(n=>{console.error(n)})),e&&await Gatey.cognito.get({apiName:e.apiName,path:e.path,options:e.options}).response.catch(n=>console.error(n));try{await E()}catch{}return Gatey.settings.redirectSignOut??t};var le=()=>{Gatey.cognito.store.then(e=>{d(e,t=>t.nextUrl,async t=>{t&&window.location.assign(t)}),u(e).clearAccount()})},pe=e=>{Gatey.cognito.store.then(t=>{u(t).setLanguage(e??"en")})},de=e=>{Gatey.cognito.store.then(t=>{u(t).setDirection(e??"auto")})};var k=!!Gatey.cognito?.store,fe=Gatey.cognito?.store??T();k||(Gatey.cognito={store:fe,observeStore:d,setLanguage:pe,setDirection:de,getAmplifyConfig:A,isAuthenticated:F,isInGroup:_,getUsername:w,getUserAttributes:N,getMfaPreferences:G,clearMfaPreferences:R,getGroups:S,getRoles:L,getPreferredRole:M,getScopes:D,signOut:le,get:se,post:ue,put:ge,del:ie,head:ae,patch:ce});k=!0;export{W as TEXT_DOMAIN,R as clearMfaPreferences,y as configureAmplify,A as getAmplifyConfig,S as getGroups,G as getMfaPreferences,M as getPreferredRole,L as getRoles,D as getScopes,u as getStoreDispatch,P as getStoreSelect,N as getUserAttributes,F as isAuthenticated,_ as isInGroup,g as loadAuthSession,O as loadMFAPreferences,I as loadUserAttributes,re as login,m as logout,d as observeStore,fe as store};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smart-cloud/gatey-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "Login & SSO with Amazon Cognito",
|
|
5
5
|
"author": "Smart Cloud Solutions Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"aws-amplify": "^6.15.8"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@aws-amplify/ui-react": "^6.13.
|
|
33
|
+
"@aws-amplify/ui-react": "^6.13.2",
|
|
34
34
|
"@types/node": "^24.10.1",
|
|
35
35
|
"@typescript-eslint/eslint-plugin": "^8.48.1",
|
|
36
36
|
"@typescript-eslint/parser": "^8.48.1",
|