@smart-cloud/gatey-core 1.0.7 → 1.0.9
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 +57 -51
- package/dist/index.d.ts +57 -51
- package/dist/index.js +1 -1
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var P=Object.defineProperty;var
|
|
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:()=>U,getUserAttributes:()=>R,isAuthenticated:()=>N,isInGroup:()=>G,loadAuthSession:()=>p,loadMFAPreferences:()=>I,loadUserAttributes:()=>E,login:()=>z,logout:()=>S,observeStore:()=>f,store:()=>j});module.exports=Q(ce);var s=require("aws-amplify/api");var x=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 K(!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),U=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=U(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=()=>x.Amplify.getConfig(),A=(e,t)=>{x.Amplify.configure(e,t)},p=e=>(0,i.fetchAuthSession)(e),E=()=>(0,i.fetchUserAttributes)(),I=()=>(0,i.fetchMFAPreference)(),K=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"})},V=()=>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)}),z=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:V,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
|
@@ -1,56 +1,48 @@
|
|
|
1
|
+
import { FormFieldOptionValue, LoginMechanism, SignUpAttribute, SocialProvider } from '@aws-amplify/ui';
|
|
1
2
|
import { ResourcesConfig } from 'aws-amplify';
|
|
2
3
|
import { get, post, put, del, head, patch } from 'aws-amplify/api';
|
|
3
|
-
import {
|
|
4
|
-
import { FetchUserAttributesOutput, FetchMFAPreferenceOutput, FetchAuthSessionOptions, AuthSession } from 'aws-amplify/auth';
|
|
4
|
+
import { FetchMFAPreferenceOutput, FetchUserAttributesOutput, FetchAuthSessionOptions, AuthSession } from 'aws-amplify/auth';
|
|
5
5
|
import { CustomProvider } from '@aws-amplify/ui-react';
|
|
6
|
-
import { StoreDescriptor
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* External dependencies
|
|
10
|
-
*/
|
|
6
|
+
import { StoreDescriptor } from '@wordpress/data';
|
|
11
7
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
type
|
|
45
|
-
|
|
46
|
-
|
|
8
|
+
declare const actions: {
|
|
9
|
+
setAmplifyConfig(amplifyConfig: ResourcesConfig): {
|
|
10
|
+
type: string;
|
|
11
|
+
amplifyConfig: ResourcesConfig;
|
|
12
|
+
};
|
|
13
|
+
setAccount(account: Account): {
|
|
14
|
+
type: string;
|
|
15
|
+
account: Account;
|
|
16
|
+
};
|
|
17
|
+
clearAccount(): {
|
|
18
|
+
type: string;
|
|
19
|
+
};
|
|
20
|
+
setSignedIn(signedIn: boolean): {
|
|
21
|
+
type: string;
|
|
22
|
+
signedIn: boolean;
|
|
23
|
+
};
|
|
24
|
+
setNextUrl(nextUrl: string | undefined | null): {
|
|
25
|
+
type: string;
|
|
26
|
+
nextUrl: string | null | undefined;
|
|
27
|
+
};
|
|
28
|
+
setLanguage(language: string | undefined | null): {
|
|
29
|
+
type: string;
|
|
30
|
+
language: string | null | undefined;
|
|
31
|
+
};
|
|
32
|
+
setDirection(direction: "ltr" | "rtl" | "auto" | undefined | null): {
|
|
33
|
+
type: string;
|
|
34
|
+
direction: "ltr" | "rtl" | "auto" | null | undefined;
|
|
35
|
+
};
|
|
36
|
+
reloadAuthSession(): {
|
|
37
|
+
type: string;
|
|
38
|
+
};
|
|
39
|
+
reloadUserAttributes(): {
|
|
40
|
+
type: string;
|
|
41
|
+
};
|
|
42
|
+
reloadMFAPreferences(): {
|
|
43
|
+
type: string;
|
|
44
|
+
};
|
|
47
45
|
};
|
|
48
|
-
type PromisifyActionCreator<Action extends ActionCreator> = (...args: Parameters<Action>) => Promise<ReturnType<Action> extends (..._args: any[]) => any ? ThunkReturnType<Action> : ReturnType<Action>>;
|
|
49
|
-
type ThunkReturnType<Action extends ActionCreator> = Awaited<ReturnType<ReturnType<Action>>>;
|
|
50
|
-
type SelectorsOf<Config extends AnyConfig> = Config extends ReduxStoreConfig<any, any, infer Selectors> ? {
|
|
51
|
-
[name in keyof Selectors]: Function;
|
|
52
|
-
} : never;
|
|
53
|
-
|
|
54
46
|
interface FormField {
|
|
55
47
|
name: string;
|
|
56
48
|
type: string;
|
|
@@ -108,7 +100,21 @@ interface State {
|
|
|
108
100
|
reloadMFAPreferences: number;
|
|
109
101
|
}
|
|
110
102
|
type SubscriptionType = "PROFESSIONAL" | "AGENCY";
|
|
111
|
-
type Store = StoreDescriptor
|
|
103
|
+
type Store = StoreDescriptor;
|
|
104
|
+
type StoreSelectors = {
|
|
105
|
+
getAmplifyConfig(): ResourcesConfig;
|
|
106
|
+
getAccount(): Account;
|
|
107
|
+
getNextUrl(): string | null | undefined;
|
|
108
|
+
isSignedIn(): boolean;
|
|
109
|
+
getConfig(): AuthenticatorConfig | null;
|
|
110
|
+
getCustomTranslations(): CustomTranslations | null;
|
|
111
|
+
getLanguage(): string | undefined | null;
|
|
112
|
+
getDirection(): "ltr" | "rtl" | "auto" | undefined | null;
|
|
113
|
+
getState(): State;
|
|
114
|
+
};
|
|
115
|
+
type StoreActions = typeof actions;
|
|
116
|
+
declare const getStoreDispatch: (store: Store) => StoreActions;
|
|
117
|
+
declare const getStoreSelect: (store: Store) => StoreSelectors;
|
|
112
118
|
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;
|
|
113
119
|
|
|
114
120
|
interface Account {
|
|
@@ -211,6 +217,6 @@ interface Gatey {
|
|
|
211
217
|
uploadUrl: string;
|
|
212
218
|
}
|
|
213
219
|
|
|
214
|
-
declare const store: Promise<
|
|
220
|
+
declare const store: Promise<Store>;
|
|
215
221
|
|
|
216
|
-
export { type Account, type AuthenticatorConfig, type Cognito, type CustomTranslations, type FormField, Gatey, type RoleMapping, type Settings, type SiteSettings, type State, type Store, type SubscriptionType, TEXT_DOMAIN, clearMfaPreferences, configureAmplify, getAmplifyConfig, getGroups, getMfaPreferences, getPreferredRole, getRoles, getScopes, getUserAttributes, isAuthenticated, isInGroup, loadAuthSession, loadMFAPreferences, loadUserAttributes, login, logout, observeStore, store };
|
|
222
|
+
export { type Account, type AuthenticatorConfig, type Cognito, type CustomTranslations, type FormField, Gatey, type RoleMapping, type Settings, type SiteSettings, 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
|
@@ -1,56 +1,48 @@
|
|
|
1
|
+
import { FormFieldOptionValue, LoginMechanism, SignUpAttribute, SocialProvider } from '@aws-amplify/ui';
|
|
1
2
|
import { ResourcesConfig } from 'aws-amplify';
|
|
2
3
|
import { get, post, put, del, head, patch } from 'aws-amplify/api';
|
|
3
|
-
import {
|
|
4
|
-
import { FetchUserAttributesOutput, FetchMFAPreferenceOutput, FetchAuthSessionOptions, AuthSession } from 'aws-amplify/auth';
|
|
4
|
+
import { FetchMFAPreferenceOutput, FetchUserAttributesOutput, FetchAuthSessionOptions, AuthSession } from 'aws-amplify/auth';
|
|
5
5
|
import { CustomProvider } from '@aws-amplify/ui-react';
|
|
6
|
-
import { StoreDescriptor
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* External dependencies
|
|
10
|
-
*/
|
|
6
|
+
import { StoreDescriptor } from '@wordpress/data';
|
|
11
7
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
type
|
|
45
|
-
|
|
46
|
-
|
|
8
|
+
declare const actions: {
|
|
9
|
+
setAmplifyConfig(amplifyConfig: ResourcesConfig): {
|
|
10
|
+
type: string;
|
|
11
|
+
amplifyConfig: ResourcesConfig;
|
|
12
|
+
};
|
|
13
|
+
setAccount(account: Account): {
|
|
14
|
+
type: string;
|
|
15
|
+
account: Account;
|
|
16
|
+
};
|
|
17
|
+
clearAccount(): {
|
|
18
|
+
type: string;
|
|
19
|
+
};
|
|
20
|
+
setSignedIn(signedIn: boolean): {
|
|
21
|
+
type: string;
|
|
22
|
+
signedIn: boolean;
|
|
23
|
+
};
|
|
24
|
+
setNextUrl(nextUrl: string | undefined | null): {
|
|
25
|
+
type: string;
|
|
26
|
+
nextUrl: string | null | undefined;
|
|
27
|
+
};
|
|
28
|
+
setLanguage(language: string | undefined | null): {
|
|
29
|
+
type: string;
|
|
30
|
+
language: string | null | undefined;
|
|
31
|
+
};
|
|
32
|
+
setDirection(direction: "ltr" | "rtl" | "auto" | undefined | null): {
|
|
33
|
+
type: string;
|
|
34
|
+
direction: "ltr" | "rtl" | "auto" | null | undefined;
|
|
35
|
+
};
|
|
36
|
+
reloadAuthSession(): {
|
|
37
|
+
type: string;
|
|
38
|
+
};
|
|
39
|
+
reloadUserAttributes(): {
|
|
40
|
+
type: string;
|
|
41
|
+
};
|
|
42
|
+
reloadMFAPreferences(): {
|
|
43
|
+
type: string;
|
|
44
|
+
};
|
|
47
45
|
};
|
|
48
|
-
type PromisifyActionCreator<Action extends ActionCreator> = (...args: Parameters<Action>) => Promise<ReturnType<Action> extends (..._args: any[]) => any ? ThunkReturnType<Action> : ReturnType<Action>>;
|
|
49
|
-
type ThunkReturnType<Action extends ActionCreator> = Awaited<ReturnType<ReturnType<Action>>>;
|
|
50
|
-
type SelectorsOf<Config extends AnyConfig> = Config extends ReduxStoreConfig<any, any, infer Selectors> ? {
|
|
51
|
-
[name in keyof Selectors]: Function;
|
|
52
|
-
} : never;
|
|
53
|
-
|
|
54
46
|
interface FormField {
|
|
55
47
|
name: string;
|
|
56
48
|
type: string;
|
|
@@ -108,7 +100,21 @@ interface State {
|
|
|
108
100
|
reloadMFAPreferences: number;
|
|
109
101
|
}
|
|
110
102
|
type SubscriptionType = "PROFESSIONAL" | "AGENCY";
|
|
111
|
-
type Store = StoreDescriptor
|
|
103
|
+
type Store = StoreDescriptor;
|
|
104
|
+
type StoreSelectors = {
|
|
105
|
+
getAmplifyConfig(): ResourcesConfig;
|
|
106
|
+
getAccount(): Account;
|
|
107
|
+
getNextUrl(): string | null | undefined;
|
|
108
|
+
isSignedIn(): boolean;
|
|
109
|
+
getConfig(): AuthenticatorConfig | null;
|
|
110
|
+
getCustomTranslations(): CustomTranslations | null;
|
|
111
|
+
getLanguage(): string | undefined | null;
|
|
112
|
+
getDirection(): "ltr" | "rtl" | "auto" | undefined | null;
|
|
113
|
+
getState(): State;
|
|
114
|
+
};
|
|
115
|
+
type StoreActions = typeof actions;
|
|
116
|
+
declare const getStoreDispatch: (store: Store) => StoreActions;
|
|
117
|
+
declare const getStoreSelect: (store: Store) => StoreSelectors;
|
|
112
118
|
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;
|
|
113
119
|
|
|
114
120
|
interface Account {
|
|
@@ -211,6 +217,6 @@ interface Gatey {
|
|
|
211
217
|
uploadUrl: string;
|
|
212
218
|
}
|
|
213
219
|
|
|
214
|
-
declare const store: Promise<
|
|
220
|
+
declare const store: Promise<Store>;
|
|
215
221
|
|
|
216
|
-
export { type Account, type AuthenticatorConfig, type Cognito, type CustomTranslations, type FormField, Gatey, type RoleMapping, type Settings, type SiteSettings, type State, type Store, type SubscriptionType, TEXT_DOMAIN, clearMfaPreferences, configureAmplify, getAmplifyConfig, getGroups, getMfaPreferences, getPreferredRole, getRoles, getScopes, getUserAttributes, isAuthenticated, isInGroup, loadAuthSession, loadMFAPreferences, loadUserAttributes, login, logout, observeStore, store };
|
|
222
|
+
export { type Account, type AuthenticatorConfig, type Cognito, type CustomTranslations, type FormField, Gatey, type RoleMapping, type Settings, type SiteSettings, 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{
|
|
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 U}from"aws-amplify";import{fetchAuthSession as x,fetchUserAttributes as ee,fetchMFAPreference as te,getCurrentUser as ne,signOut as E,updateMFAPreference as oe}from"aws-amplify/auth";import{fetchAuthSession as K}from"aws-amplify/auth";import{I18n as C}from"aws-amplify/utils";import{createReduxStore as V,dispatch as z,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 K();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=>z(e),P=e=>j(e),T=async()=>{let e=await H(),t=V("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=()=>U.getConfig(),y=(e,t)=>{U.configure(e,t)},g=e=>x(e),I=()=>ee(),O=()=>te(),b=async(e=!0)=>{let t=e?await c():{};if(t?.username)return t;try{if((await x()).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.9",
|
|
4
4
|
"description": "Login & SSO with Amazon Cognito",
|
|
5
5
|
"author": "Smart Cloud Solutions Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,14 +22,15 @@
|
|
|
22
22
|
"scope": "@smart-cloud/gatey-core"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@aws-amplify/ui-react": "^6.13.1",
|
|
26
25
|
"@smart-cloud/wpsuite-core": "^1.0.7"
|
|
27
26
|
},
|
|
28
27
|
"peerDependencies": {
|
|
29
|
-
"aws-amplify": "^6.
|
|
30
|
-
"@wordpress/data": "^10.36.0"
|
|
28
|
+
"@aws-amplify/ui-react": "^6.13.1",
|
|
29
|
+
"@wordpress/data": "^10.36.0",
|
|
30
|
+
"aws-amplify": "^6.15.8"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
+
"@aws-amplify/ui-react": "^6.13.1",
|
|
33
34
|
"@types/node": "^24.10.1",
|
|
34
35
|
"@typescript-eslint/eslint-plugin": "^8.48.1",
|
|
35
36
|
"@typescript-eslint/parser": "^8.48.1",
|