@smart-cloud/gatey-core 2.0.4 → 2.0.6

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 CHANGED
@@ -1 +1 @@
1
- "use strict";var b=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var Z=(e,t)=>{for(var n in t)b(e,n,{get:t[n],enumerable:!0})},ee=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of $(t))!Q.call(e,o)&&o!==n&&b(e,o,{get:()=>t[o],enumerable:!(r=H(t,o))||r.enumerable});return e};var te=e=>ee(b({},"__esModule",{value:!0}),e);var pe={};Z(pe,{TEXT_DOMAIN:()=>z,clearMfaPreferences:()=>F,configureAmplify:()=>P,getAmplifyConfig:()=>T,getGateyPlugin:()=>u,getGroups:()=>E,getMfaPreferences:()=>L,getPreferredRole:()=>M,getRoles:()=>D,getScopes:()=>W,getStore:()=>p,getStoreDispatch:()=>d,getStoreSelect:()=>I,getUserAttributes:()=>N,initializeGatey:()=>le,isAuthenticated:()=>_,isInGroup:()=>k,loadAuthSession:()=>f,loadMFAPreferences:()=>v,loadUserAttributes:()=>G,login:()=>J,logout:()=>w,observeStore:()=>S,waitForGateyReady:()=>x});module.exports=te(pe);var a=require("aws-amplify/api");function u(){return globalThis.WpSuite?.plugins?.gatey}async function x(e=8e3){let t=u();if(t?.status!=="available"){if(t?.status==="error")throw new Error("Gatey failed");await new Promise((n,r)=>{let o=()=>A(n),y=()=>A(()=>r(new Error("Gatey failed"))),A=c=>{window.removeEventListener("wpsuite:gatey:ready",o),window.removeEventListener("wpsuite:gatey:error",y),s&&clearTimeout(s),c()};window.addEventListener("wpsuite:gatey:ready",o,{once:!0}),window.addEventListener("wpsuite:gatey:error",y,{once:!0});let s=e?window.setTimeout(()=>A(()=>r(new Error("Gatey timeout"))),e):0})}}async function p(e=1e4){await x(e);let n=u()?.cognito?.store;if(!n)throw new Error("Gatey store is not available");return n}var O=require("aws-amplify"),i=require("aws-amplify/auth");var B=require("aws-amplify/auth"),R=require("aws-amplify/utils"),g=require("@wordpress/data"),V=require("@smart-cloud/wpsuite-core");var h="gatey_account",z="gatey";var U;typeof WpSuite<"u"?U=WpSuite.siteSettings:U={};var C=e=>{e?.username?window.localStorage.setItem(h,JSON.stringify(e)):window.localStorage.removeItem(h)},m=async e=>{let t=JSON.parse(window.localStorage.getItem(h)??"{}"),n=!1;if(t?.username)try{let r=await(0,B.fetchAuthSession)();r?.tokens?.accessToken?.payload?.exp&&r.tokens.accessToken.payload.exp>new Date().getTime()/1e3&&(n=!0)}catch(r){console.error(r)}else try{t=await X(!1),t?.username&&(C(t),t.loaded=!0,n=!0)}catch(r){console.error(r)}return!n&&t?.username&&(C({}),p().then(async r=>{await w(e?.signOutHook),d(r).clearAccount()})),t},ne=async e=>{let t=window.location.hostname.toLowerCase().split(":")[0],n=u();if(!n)throw new Error("Gatey plugin is not available");let r=n.settings?.secondaryUserPoolDomains&&t.toLowerCase().match(n.settings.secondaryUserPoolDomains.toLowerCase())&&n.settings?.userPoolConfigurations.secondary?.Auth?.Cognito?.userPoolId?n.settings?.userPoolConfigurations.secondary:n.settings?.userPoolConfigurations.default,o={Auth:{Cognito:{userPoolClientId:"",userPoolId:"",identityPoolId:"",...r.Auth?.Cognito,loginWith:{oauth:{domain:"",scopes:[],responseType:"code",...r.Auth?.Cognito?.loginWith?.oauth,redirectSignIn:[window.location.origin+n.settings?.signInPage],redirectSignOut:[window.location.origin+n.settings?.signInPage]}}}},API:{...r.API,REST:{...r.API?.REST,admin:{endpoint:n.restUrl}}}},y=e?.apiConfigurations?.secondary?.domains&&t.toLowerCase().match(e.apiConfigurations.secondary?.domains.toLowerCase())&&e.apiConfigurations?.secondary?.apis?.length?e.apiConfigurations.secondary:e?.apiConfigurations?.default;y?.apis?.forEach(s=>{let c=o.API?.REST;c&&(c[s.name]={endpoint:s.endpoint,region:s.region})}),P(o,{API:{REST:{headers:async s=>{let c=y?.apis?.find(l=>l.name===s.apiName);if(s.apiName==="admin"||c?.authorization==="ID_TOKEN"||c?.authorization==="ACCESS_TOKEN")try{let l=await f();if(l?.tokens?.idToken&&l?.tokens?.accessToken)return{Authorization:`Bearer ${s.apiName==="admin"||c?.authorization==="ID_TOKEN"?l.tokens.idToken.toString():l.tokens.accessToken.toString()}`}}catch(l){console.error(l),p().then(q=>{d(q).clearAccount()})}return{}}}}})},re=async()=>{let e=u();if(!e)throw new Error("Gatey plugin is not available");let t=null;return e.settings.customTranslationsUrl&&(t=await fetch(e.settings.customTranslationsUrl+(e.settings.customTranslationsUrl.includes("?")?"&":"?")+"t="+U.lastUpdate).then(n=>n.ok?n.text():null).then(n=>n?JSON.parse(n):null).catch(()=>null)),t??null},oe=async()=>{let e=await(0,V.getConfig)("gatey");ne(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,r=await m(n),o=await re();return{config:e,amplifyConfig:{},account:r,signedIn:!!r?.username&&!r.loaded,nextUrl:void 0,language:void 0,direction:void 0,customTranslations:o,reloadAuthSession:0,reloadUserAttributes:0,reloadMFAPreferences:0}},ie={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"?R.I18n.setLanguage(""):R.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"}}},se={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}},ae={},d=e=>(0,g.dispatch)(e),I=e=>(0,g.select)(e),K=async()=>{let e=await oe(),t=(0,g.createReduxStore)("wpsuite/gatey",{reducer(n=e,r){switch(r.type){case"SET_AMPLIFY_CONFIG":return{...n,amplifyConfig:r.amplifyConfig};case"SET_ACCOUNT":return C(r.account),{...n,account:r.account};case"CLEAR_ACCOUNT":return C({}),{...n,account:{}};case"RELOAD_AUTH_SESSION":{let o=Math.random();return{...n,reloadAuthSession:n.reloadAuthSession!==o?o:o+1}}case"RELOAD_USER_ATTRIBUTES":{let o=Math.random();return{...n,reloadUserAttributes:n.reloadUserAttributes!==o?o:o+1}}case"RELOAD_MFA_PREFERENCE":{let o=Math.random();return{...n,reloadMFAPreferences:n.reloadMFAPreferences!==o?o:o+1}}case"SET_SIGNED_IN":return{...n,signedIn:r.signedIn};case"SET_NEXT_URL":return{...n,nextUrl:r.nextUrl};case"SET_LANGUAGE":return{...n,language:r.language};case"SET_DIRECTION":return{...n,direction:r.direction}}return n},actions:ie,selectors:se,resolvers:ae});return(0,g.register)(t),t},S=(e,t,n)=>{let r;function o(){let A=I(e).getState(),s=t(A);if(s!==r){let c=r;r=s,n(r,c)}}let y=(0,g.subscribe)(o,e);return o(),y};var T=()=>O.Amplify.getConfig(),P=(e,t)=>{O.Amplify.configure(e,t)},f=e=>(0,i.fetchAuthSession)(e),G=()=>(0,i.fetchUserAttributes)(),v=()=>(0,i.fetchMFAPreference)(),X=async(e=!0)=>{let t=e?await m():{};if(t?.username)return t;try{if((await(0,i.fetchAuthSession)()).tokens)return{username:(await(0,i.getCurrentUser)()).username,userAttributes:await G(),mfaPreferences:await v()}}catch(n){console.error(n);try{await(0,i.signOut)()}catch{}}return{}},F=async()=>{await(0,i.updateMFAPreference)({totp:"DISABLED"})},j=()=>m().then(e=>e?.username),N=()=>m().then(e=>e?.userAttributes),L=()=>m().then(e=>e?.mfaPreferences),_=()=>m().then(e=>!!e?.username),k=e=>E().then(t=>t?.includes(e)||!1),E=()=>f().then(e=>e.tokens?.idToken?.payload["cognito:groups"]instanceof Array?e.tokens.idToken.payload["cognito:groups"].map(t=>t):[]).catch(e=>{console.error(e)}),D=async()=>f().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()=>f().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)}),W=()=>f().then(e=>e.tokens?.accessToken.payload.scope?.split(" ")??[]).catch(e=>{console.error(e)}),J=async e=>{let t,n=u();if(!n)throw new Error("Gatey plugin is not available");return n.settings.integrateWpLogin&&n.restUrl?.startsWith("http")&&(t=await n.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 n.cognito.get({apiName:e.apiName,path:e.path,options:e.options}).response.catch(r=>console.error(r)),n.settings.redirectSignIn??t},w=async e=>{let t=u();if(!t)throw new Error("Gatey plugin is not available");let n;t.settings.integrateWpLogin&&(n=await t.cognito.get({apiName:"admin",path:"/logout"}).response.then(r=>r.body.json()).then(r=>{if(r instanceof Object&&"redirect"in r)return r?.redirect}).catch(r=>{console.error(r)})),e&&await t.cognito.get({apiName:e.apiName,path:e.path,options:e.options}).response.catch(r=>console.error(r));try{await(0,i.signOut)()}catch{}return t.settings.redirectSignOut??n};var Y=require("@smart-cloud/wpsuite-core"),ue=()=>{p().then(e=>{S(e,t=>t.nextUrl,async t=>{t&&window.location.assign(t)}),d(e).clearAccount()}).catch(e=>{console.error("Gatey signOut error:",e)})},ce=e=>{p().then(t=>{d(t).setLanguage(e??"en")}).catch(t=>{console.error("Gatey setLanguage error:",t)})},ge=e=>{p().then(t=>{d(t).setDirection(e??"auto")}).catch(t=>{console.error("Gatey setDirection error:",t)})};var le=()=>{let e=globalThis.WpSuite,t=u();if(!t)throw new Error("Gatey plugin is not available");(0,Y.attachDefaultPluginRuntime)(t),t.status=t.status??"initializing";let n=K();return t.cognito={store:n,observeStore:S,setLanguage:ce,setDirection:ge,getAmplifyConfig:T,isAuthenticated:_,isInGroup:k,getUsername:j,getUserAttributes:N,getMfaPreferences:L,clearMfaPreferences:F,getGroups:E,getRoles:D,getPreferredRole:M,getScopes:W,signOut:ue,get:a.get,post:a.post,put:a.put,del:a.del,head:a.head,patch:a.patch},n.then(()=>{t.status="available",e?.events?.emit("wpsuite:gatey:ready",{key:t.key,version:t.version})}).catch(r=>{t.status="error",e?.events?.emit("wpsuite:gatey:error",{key:t.key,error:String(r)})}),t};0&&(module.exports={TEXT_DOMAIN,clearMfaPreferences,configureAmplify,getAmplifyConfig,getGateyPlugin,getGroups,getMfaPreferences,getPreferredRole,getRoles,getScopes,getStore,getStoreDispatch,getStoreSelect,getUserAttributes,initializeGatey,isAuthenticated,isInGroup,loadAuthSession,loadMFAPreferences,loadUserAttributes,login,logout,observeStore,waitForGateyReady});
1
+ "use strict";var b=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var Z=(e,t)=>{for(var n in t)b(e,n,{get:t[n],enumerable:!0})},ee=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of $(t))!Q.call(e,o)&&o!==n&&b(e,o,{get:()=>t[o],enumerable:!(r=H(t,o))||r.enumerable});return e};var te=e=>ee(b({},"__esModule",{value:!0}),e);var de={};Z(de,{TEXT_DOMAIN:()=>z,clearMfaPreferences:()=>F,configureAmplify:()=>P,getAmplifyConfig:()=>T,getGateyPlugin:()=>u,getGroups:()=>E,getMfaPreferences:()=>L,getPreferredRole:()=>M,getRoles:()=>D,getScopes:()=>W,getStore:()=>l,getStoreDispatch:()=>d,getStoreSelect:()=>I,getUserAttributes:()=>N,initializeGatey:()=>pe,isAuthenticated:()=>_,isInGroup:()=>k,loadAuthSession:()=>f,loadMFAPreferences:()=>v,loadUserAttributes:()=>G,login:()=>J,logout:()=>w,observeStore:()=>S,store:()=>le,waitForGateyReady:()=>x});module.exports=te(de);var a=require("aws-amplify/api");function u(){return globalThis.WpSuite?.plugins?.gatey}async function x(e=8e3){let t=u();if(t?.status!=="available"){if(t?.status==="error")throw new Error("Gatey failed");await new Promise((n,r)=>{let o=()=>A(n),y=()=>A(()=>r(new Error("Gatey failed"))),A=c=>{window.removeEventListener("wpsuite:gatey:ready",o),window.removeEventListener("wpsuite:gatey:error",y),s&&clearTimeout(s),c()};window.addEventListener("wpsuite:gatey:ready",o,{once:!0}),window.addEventListener("wpsuite:gatey:error",y,{once:!0});let s=e?window.setTimeout(()=>A(()=>r(new Error("Gatey timeout"))),e):0})}}async function l(e=1e4){await x(e);let n=u()?.cognito?.store;if(!n)throw new Error("Gatey store is not available");return n}var O=require("aws-amplify"),i=require("aws-amplify/auth");var B=require("aws-amplify/auth"),R=require("aws-amplify/utils"),g=require("@wordpress/data"),V=require("@smart-cloud/wpsuite-core");var h="gatey_account",z="gatey";var U;typeof WpSuite<"u"?U=WpSuite.siteSettings:U={};var C=e=>{e?.username?window.localStorage.setItem(h,JSON.stringify(e)):window.localStorage.removeItem(h)},m=async e=>{let t=JSON.parse(window.localStorage.getItem(h)??"{}"),n=!1;if(t?.username)try{let r=await(0,B.fetchAuthSession)();r?.tokens?.accessToken?.payload?.exp&&r.tokens.accessToken.payload.exp>new Date().getTime()/1e3&&(n=!0)}catch(r){console.error(r)}else try{t=await X(!1),t?.username&&(C(t),t.loaded=!0,n=!0)}catch(r){console.error(r)}return!n&&t?.username&&(C({}),l().then(async r=>{await w(e?.signOutHook),d(r).clearAccount()})),t},ne=async e=>{let t=window.location.hostname.toLowerCase().split(":")[0],n=u();if(!n)throw new Error("Gatey plugin is not available");let r=n.settings?.secondaryUserPoolDomains&&t.toLowerCase().match(n.settings.secondaryUserPoolDomains.toLowerCase())&&n.settings?.userPoolConfigurations.secondary?.Auth?.Cognito?.userPoolId?n.settings?.userPoolConfigurations.secondary:n.settings?.userPoolConfigurations.default,o={Auth:{Cognito:{userPoolClientId:"",userPoolId:"",identityPoolId:"",...r.Auth?.Cognito,loginWith:{oauth:{domain:"",scopes:[],responseType:"code",...r.Auth?.Cognito?.loginWith?.oauth,redirectSignIn:[window.location.origin+n.settings?.signInPage],redirectSignOut:[window.location.origin+n.settings?.signInPage]}}}},API:{...r.API,REST:{...r.API?.REST,admin:{endpoint:n.restUrl}}}},y=e?.apiConfigurations?.secondary?.domains&&t.toLowerCase().match(e.apiConfigurations.secondary?.domains.toLowerCase())&&e.apiConfigurations?.secondary?.apis?.length?e.apiConfigurations.secondary:e?.apiConfigurations?.default;y?.apis?.forEach(s=>{let c=o.API?.REST;c&&(c[s.name]={endpoint:s.endpoint,region:s.region})}),P(o,{API:{REST:{headers:async s=>{let c=y?.apis?.find(p=>p.name===s.apiName);if(s.apiName==="admin"||c?.authorization==="ID_TOKEN"||c?.authorization==="ACCESS_TOKEN")try{let p=await f();if(p?.tokens?.idToken&&p?.tokens?.accessToken)return{Authorization:`Bearer ${s.apiName==="admin"||c?.authorization==="ID_TOKEN"?p.tokens.idToken.toString():p.tokens.accessToken.toString()}`}}catch(p){console.error(p),l().then(q=>{d(q).clearAccount()})}return{}}}}})},re=async()=>{let e=u();if(!e)throw new Error("Gatey plugin is not available");let t=null;return e.settings.customTranslationsUrl&&(t=await fetch(e.settings.customTranslationsUrl+(e.settings.customTranslationsUrl.includes("?")?"&":"?")+"t="+U.lastUpdate).then(n=>n.ok?n.text():null).then(n=>n?JSON.parse(n):null).catch(()=>null)),t??null},oe=async()=>{let e=await(0,V.getConfig)("gatey");ne(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,r=await m(n),o=await re();return{config:e,amplifyConfig:{},account:r,signedIn:!!r?.username&&!r.loaded,nextUrl:void 0,language:void 0,direction:void 0,customTranslations:o,reloadAuthSession:0,reloadUserAttributes:0,reloadMFAPreferences:0}},ie={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"?R.I18n.setLanguage(""):R.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"}}},se={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}},ae={},d=e=>(0,g.dispatch)(e),I=e=>(0,g.select)(e),K=async()=>{let e=await oe(),t=(0,g.createReduxStore)("wpsuite/gatey",{reducer(n=e,r){switch(r.type){case"SET_AMPLIFY_CONFIG":return{...n,amplifyConfig:r.amplifyConfig};case"SET_ACCOUNT":return C(r.account),{...n,account:r.account};case"CLEAR_ACCOUNT":return C({}),{...n,account:{}};case"RELOAD_AUTH_SESSION":{let o=Math.random();return{...n,reloadAuthSession:n.reloadAuthSession!==o?o:o+1}}case"RELOAD_USER_ATTRIBUTES":{let o=Math.random();return{...n,reloadUserAttributes:n.reloadUserAttributes!==o?o:o+1}}case"RELOAD_MFA_PREFERENCE":{let o=Math.random();return{...n,reloadMFAPreferences:n.reloadMFAPreferences!==o?o:o+1}}case"SET_SIGNED_IN":return{...n,signedIn:r.signedIn};case"SET_NEXT_URL":return{...n,nextUrl:r.nextUrl};case"SET_LANGUAGE":return{...n,language:r.language};case"SET_DIRECTION":return{...n,direction:r.direction}}return n},actions:ie,selectors:se,resolvers:ae});return(0,g.register)(t),t},S=(e,t,n)=>{let r;function o(){let A=I(e).getState(),s=t(A);if(s!==r){let c=r;r=s,n(r,c)}}let y=(0,g.subscribe)(o,e);return o(),y};var T=()=>O.Amplify.getConfig(),P=(e,t)=>{O.Amplify.configure(e,t)},f=e=>(0,i.fetchAuthSession)(e),G=()=>(0,i.fetchUserAttributes)(),v=()=>(0,i.fetchMFAPreference)(),X=async(e=!0)=>{let t=e?await m():{};if(t?.username)return t;try{if((await(0,i.fetchAuthSession)()).tokens)return{username:(await(0,i.getCurrentUser)()).username,userAttributes:await G(),mfaPreferences:await v()}}catch(n){console.error(n);try{await(0,i.signOut)()}catch{}}return{}},F=async()=>{await(0,i.updateMFAPreference)({totp:"DISABLED"})},j=()=>m().then(e=>e?.username),N=()=>m().then(e=>e?.userAttributes),L=()=>m().then(e=>e?.mfaPreferences),_=()=>m().then(e=>!!e?.username),k=e=>E().then(t=>t?.includes(e)||!1),E=()=>f().then(e=>e.tokens?.idToken?.payload["cognito:groups"]instanceof Array?e.tokens.idToken.payload["cognito:groups"].map(t=>t):[]).catch(e=>{console.error(e)}),D=async()=>f().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()=>f().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)}),W=()=>f().then(e=>e.tokens?.accessToken.payload.scope?.split(" ")??[]).catch(e=>{console.error(e)}),J=async e=>{let t,n=u();if(!n)throw new Error("Gatey plugin is not available");return n.settings.integrateWpLogin&&n.restUrl?.startsWith("http")&&(t=await n.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 n.cognito.get({apiName:e.apiName,path:e.path,options:e.options}).response.catch(r=>console.error(r)),n.settings.redirectSignIn??t},w=async e=>{let t=u();if(!t)throw new Error("Gatey plugin is not available");let n;t.settings.integrateWpLogin&&(n=await t.cognito.get({apiName:"admin",path:"/logout"}).response.then(r=>r.body.json()).then(r=>{if(r instanceof Object&&"redirect"in r)return r?.redirect}).catch(r=>{console.error(r)})),e&&await t.cognito.get({apiName:e.apiName,path:e.path,options:e.options}).response.catch(r=>console.error(r));try{await(0,i.signOut)()}catch{}return t.settings.redirectSignOut??n};var Y=require("@smart-cloud/wpsuite-core"),ue=()=>{l().then(e=>{S(e,t=>t.nextUrl,async t=>{t&&window.location.assign(t)}),d(e).clearAccount()}).catch(e=>{console.error("Gatey signOut error:",e)})},ce=e=>{l().then(t=>{d(t).setLanguage(e??"en")}).catch(t=>{console.error("Gatey setLanguage error:",t)})},ge=e=>{l().then(t=>{d(t).setDirection(e??"auto")}).catch(t=>{console.error("Gatey setDirection error:",t)})};var le=async()=>l(),pe=()=>{let e=globalThis.WpSuite,t=u();if(!t)throw new Error("Gatey plugin is not available");(0,Y.attachDefaultPluginRuntime)(t),t.status=t.status??"initializing";let n=K();return t.cognito={store:n,observeStore:S,setLanguage:ce,setDirection:ge,getAmplifyConfig:T,isAuthenticated:_,isInGroup:k,getUsername:j,getUserAttributes:N,getMfaPreferences:L,clearMfaPreferences:F,getGroups:E,getRoles:D,getPreferredRole:M,getScopes:W,signOut:ue,get:a.get,post:a.post,put:a.put,del:a.del,head:a.head,patch:a.patch},n.then(()=>{t.status="available",e?.events?.emit("wpsuite:gatey:ready",{key:t.key,version:t.version})}).catch(r=>{t.status="error",e?.events?.emit("wpsuite:gatey:error",{key:t.key,error:String(r)})}),t};0&&(module.exports={TEXT_DOMAIN,clearMfaPreferences,configureAmplify,getAmplifyConfig,getGateyPlugin,getGroups,getMfaPreferences,getPreferredRole,getRoles,getScopes,getStore,getStoreDispatch,getStoreSelect,getUserAttributes,initializeGatey,isAuthenticated,isInGroup,loadAuthSession,loadMFAPreferences,loadUserAttributes,login,logout,observeStore,store,waitForGateyReady});
package/dist/index.d.cts CHANGED
@@ -1,63 +1,34 @@
1
1
  import { FormFieldOptionValue, LoginMechanism, SignUpAttribute, SocialProvider } from '@aws-amplify/ui';
2
2
  import { ResourcesConfig } from 'aws-amplify';
3
3
  import { get, post, put, del, head, patch } from 'aws-amplify/api';
4
- import { WpSuitePluginBase, SubscriptionType } from '@smart-cloud/wpsuite-core';
5
- import { FetchUserAttributesOutput, FetchMFAPreferenceOutput, FetchAuthSessionOptions, AuthSession } from 'aws-amplify/auth';
6
4
  import { CustomProvider } from '@aws-amplify/ui-react';
7
- import { StoreDescriptor as StoreDescriptor$1 } from '@wordpress/data';
8
-
9
- /**
10
- * External dependencies
11
- */
5
+ import { StoreDescriptor } from '@wordpress/data';
6
+ import { SubscriptionType, WpSuitePluginBase } from '@smart-cloud/wpsuite-core';
7
+ import { FetchUserAttributesOutput, FetchMFAPreferenceOutput, FetchAuthSessionOptions, AuthSession } from 'aws-amplify/auth';
12
8
 
13
- type MapOf<T> = {
14
- [name: string]: T;
15
- };
16
- type ActionCreator = (...args: any[]) => any | Generator;
17
- type Resolver = Function | Generator;
18
- type AnyConfig = ReduxStoreConfig<any, any, any>;
19
- interface StoreInstance<Config extends AnyConfig> {
20
- getSelectors: () => SelectorsOf<Config>;
21
- getActions: () => ActionCreatorsOf<Config>;
22
- subscribe: (listener: () => void) => () => void;
23
- }
24
- interface StoreDescriptor<Config extends AnyConfig> {
25
- /**
26
- * Store Name
27
- */
28
- name: string;
29
- /**
30
- * Creates a store instance
31
- */
32
- instantiate: (registry: DataRegistry) => StoreInstance<Config>;
33
- }
34
- interface ReduxStoreConfig<State, ActionCreators extends MapOf<ActionCreator>, Selectors> {
35
- initialState?: State;
36
- reducer: (state: any, action: any) => any;
37
- actions?: ActionCreators;
38
- resolvers?: MapOf<Resolver>;
39
- selectors?: Selectors;
40
- controls?: MapOf<Function>;
41
- }
42
- interface DataRegistry {
43
- register: (store: StoreDescriptor<any>) => void;
9
+ interface Account {
10
+ username?: string;
11
+ loaded?: boolean;
12
+ userAttributes?: FetchUserAttributesOutput;
13
+ mfaPreferences?: FetchMFAPreferenceOutput;
44
14
  }
45
- type ActionCreatorsOf<Config extends AnyConfig> = Config extends ReduxStoreConfig<any, infer ActionCreators, any> ? PromisifiedActionCreators<ActionCreators> : never;
46
- type PromisifiedActionCreators<ActionCreators extends MapOf<ActionCreator>> = {
47
- [Action in keyof ActionCreators]: PromisifyActionCreator<ActionCreators[Action]>;
48
- };
49
- type PromisifyActionCreator<Action extends ActionCreator> = (...args: Parameters<Action>) => Promise<ReturnType<Action> extends (..._args: any[]) => any ? ThunkReturnType<Action> : ReturnType<Action>>;
50
- type ThunkReturnType<Action extends ActionCreator> = Awaited<ReturnType<ReturnType<Action>>>;
51
- type SelectorsOf<Config extends AnyConfig> = Config extends ReduxStoreConfig<any, any, infer Selectors> ? {
52
- [name in keyof Selectors]: Function;
53
- } : never;
54
-
55
- type GateyReadyEvent = "wpsuite:gatey:ready";
56
- type GateyErrorEvent = "wpsuite:gatey:error";
57
- type GateyPlugin = WpSuitePluginBase & Gatey;
58
- declare function getGateyPlugin(): GateyPlugin;
59
- declare function waitForGateyReady(timeoutMs?: number): Promise<void>;
60
- declare function getStore(timeoutMs?: number): Promise<StoreDescriptor<any>>;
15
+ declare const getAmplifyConfig: () => ResourcesConfig;
16
+ declare const configureAmplify: (resourcesConfig: ResourcesConfig, libraryOptions?: Record<string, unknown>) => void;
17
+ declare const loadAuthSession: (options?: FetchAuthSessionOptions) => Promise<AuthSession>;
18
+ declare const loadUserAttributes: () => Promise<FetchUserAttributesOutput>;
19
+ declare const loadMFAPreferences: () => Promise<FetchMFAPreferenceOutput>;
20
+ declare const clearMfaPreferences: () => Promise<void>;
21
+ declare const getUsername: () => Promise<string | undefined>;
22
+ declare const getUserAttributes: () => Promise<FetchUserAttributesOutput | undefined>;
23
+ declare const getMfaPreferences: () => Promise<FetchMFAPreferenceOutput | undefined>;
24
+ declare const isAuthenticated: () => Promise<boolean>;
25
+ declare const isInGroup: (group: string) => Promise<boolean>;
26
+ declare const getGroups: () => Promise<string[] | undefined>;
27
+ declare const getRoles: () => Promise<string[] | undefined>;
28
+ declare const getPreferredRole: () => Promise<string | undefined>;
29
+ declare const getScopes: () => Promise<string[] | undefined>;
30
+ declare const login: (signInHook: ApiConfiguration["signInHook"]) => Promise<string | undefined>;
31
+ declare const logout: (signOutHook: ApiConfiguration["signOutHook"]) => Promise<string | undefined>;
61
32
 
62
33
  declare const actions: {
63
34
  setAmplifyConfig(amplifyConfig: ResourcesConfig): {
@@ -153,7 +124,7 @@ interface State {
153
124
  reloadUserAttributes: number;
154
125
  reloadMFAPreferences: number;
155
126
  }
156
- type Store = StoreDescriptor$1;
127
+ type Store = StoreDescriptor;
157
128
  type StoreSelectors = {
158
129
  getAmplifyConfig(): ResourcesConfig;
159
130
  getAccount(): Account;
@@ -168,31 +139,14 @@ type StoreSelectors = {
168
139
  type StoreActions = typeof actions;
169
140
  declare const getStoreDispatch: (store: Store) => StoreActions;
170
141
  declare const getStoreSelect: (store: Store) => StoreSelectors;
171
- declare const observeStore: (observableStore: Store, selector: (state: State) => ResourcesConfig | Account | boolean | number | string | null | undefined, onChange: (nextValue: ResourcesConfig | Account | boolean | number | string | null | undefined, previousValue: ResourcesConfig | Account | boolean | number | string | null | undefined) => void) => any;
142
+ declare const observeStore: (observableStore: Store, selector: (state: State) => ResourcesConfig | Account | boolean | number | string | null | undefined, onChange: (nextValue: ResourcesConfig | Account | boolean | number | string | null | undefined, previousValue: ResourcesConfig | Account | boolean | number | string | null | undefined) => void) => () => void;
172
143
 
173
- interface Account {
174
- username?: string;
175
- loaded?: boolean;
176
- userAttributes?: FetchUserAttributesOutput;
177
- mfaPreferences?: FetchMFAPreferenceOutput;
178
- }
179
- declare const getAmplifyConfig: () => ResourcesConfig;
180
- declare const configureAmplify: (resourcesConfig: ResourcesConfig, libraryOptions?: Record<string, unknown>) => void;
181
- declare const loadAuthSession: (options?: FetchAuthSessionOptions) => Promise<AuthSession>;
182
- declare const loadUserAttributes: () => Promise<FetchUserAttributesOutput>;
183
- declare const loadMFAPreferences: () => Promise<FetchMFAPreferenceOutput>;
184
- declare const clearMfaPreferences: () => Promise<void>;
185
- declare const getUsername: () => Promise<string | undefined>;
186
- declare const getUserAttributes: () => Promise<FetchUserAttributesOutput | undefined>;
187
- declare const getMfaPreferences: () => Promise<FetchMFAPreferenceOutput | undefined>;
188
- declare const isAuthenticated: () => Promise<boolean>;
189
- declare const isInGroup: (group: string) => Promise<boolean>;
190
- declare const getGroups: () => Promise<string[] | undefined>;
191
- declare const getRoles: () => Promise<string[] | undefined>;
192
- declare const getPreferredRole: () => Promise<string | undefined>;
193
- declare const getScopes: () => Promise<string[] | undefined>;
194
- declare const login: (signInHook: ApiConfiguration["signInHook"]) => Promise<string | undefined>;
195
- declare const logout: (signOutHook: ApiConfiguration["signOutHook"]) => Promise<string | undefined>;
144
+ type GateyReadyEvent = "wpsuite:gatey:ready";
145
+ type GateyErrorEvent = "wpsuite:gatey:error";
146
+ type GateyPlugin = WpSuitePluginBase & Gatey;
147
+ declare function getGateyPlugin(): GateyPlugin;
148
+ declare function waitForGateyReady(timeoutMs?: number): Promise<void>;
149
+ declare function getStore(timeoutMs?: number): Promise<Store>;
196
150
 
197
151
  declare const TEXT_DOMAIN = "gatey";
198
152
 
@@ -258,6 +212,11 @@ interface Gatey {
258
212
  restUrl: string;
259
213
  }
260
214
 
215
+ /**
216
+ * @deprecated Use `getStore()` instead. Import with `import { getStore } from '@smart-cloud/gatey-core';`
217
+ */
218
+ declare const store: () => Promise<Store>;
219
+
261
220
  declare const initializeGatey: () => GateyPlugin;
262
221
 
263
- export { type Account, type AuthenticatorConfig, type Cognito, type CustomTranslations, type FormField, type Gatey, type GateyErrorEvent, type GateyPlugin, type GateyReadyEvent, type RoleMapping, type Settings, type State, type Store, TEXT_DOMAIN, clearMfaPreferences, configureAmplify, getAmplifyConfig, getGateyPlugin, getGroups, getMfaPreferences, getPreferredRole, getRoles, getScopes, getStore, getStoreDispatch, getStoreSelect, getUserAttributes, initializeGatey, isAuthenticated, isInGroup, loadAuthSession, loadMFAPreferences, loadUserAttributes, login, logout, observeStore, waitForGateyReady };
222
+ export { type Account, type AuthenticatorConfig, type Cognito, type CustomTranslations, type FormField, type Gatey, type GateyErrorEvent, type GateyPlugin, type GateyReadyEvent, type RoleMapping, type Settings, type State, type Store, TEXT_DOMAIN, clearMfaPreferences, configureAmplify, getAmplifyConfig, getGateyPlugin, getGroups, getMfaPreferences, getPreferredRole, getRoles, getScopes, getStore, getStoreDispatch, getStoreSelect, getUserAttributes, initializeGatey, isAuthenticated, isInGroup, loadAuthSession, loadMFAPreferences, loadUserAttributes, login, logout, observeStore, store, waitForGateyReady };
package/dist/index.d.ts CHANGED
@@ -1,63 +1,34 @@
1
1
  import { FormFieldOptionValue, LoginMechanism, SignUpAttribute, SocialProvider } from '@aws-amplify/ui';
2
2
  import { ResourcesConfig } from 'aws-amplify';
3
3
  import { get, post, put, del, head, patch } from 'aws-amplify/api';
4
- import { WpSuitePluginBase, SubscriptionType } from '@smart-cloud/wpsuite-core';
5
- import { FetchUserAttributesOutput, FetchMFAPreferenceOutput, FetchAuthSessionOptions, AuthSession } from 'aws-amplify/auth';
6
4
  import { CustomProvider } from '@aws-amplify/ui-react';
7
- import { StoreDescriptor as StoreDescriptor$1 } from '@wordpress/data';
8
-
9
- /**
10
- * External dependencies
11
- */
5
+ import { StoreDescriptor } from '@wordpress/data';
6
+ import { SubscriptionType, WpSuitePluginBase } from '@smart-cloud/wpsuite-core';
7
+ import { FetchUserAttributesOutput, FetchMFAPreferenceOutput, FetchAuthSessionOptions, AuthSession } from 'aws-amplify/auth';
12
8
 
13
- type MapOf<T> = {
14
- [name: string]: T;
15
- };
16
- type ActionCreator = (...args: any[]) => any | Generator;
17
- type Resolver = Function | Generator;
18
- type AnyConfig = ReduxStoreConfig<any, any, any>;
19
- interface StoreInstance<Config extends AnyConfig> {
20
- getSelectors: () => SelectorsOf<Config>;
21
- getActions: () => ActionCreatorsOf<Config>;
22
- subscribe: (listener: () => void) => () => void;
23
- }
24
- interface StoreDescriptor<Config extends AnyConfig> {
25
- /**
26
- * Store Name
27
- */
28
- name: string;
29
- /**
30
- * Creates a store instance
31
- */
32
- instantiate: (registry: DataRegistry) => StoreInstance<Config>;
33
- }
34
- interface ReduxStoreConfig<State, ActionCreators extends MapOf<ActionCreator>, Selectors> {
35
- initialState?: State;
36
- reducer: (state: any, action: any) => any;
37
- actions?: ActionCreators;
38
- resolvers?: MapOf<Resolver>;
39
- selectors?: Selectors;
40
- controls?: MapOf<Function>;
41
- }
42
- interface DataRegistry {
43
- register: (store: StoreDescriptor<any>) => void;
9
+ interface Account {
10
+ username?: string;
11
+ loaded?: boolean;
12
+ userAttributes?: FetchUserAttributesOutput;
13
+ mfaPreferences?: FetchMFAPreferenceOutput;
44
14
  }
45
- type ActionCreatorsOf<Config extends AnyConfig> = Config extends ReduxStoreConfig<any, infer ActionCreators, any> ? PromisifiedActionCreators<ActionCreators> : never;
46
- type PromisifiedActionCreators<ActionCreators extends MapOf<ActionCreator>> = {
47
- [Action in keyof ActionCreators]: PromisifyActionCreator<ActionCreators[Action]>;
48
- };
49
- type PromisifyActionCreator<Action extends ActionCreator> = (...args: Parameters<Action>) => Promise<ReturnType<Action> extends (..._args: any[]) => any ? ThunkReturnType<Action> : ReturnType<Action>>;
50
- type ThunkReturnType<Action extends ActionCreator> = Awaited<ReturnType<ReturnType<Action>>>;
51
- type SelectorsOf<Config extends AnyConfig> = Config extends ReduxStoreConfig<any, any, infer Selectors> ? {
52
- [name in keyof Selectors]: Function;
53
- } : never;
54
-
55
- type GateyReadyEvent = "wpsuite:gatey:ready";
56
- type GateyErrorEvent = "wpsuite:gatey:error";
57
- type GateyPlugin = WpSuitePluginBase & Gatey;
58
- declare function getGateyPlugin(): GateyPlugin;
59
- declare function waitForGateyReady(timeoutMs?: number): Promise<void>;
60
- declare function getStore(timeoutMs?: number): Promise<StoreDescriptor<any>>;
15
+ declare const getAmplifyConfig: () => ResourcesConfig;
16
+ declare const configureAmplify: (resourcesConfig: ResourcesConfig, libraryOptions?: Record<string, unknown>) => void;
17
+ declare const loadAuthSession: (options?: FetchAuthSessionOptions) => Promise<AuthSession>;
18
+ declare const loadUserAttributes: () => Promise<FetchUserAttributesOutput>;
19
+ declare const loadMFAPreferences: () => Promise<FetchMFAPreferenceOutput>;
20
+ declare const clearMfaPreferences: () => Promise<void>;
21
+ declare const getUsername: () => Promise<string | undefined>;
22
+ declare const getUserAttributes: () => Promise<FetchUserAttributesOutput | undefined>;
23
+ declare const getMfaPreferences: () => Promise<FetchMFAPreferenceOutput | undefined>;
24
+ declare const isAuthenticated: () => Promise<boolean>;
25
+ declare const isInGroup: (group: string) => Promise<boolean>;
26
+ declare const getGroups: () => Promise<string[] | undefined>;
27
+ declare const getRoles: () => Promise<string[] | undefined>;
28
+ declare const getPreferredRole: () => Promise<string | undefined>;
29
+ declare const getScopes: () => Promise<string[] | undefined>;
30
+ declare const login: (signInHook: ApiConfiguration["signInHook"]) => Promise<string | undefined>;
31
+ declare const logout: (signOutHook: ApiConfiguration["signOutHook"]) => Promise<string | undefined>;
61
32
 
62
33
  declare const actions: {
63
34
  setAmplifyConfig(amplifyConfig: ResourcesConfig): {
@@ -153,7 +124,7 @@ interface State {
153
124
  reloadUserAttributes: number;
154
125
  reloadMFAPreferences: number;
155
126
  }
156
- type Store = StoreDescriptor$1;
127
+ type Store = StoreDescriptor;
157
128
  type StoreSelectors = {
158
129
  getAmplifyConfig(): ResourcesConfig;
159
130
  getAccount(): Account;
@@ -168,31 +139,14 @@ type StoreSelectors = {
168
139
  type StoreActions = typeof actions;
169
140
  declare const getStoreDispatch: (store: Store) => StoreActions;
170
141
  declare const getStoreSelect: (store: Store) => StoreSelectors;
171
- declare const observeStore: (observableStore: Store, selector: (state: State) => ResourcesConfig | Account | boolean | number | string | null | undefined, onChange: (nextValue: ResourcesConfig | Account | boolean | number | string | null | undefined, previousValue: ResourcesConfig | Account | boolean | number | string | null | undefined) => void) => any;
142
+ declare const observeStore: (observableStore: Store, selector: (state: State) => ResourcesConfig | Account | boolean | number | string | null | undefined, onChange: (nextValue: ResourcesConfig | Account | boolean | number | string | null | undefined, previousValue: ResourcesConfig | Account | boolean | number | string | null | undefined) => void) => () => void;
172
143
 
173
- interface Account {
174
- username?: string;
175
- loaded?: boolean;
176
- userAttributes?: FetchUserAttributesOutput;
177
- mfaPreferences?: FetchMFAPreferenceOutput;
178
- }
179
- declare const getAmplifyConfig: () => ResourcesConfig;
180
- declare const configureAmplify: (resourcesConfig: ResourcesConfig, libraryOptions?: Record<string, unknown>) => void;
181
- declare const loadAuthSession: (options?: FetchAuthSessionOptions) => Promise<AuthSession>;
182
- declare const loadUserAttributes: () => Promise<FetchUserAttributesOutput>;
183
- declare const loadMFAPreferences: () => Promise<FetchMFAPreferenceOutput>;
184
- declare const clearMfaPreferences: () => Promise<void>;
185
- declare const getUsername: () => Promise<string | undefined>;
186
- declare const getUserAttributes: () => Promise<FetchUserAttributesOutput | undefined>;
187
- declare const getMfaPreferences: () => Promise<FetchMFAPreferenceOutput | undefined>;
188
- declare const isAuthenticated: () => Promise<boolean>;
189
- declare const isInGroup: (group: string) => Promise<boolean>;
190
- declare const getGroups: () => Promise<string[] | undefined>;
191
- declare const getRoles: () => Promise<string[] | undefined>;
192
- declare const getPreferredRole: () => Promise<string | undefined>;
193
- declare const getScopes: () => Promise<string[] | undefined>;
194
- declare const login: (signInHook: ApiConfiguration["signInHook"]) => Promise<string | undefined>;
195
- declare const logout: (signOutHook: ApiConfiguration["signOutHook"]) => Promise<string | undefined>;
144
+ type GateyReadyEvent = "wpsuite:gatey:ready";
145
+ type GateyErrorEvent = "wpsuite:gatey:error";
146
+ type GateyPlugin = WpSuitePluginBase & Gatey;
147
+ declare function getGateyPlugin(): GateyPlugin;
148
+ declare function waitForGateyReady(timeoutMs?: number): Promise<void>;
149
+ declare function getStore(timeoutMs?: number): Promise<Store>;
196
150
 
197
151
  declare const TEXT_DOMAIN = "gatey";
198
152
 
@@ -258,6 +212,11 @@ interface Gatey {
258
212
  restUrl: string;
259
213
  }
260
214
 
215
+ /**
216
+ * @deprecated Use `getStore()` instead. Import with `import { getStore } from '@smart-cloud/gatey-core';`
217
+ */
218
+ declare const store: () => Promise<Store>;
219
+
261
220
  declare const initializeGatey: () => GateyPlugin;
262
221
 
263
- export { type Account, type AuthenticatorConfig, type Cognito, type CustomTranslations, type FormField, type Gatey, type GateyErrorEvent, type GateyPlugin, type GateyReadyEvent, type RoleMapping, type Settings, type State, type Store, TEXT_DOMAIN, clearMfaPreferences, configureAmplify, getAmplifyConfig, getGateyPlugin, getGroups, getMfaPreferences, getPreferredRole, getRoles, getScopes, getStore, getStoreDispatch, getStoreSelect, getUserAttributes, initializeGatey, isAuthenticated, isInGroup, loadAuthSession, loadMFAPreferences, loadUserAttributes, login, logout, observeStore, waitForGateyReady };
222
+ export { type Account, type AuthenticatorConfig, type Cognito, type CustomTranslations, type FormField, type Gatey, type GateyErrorEvent, type GateyPlugin, type GateyReadyEvent, type RoleMapping, type Settings, type State, type Store, TEXT_DOMAIN, clearMfaPreferences, configureAmplify, getAmplifyConfig, getGateyPlugin, getGroups, getMfaPreferences, getPreferredRole, getRoles, getScopes, getStore, getStoreDispatch, getStoreSelect, getUserAttributes, initializeGatey, isAuthenticated, isInGroup, loadAuthSession, loadMFAPreferences, loadUserAttributes, login, logout, observeStore, store, waitForGateyReady };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{del as ue,get as ce,head as ge,patch as le,post as pe,put as de}from"aws-amplify/api";function a(){return globalThis.WpSuite?.plugins?.gatey}async function T(e=8e3){let t=a();if(t?.status!=="available"){if(t?.status==="error")throw new Error("Gatey failed");await new Promise((n,r)=>{let o=()=>f(n),c=()=>f(()=>r(new Error("Gatey failed"))),f=s=>{window.removeEventListener("wpsuite:gatey:ready",o),window.removeEventListener("wpsuite:gatey:error",c),i&&clearTimeout(i),s()};window.addEventListener("wpsuite:gatey:ready",o,{once:!0}),window.addEventListener("wpsuite:gatey:error",c,{once:!0});let i=e?window.setTimeout(()=>f(()=>r(new Error("Gatey timeout"))),e):0})}}async function g(e=1e4){await T(e);let n=a()?.cognito?.store;if(!n)throw new Error("Gatey store is not available");return n}import{Amplify as U}from"aws-amplify";import{fetchAuthSession as I,fetchMFAPreference as re,fetchUserAttributes as oe,getCurrentUser as ie,signOut as O,updateMFAPreference as se}from"aws-amplify/auth";import{fetchAuthSession as K}from"aws-amplify/auth";import{I18n as E}from"aws-amplify/utils";import{createReduxStore as X,dispatch as j,register as J,select as Y,subscribe as q}from"@wordpress/data";import{getConfig as H}from"@smart-cloud/wpsuite-core";var y="gatey_account",V="gatey";var S;typeof WpSuite<"u"?S=WpSuite.siteSettings:S={};var m=e=>{e?.username?window.localStorage.setItem(y,JSON.stringify(e)):window.localStorage.removeItem(y)},l=async e=>{let t=JSON.parse(window.localStorage.getItem(y)??"{}"),n=!1;if(t?.username)try{let r=await K();r?.tokens?.accessToken?.payload?.exp&&r.tokens.accessToken.payload.exp>new Date().getTime()/1e3&&(n=!0)}catch(r){console.error(r)}else try{t=await R(!1),t?.username&&(m(t),t.loaded=!0,n=!0)}catch(r){console.error(r)}return!n&&t?.username&&(m({}),g().then(async r=>{await C(e?.signOutHook),p(r).clearAccount()})),t},$=async e=>{let t=window.location.hostname.toLowerCase().split(":")[0],n=a();if(!n)throw new Error("Gatey plugin is not available");let r=n.settings?.secondaryUserPoolDomains&&t.toLowerCase().match(n.settings.secondaryUserPoolDomains.toLowerCase())&&n.settings?.userPoolConfigurations.secondary?.Auth?.Cognito?.userPoolId?n.settings?.userPoolConfigurations.secondary:n.settings?.userPoolConfigurations.default,o={Auth:{Cognito:{userPoolClientId:"",userPoolId:"",identityPoolId:"",...r.Auth?.Cognito,loginWith:{oauth:{domain:"",scopes:[],responseType:"code",...r.Auth?.Cognito?.loginWith?.oauth,redirectSignIn:[window.location.origin+n.settings?.signInPage],redirectSignOut:[window.location.origin+n.settings?.signInPage]}}}},API:{...r.API,REST:{...r.API?.REST,admin:{endpoint:n.restUrl}}}},c=e?.apiConfigurations?.secondary?.domains&&t.toLowerCase().match(e.apiConfigurations.secondary?.domains.toLowerCase())&&e.apiConfigurations?.secondary?.apis?.length?e.apiConfigurations.secondary:e?.apiConfigurations?.default;c?.apis?.forEach(i=>{let s=o.API?.REST;s&&(s[i.name]={endpoint:i.endpoint,region:i.region})}),h(o,{API:{REST:{headers:async i=>{let s=c?.apis?.find(u=>u.name===i.apiName);if(i.apiName==="admin"||s?.authorization==="ID_TOKEN"||s?.authorization==="ACCESS_TOKEN")try{let u=await d();if(u?.tokens?.idToken&&u?.tokens?.accessToken)return{Authorization:`Bearer ${i.apiName==="admin"||s?.authorization==="ID_TOKEN"?u.tokens.idToken.toString():u.tokens.accessToken.toString()}`}}catch(u){console.error(u),g().then(B=>{p(B).clearAccount()})}return{}}}}})},Q=async()=>{let e=a();if(!e)throw new Error("Gatey plugin is not available");let t=null;return e.settings.customTranslationsUrl&&(t=await fetch(e.settings.customTranslationsUrl+(e.settings.customTranslationsUrl.includes("?")?"&":"?")+"t="+S.lastUpdate).then(n=>n.ok?n.text():null).then(n=>n?JSON.parse(n):null).catch(()=>null)),t??null},Z=async()=>{let e=await H("gatey");$(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,r=await l(n),o=await Q();return{config:e,amplifyConfig:{},account:r,signedIn:!!r?.username&&!r.loaded,nextUrl:void 0,language:void 0,direction:void 0,customTranslations:o,reloadAuthSession:0,reloadUserAttributes:0,reloadMFAPreferences:0}},ee={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"?E.setLanguage(""):E.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"}}},te={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}},ne={},p=e=>j(e),b=e=>Y(e),x=async()=>{let e=await Z(),t=X("wpsuite/gatey",{reducer(n=e,r){switch(r.type){case"SET_AMPLIFY_CONFIG":return{...n,amplifyConfig:r.amplifyConfig};case"SET_ACCOUNT":return m(r.account),{...n,account:r.account};case"CLEAR_ACCOUNT":return m({}),{...n,account:{}};case"RELOAD_AUTH_SESSION":{let o=Math.random();return{...n,reloadAuthSession:n.reloadAuthSession!==o?o:o+1}}case"RELOAD_USER_ATTRIBUTES":{let o=Math.random();return{...n,reloadUserAttributes:n.reloadUserAttributes!==o?o:o+1}}case"RELOAD_MFA_PREFERENCE":{let o=Math.random();return{...n,reloadMFAPreferences:n.reloadMFAPreferences!==o?o:o+1}}case"SET_SIGNED_IN":return{...n,signedIn:r.signedIn};case"SET_NEXT_URL":return{...n,nextUrl:r.nextUrl};case"SET_LANGUAGE":return{...n,language:r.language};case"SET_DIRECTION":return{...n,direction:r.direction}}return n},actions:ee,selectors:te,resolvers:ne});return J(t),t},A=(e,t,n)=>{let r;function o(){let f=b(e).getState(),i=t(f);if(i!==r){let s=r;r=i,n(r,s)}}let c=q(o,e);return o(),c};var P=()=>U.getConfig(),h=(e,t)=>{U.configure(e,t)},d=e=>I(e),G=()=>oe(),v=()=>re(),R=async(e=!0)=>{let t=e?await l():{};if(t?.username)return t;try{if((await I()).tokens)return{username:(await ie()).username,userAttributes:await G(),mfaPreferences:await v()}}catch(n){console.error(n);try{await O()}catch{}}return{}},F=async()=>{await se({totp:"DISABLED"})},N=()=>l().then(e=>e?.username),L=()=>l().then(e=>e?.userAttributes),_=()=>l().then(e=>e?.mfaPreferences),k=()=>l().then(e=>!!e?.username),D=e=>w().then(t=>t?.includes(e)||!1),w=()=>d().then(e=>e.tokens?.idToken?.payload["cognito:groups"]instanceof Array?e.tokens.idToken.payload["cognito:groups"].map(t=>t):[]).catch(e=>{console.error(e)}),M=async()=>d().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)}),W=async()=>d().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)}),z=()=>d().then(e=>e.tokens?.accessToken.payload.scope?.split(" ")??[]).catch(e=>{console.error(e)}),ae=async e=>{let t,n=a();if(!n)throw new Error("Gatey plugin is not available");return n.settings.integrateWpLogin&&n.restUrl?.startsWith("http")&&(t=await n.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 n.cognito.get({apiName:e.apiName,path:e.path,options:e.options}).response.catch(r=>console.error(r)),n.settings.redirectSignIn??t},C=async e=>{let t=a();if(!t)throw new Error("Gatey plugin is not available");let n;t.settings.integrateWpLogin&&(n=await t.cognito.get({apiName:"admin",path:"/logout"}).response.then(r=>r.body.json()).then(r=>{if(r instanceof Object&&"redirect"in r)return r?.redirect}).catch(r=>{console.error(r)})),e&&await t.cognito.get({apiName:e.apiName,path:e.path,options:e.options}).response.catch(r=>console.error(r));try{await O()}catch{}return t.settings.redirectSignOut??n};import{attachDefaultPluginRuntime as fe}from"@smart-cloud/wpsuite-core";var ye=()=>{g().then(e=>{A(e,t=>t.nextUrl,async t=>{t&&window.location.assign(t)}),p(e).clearAccount()}).catch(e=>{console.error("Gatey signOut error:",e)})},me=e=>{g().then(t=>{p(t).setLanguage(e??"en")}).catch(t=>{console.error("Gatey setLanguage error:",t)})},Ae=e=>{g().then(t=>{p(t).setDirection(e??"auto")}).catch(t=>{console.error("Gatey setDirection error:",t)})};var Me=()=>{let e=globalThis.WpSuite,t=a();if(!t)throw new Error("Gatey plugin is not available");fe(t),t.status=t.status??"initializing";let n=x();return t.cognito={store:n,observeStore:A,setLanguage:me,setDirection:Ae,getAmplifyConfig:P,isAuthenticated:k,isInGroup:D,getUsername:N,getUserAttributes:L,getMfaPreferences:_,clearMfaPreferences:F,getGroups:w,getRoles:M,getPreferredRole:W,getScopes:z,signOut:ye,get:ce,post:pe,put:de,del:ue,head:ge,patch:le},n.then(()=>{t.status="available",e?.events?.emit("wpsuite:gatey:ready",{key:t.key,version:t.version})}).catch(r=>{t.status="error",e?.events?.emit("wpsuite:gatey:error",{key:t.key,error:String(r)})}),t};export{V as TEXT_DOMAIN,F as clearMfaPreferences,h as configureAmplify,P as getAmplifyConfig,a as getGateyPlugin,w as getGroups,_ as getMfaPreferences,W as getPreferredRole,M as getRoles,z as getScopes,g as getStore,p as getStoreDispatch,b as getStoreSelect,L as getUserAttributes,Me as initializeGatey,k as isAuthenticated,D as isInGroup,d as loadAuthSession,v as loadMFAPreferences,G as loadUserAttributes,ae as login,C as logout,A as observeStore,T as waitForGateyReady};
1
+ import{del as ue,get as ce,head as ge,patch as le,post as pe,put as de}from"aws-amplify/api";function a(){return globalThis.WpSuite?.plugins?.gatey}async function T(e=8e3){let t=a();if(t?.status!=="available"){if(t?.status==="error")throw new Error("Gatey failed");await new Promise((n,r)=>{let o=()=>f(n),g=()=>f(()=>r(new Error("Gatey failed"))),f=s=>{window.removeEventListener("wpsuite:gatey:ready",o),window.removeEventListener("wpsuite:gatey:error",g),i&&clearTimeout(i),s()};window.addEventListener("wpsuite:gatey:ready",o,{once:!0}),window.addEventListener("wpsuite:gatey:error",g,{once:!0});let i=e?window.setTimeout(()=>f(()=>r(new Error("Gatey timeout"))),e):0})}}async function c(e=1e4){await T(e);let n=a()?.cognito?.store;if(!n)throw new Error("Gatey store is not available");return n}import{Amplify as U}from"aws-amplify";import{fetchAuthSession as I,fetchMFAPreference as re,fetchUserAttributes as oe,getCurrentUser as ie,signOut as O,updateMFAPreference as se}from"aws-amplify/auth";import{fetchAuthSession as K}from"aws-amplify/auth";import{I18n as E}from"aws-amplify/utils";import{createReduxStore as X,dispatch as j,register as J,select as Y,subscribe as q}from"@wordpress/data";import{getConfig as H}from"@smart-cloud/wpsuite-core";var y="gatey_account",V="gatey";var S;typeof WpSuite<"u"?S=WpSuite.siteSettings:S={};var m=e=>{e?.username?window.localStorage.setItem(y,JSON.stringify(e)):window.localStorage.removeItem(y)},l=async e=>{let t=JSON.parse(window.localStorage.getItem(y)??"{}"),n=!1;if(t?.username)try{let r=await K();r?.tokens?.accessToken?.payload?.exp&&r.tokens.accessToken.payload.exp>new Date().getTime()/1e3&&(n=!0)}catch(r){console.error(r)}else try{t=await R(!1),t?.username&&(m(t),t.loaded=!0,n=!0)}catch(r){console.error(r)}return!n&&t?.username&&(m({}),c().then(async r=>{await C(e?.signOutHook),p(r).clearAccount()})),t},$=async e=>{let t=window.location.hostname.toLowerCase().split(":")[0],n=a();if(!n)throw new Error("Gatey plugin is not available");let r=n.settings?.secondaryUserPoolDomains&&t.toLowerCase().match(n.settings.secondaryUserPoolDomains.toLowerCase())&&n.settings?.userPoolConfigurations.secondary?.Auth?.Cognito?.userPoolId?n.settings?.userPoolConfigurations.secondary:n.settings?.userPoolConfigurations.default,o={Auth:{Cognito:{userPoolClientId:"",userPoolId:"",identityPoolId:"",...r.Auth?.Cognito,loginWith:{oauth:{domain:"",scopes:[],responseType:"code",...r.Auth?.Cognito?.loginWith?.oauth,redirectSignIn:[window.location.origin+n.settings?.signInPage],redirectSignOut:[window.location.origin+n.settings?.signInPage]}}}},API:{...r.API,REST:{...r.API?.REST,admin:{endpoint:n.restUrl}}}},g=e?.apiConfigurations?.secondary?.domains&&t.toLowerCase().match(e.apiConfigurations.secondary?.domains.toLowerCase())&&e.apiConfigurations?.secondary?.apis?.length?e.apiConfigurations.secondary:e?.apiConfigurations?.default;g?.apis?.forEach(i=>{let s=o.API?.REST;s&&(s[i.name]={endpoint:i.endpoint,region:i.region})}),h(o,{API:{REST:{headers:async i=>{let s=g?.apis?.find(u=>u.name===i.apiName);if(i.apiName==="admin"||s?.authorization==="ID_TOKEN"||s?.authorization==="ACCESS_TOKEN")try{let u=await d();if(u?.tokens?.idToken&&u?.tokens?.accessToken)return{Authorization:`Bearer ${i.apiName==="admin"||s?.authorization==="ID_TOKEN"?u.tokens.idToken.toString():u.tokens.accessToken.toString()}`}}catch(u){console.error(u),c().then(B=>{p(B).clearAccount()})}return{}}}}})},Q=async()=>{let e=a();if(!e)throw new Error("Gatey plugin is not available");let t=null;return e.settings.customTranslationsUrl&&(t=await fetch(e.settings.customTranslationsUrl+(e.settings.customTranslationsUrl.includes("?")?"&":"?")+"t="+S.lastUpdate).then(n=>n.ok?n.text():null).then(n=>n?JSON.parse(n):null).catch(()=>null)),t??null},Z=async()=>{let e=await H("gatey");$(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,r=await l(n),o=await Q();return{config:e,amplifyConfig:{},account:r,signedIn:!!r?.username&&!r.loaded,nextUrl:void 0,language:void 0,direction:void 0,customTranslations:o,reloadAuthSession:0,reloadUserAttributes:0,reloadMFAPreferences:0}},ee={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"?E.setLanguage(""):E.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"}}},te={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}},ne={},p=e=>j(e),b=e=>Y(e),x=async()=>{let e=await Z(),t=X("wpsuite/gatey",{reducer(n=e,r){switch(r.type){case"SET_AMPLIFY_CONFIG":return{...n,amplifyConfig:r.amplifyConfig};case"SET_ACCOUNT":return m(r.account),{...n,account:r.account};case"CLEAR_ACCOUNT":return m({}),{...n,account:{}};case"RELOAD_AUTH_SESSION":{let o=Math.random();return{...n,reloadAuthSession:n.reloadAuthSession!==o?o:o+1}}case"RELOAD_USER_ATTRIBUTES":{let o=Math.random();return{...n,reloadUserAttributes:n.reloadUserAttributes!==o?o:o+1}}case"RELOAD_MFA_PREFERENCE":{let o=Math.random();return{...n,reloadMFAPreferences:n.reloadMFAPreferences!==o?o:o+1}}case"SET_SIGNED_IN":return{...n,signedIn:r.signedIn};case"SET_NEXT_URL":return{...n,nextUrl:r.nextUrl};case"SET_LANGUAGE":return{...n,language:r.language};case"SET_DIRECTION":return{...n,direction:r.direction}}return n},actions:ee,selectors:te,resolvers:ne});return J(t),t},A=(e,t,n)=>{let r;function o(){let f=b(e).getState(),i=t(f);if(i!==r){let s=r;r=i,n(r,s)}}let g=q(o,e);return o(),g};var P=()=>U.getConfig(),h=(e,t)=>{U.configure(e,t)},d=e=>I(e),G=()=>oe(),v=()=>re(),R=async(e=!0)=>{let t=e?await l():{};if(t?.username)return t;try{if((await I()).tokens)return{username:(await ie()).username,userAttributes:await G(),mfaPreferences:await v()}}catch(n){console.error(n);try{await O()}catch{}}return{}},F=async()=>{await se({totp:"DISABLED"})},N=()=>l().then(e=>e?.username),L=()=>l().then(e=>e?.userAttributes),_=()=>l().then(e=>e?.mfaPreferences),k=()=>l().then(e=>!!e?.username),D=e=>w().then(t=>t?.includes(e)||!1),w=()=>d().then(e=>e.tokens?.idToken?.payload["cognito:groups"]instanceof Array?e.tokens.idToken.payload["cognito:groups"].map(t=>t):[]).catch(e=>{console.error(e)}),M=async()=>d().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)}),W=async()=>d().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)}),z=()=>d().then(e=>e.tokens?.accessToken.payload.scope?.split(" ")??[]).catch(e=>{console.error(e)}),ae=async e=>{let t,n=a();if(!n)throw new Error("Gatey plugin is not available");return n.settings.integrateWpLogin&&n.restUrl?.startsWith("http")&&(t=await n.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 n.cognito.get({apiName:e.apiName,path:e.path,options:e.options}).response.catch(r=>console.error(r)),n.settings.redirectSignIn??t},C=async e=>{let t=a();if(!t)throw new Error("Gatey plugin is not available");let n;t.settings.integrateWpLogin&&(n=await t.cognito.get({apiName:"admin",path:"/logout"}).response.then(r=>r.body.json()).then(r=>{if(r instanceof Object&&"redirect"in r)return r?.redirect}).catch(r=>{console.error(r)})),e&&await t.cognito.get({apiName:e.apiName,path:e.path,options:e.options}).response.catch(r=>console.error(r));try{await O()}catch{}return t.settings.redirectSignOut??n};import{attachDefaultPluginRuntime as fe}from"@smart-cloud/wpsuite-core";var ye=()=>{c().then(e=>{A(e,t=>t.nextUrl,async t=>{t&&window.location.assign(t)}),p(e).clearAccount()}).catch(e=>{console.error("Gatey signOut error:",e)})},me=e=>{c().then(t=>{p(t).setLanguage(e??"en")}).catch(t=>{console.error("Gatey setLanguage error:",t)})},Ae=e=>{c().then(t=>{p(t).setDirection(e??"auto")}).catch(t=>{console.error("Gatey setDirection error:",t)})};var Me=async()=>c(),We=()=>{let e=globalThis.WpSuite,t=a();if(!t)throw new Error("Gatey plugin is not available");fe(t),t.status=t.status??"initializing";let n=x();return t.cognito={store:n,observeStore:A,setLanguage:me,setDirection:Ae,getAmplifyConfig:P,isAuthenticated:k,isInGroup:D,getUsername:N,getUserAttributes:L,getMfaPreferences:_,clearMfaPreferences:F,getGroups:w,getRoles:M,getPreferredRole:W,getScopes:z,signOut:ye,get:ce,post:pe,put:de,del:ue,head:ge,patch:le},n.then(()=>{t.status="available",e?.events?.emit("wpsuite:gatey:ready",{key:t.key,version:t.version})}).catch(r=>{t.status="error",e?.events?.emit("wpsuite:gatey:error",{key:t.key,error:String(r)})}),t};export{V as TEXT_DOMAIN,F as clearMfaPreferences,h as configureAmplify,P as getAmplifyConfig,a as getGateyPlugin,w as getGroups,_ as getMfaPreferences,W as getPreferredRole,M as getRoles,z as getScopes,c as getStore,p as getStoreDispatch,b as getStoreSelect,L as getUserAttributes,We as initializeGatey,k as isAuthenticated,D as isInGroup,d as loadAuthSession,v as loadMFAPreferences,G as loadUserAttributes,ae as login,C as logout,A as observeStore,Me as store,T as waitForGateyReady};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart-cloud/gatey-core",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "Login & SSO with Amazon Cognito",
5
5
  "author": "Smart Cloud Solutions Inc.",
6
6
  "license": "MIT",
@@ -22,25 +22,25 @@
22
22
  "scope": "@smart-cloud/gatey-core"
23
23
  },
24
24
  "dependencies": {
25
- "@smart-cloud/wpsuite-core": "^2.0.2"
25
+ "@smart-cloud/wpsuite-core": "^2.0.3"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "@aws-amplify/ui-react": "^6.13.2",
29
- "@wordpress/data": "^10.36.0",
30
- "aws-amplify": "^6.15.8"
29
+ "@wordpress/data": "^10.37.0",
30
+ "aws-amplify": "^6.15.9"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@aws-amplify/ui-react": "^6.13.2",
34
34
  "@eslint/js": "^9.39.2",
35
- "@types/node": "^25.0.2",
36
- "@typescript-eslint/eslint-plugin": "^8.50.0",
37
- "@typescript-eslint/parser": "^8.50.0",
38
- "@wordpress/data": "^10.36.0",
39
- "aws-amplify": "^6.15.8",
35
+ "@types/node": "^25.0.3",
36
+ "@typescript-eslint/eslint-plugin": "^8.51.0",
37
+ "@typescript-eslint/parser": "^8.51.0",
38
+ "@wordpress/data": "^10.37.0",
39
+ "aws-amplify": "^6.15.9",
40
40
  "eslint": "^9.39.2",
41
- "globals": "^16.5.0",
41
+ "globals": "^17.0.0",
42
42
  "tsup": "^8.5.1",
43
43
  "typescript": "^5.9.3",
44
- "typescript-eslint": "^8.50.0"
44
+ "typescript-eslint": "^8.51.0"
45
45
  }
46
46
  }