@smart-cloud/gatey-core 1.0.0
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 -0
- package/dist/index.d.cts +219 -0
- package/dist/index.d.ts +219 -0
- package/dist/index.js +1 -0
- package/package.json +36 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var P=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var q=(e,t)=>{for(var n in t)P(e,n,{get:t[n],enumerable:!0})},H=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of J(t))!Y.call(e,r)&&r!==n&&P(e,r,{get:()=>t[r],enumerable:!(o=X(t,r))||o.enumerable});return e};var $=e=>H(P({},"__esModule",{value:!0}),e);var ae={};q(ae,{TEXT_DOMAIN:()=>M,clearMfaPreferences:()=>I,configureAmplify:()=>m,getAmplifyConfig:()=>S,getGroups:()=>h,getMfaPreferences:()=>O,getPreferredRole:()=>F,getRoles:()=>N,getScopes:()=>_,getUserAttributes:()=>R,isAuthenticated:()=>w,isInGroup:()=>G,loadAuthSession:()=>l,loadMFAPreferences:()=>x,loadUserAttributes:()=>E,login:()=>V,logout:()=>A,observeStore:()=>d,store:()=>B});module.exports=$(ae);var s=require("aws-amplify/api"),C=require("@wordpress/data");var U=require("aws-amplify"),i=require("aws-amplify/auth");var k=require("aws-amplify/auth"),T=require("aws-amplify/utils"),a=require("@wordpress/data"),D=require("@smart-cloud/wpsuite-core");var f="gatey_account",M="gatey";var b;typeof WpSuite<"u"?b=WpSuite.siteSettings:b={};var y=e=>{e?.username?window.localStorage.setItem(f,JSON.stringify(e)):window.localStorage.removeItem(f)},p=async e=>{let t=JSON.parse(window.localStorage.getItem(f)??"{}"),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 W(!1),t?.username&&(y(t),t.loaded=!0,n=!0)}catch(o){console.error(o)}return!n&&t?.username&&(y({}),Gatey.cognito.store.then(async o=>{await A(e?.signOutHook),await(0,a.dispatch)(o).clearAccount()})),t},Q=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})}),m(o,{API:{REST:{headers:async u=>{let g=r?.apis?.find(c=>c.name===u.apiName);if(u.apiName==="admin"||g?.authorization==="ID_TOKEN"||g?.authorization==="ACCESS_TOKEN")try{let c=await l();if(c?.tokens?.idToken&&c?.tokens?.accessToken)return{Authorization:`Bearer ${u.apiName==="admin"||g?.authorization==="ID_TOKEN"?c.tokens.idToken.toString():c.tokens.accessToken.toString()}`}}catch(c){console.error(c),Gatey.cognito.store.then(j=>{(0,a.dispatch)(j).clearAccount()})}return{}}}}})},Z=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},ee=async()=>{let e=await(0,D.getConfig)("gatey");Q(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 p(n),r=await Z();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}},te={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"}}},ne={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}},oe={},v=async()=>{let e=await ee(),t=(0,a.createReduxStore)("wpsuite/gatey",{reducer(n=e,o){switch(o.type){case"SET_AMPLIFY_CONFIG":return{...n,amplifyConfig:o.amplifyConfig};case"SET_ACCOUNT":return y(o.account),{...n,account:o.account};case"CLEAR_ACCOUNT":return y({}),{...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:te,selectors:ne,resolvers:oe});return(0,a.register)(t),t},d=(e,t,n)=>{let o;function r(){let u=(0,a.select)(e).getState(),g=t(u);if(g!==o){let c=o;o=g,n(o,c)}}let L=(0,a.subscribe)(r,e);return r(),L};var S=()=>U.Amplify.getConfig(),m=(e,t)=>{U.Amplify.configure(e,t)},l=e=>(0,i.fetchAuthSession)(e),E=()=>(0,i.fetchUserAttributes)(),x=()=>(0,i.fetchMFAPreference)(),W=async(e=!0)=>{let t=e?await p():{};if(t?.username)return t;try{if((await(0,i.fetchAuthSession)()).tokens)return{username:(await(0,i.getCurrentUser)()).username,userAttributes:await E(),mfaPreferences:await x()}}catch(n){console.error(n);try{await(0,i.signOut)()}catch{}}return{}},I=async()=>{await(0,i.updateMFAPreference)({totp:"DISABLED"})},K=()=>p().then(e=>e?.username),R=()=>p().then(e=>e?.userAttributes),O=()=>p().then(e=>e?.mfaPreferences),w=()=>p().then(e=>!!e?.username),G=e=>h().then(t=>t?.includes(e)||!1),h=()=>l().then(e=>e.tokens?.idToken?.payload["cognito:groups"]instanceof Array?e.tokens.idToken.payload["cognito:groups"].map(t=>t):[]).catch(e=>{console.error(e)}),N=async()=>l().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)}),F=async()=>l().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().then(e=>e.tokens?.accessToken.payload.scope?.split(" ")??[]).catch(e=>{console.error(e)}),V=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},A=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 re=()=>{Gatey.cognito.store.then(e=>{d(e,t=>t.nextUrl,async t=>{t&&window.location.assign(t)}),(0,C.dispatch)(e).clearAccount()})},ie=e=>{Gatey.cognito.store.then(t=>{(0,C.dispatch)(t).setLanguage(e??"en")})},se=e=>{Gatey.cognito.store.then(t=>{(0,C.dispatch)(t).setDirection(e??"auto")})};var z=!!Gatey.cognito?.store,B=Gatey.cognito?.store??v();z||(Gatey.cognito={store:B,observeStore:d,setLanguage:ie,setDirection:se,getAmplifyConfig:S,isAuthenticated:w,isInGroup:G,getUsername:K,getUserAttributes:R,getMfaPreferences:O,clearMfaPreferences:I,getGroups:h,getRoles:N,getPreferredRole:F,getScopes:_,signOut:re,get:s.get,post:s.post,put:s.put,del:s.del,head:s.head,patch:s.patch});z=!0;0&&(module.exports={TEXT_DOMAIN,clearMfaPreferences,configureAmplify,getAmplifyConfig,getGroups,getMfaPreferences,getPreferredRole,getRoles,getScopes,getUserAttributes,isAuthenticated,isInGroup,loadAuthSession,loadMFAPreferences,loadUserAttributes,login,logout,observeStore,store});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { ResourcesConfig } from 'aws-amplify';
|
|
2
|
+
import { get, post, put, del, head, patch } from 'aws-amplify/api';
|
|
3
|
+
import { FormFieldOptionValue, LoginMechanism, SignUpAttribute, SocialProvider } from '@aws-amplify/ui';
|
|
4
|
+
import { FetchUserAttributesOutput, FetchMFAPreferenceOutput, FetchAuthSessionOptions, AuthSession } from 'aws-amplify/auth';
|
|
5
|
+
import { CustomProvider } from '@aws-amplify/ui-react';
|
|
6
|
+
import { StoreDescriptor, ReduxStoreConfig } from '@wordpress/data/build-types/types';
|
|
7
|
+
|
|
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
|
+
};
|
|
45
|
+
};
|
|
46
|
+
declare const selectors: {
|
|
47
|
+
getAmplifyConfig(state: State): ResourcesConfig;
|
|
48
|
+
getAccount(state: State): Account;
|
|
49
|
+
getNextUrl(state: State): string | null | undefined;
|
|
50
|
+
isSignedIn(state: State): boolean;
|
|
51
|
+
getConfig(state: State): AuthenticatorConfig | null;
|
|
52
|
+
getCustomTranslations(state: State): CustomTranslations | null;
|
|
53
|
+
getLanguage(state: State): string | null | undefined;
|
|
54
|
+
getDirection(state: State): "ltr" | "rtl" | "auto" | null | undefined;
|
|
55
|
+
getState(state: State): State;
|
|
56
|
+
};
|
|
57
|
+
interface FormField {
|
|
58
|
+
name: string;
|
|
59
|
+
type: string;
|
|
60
|
+
values?: Array<FormFieldOptionValue>;
|
|
61
|
+
}
|
|
62
|
+
interface ApiOptions {
|
|
63
|
+
headers?: Record<string, string>;
|
|
64
|
+
queryParams?: Record<string, string>;
|
|
65
|
+
body?: never;
|
|
66
|
+
withCredentials?: boolean;
|
|
67
|
+
}
|
|
68
|
+
interface API {
|
|
69
|
+
name: string;
|
|
70
|
+
endpoint: string;
|
|
71
|
+
region?: string;
|
|
72
|
+
authorization: "IAM" | "ID_TOKEN" | "ACCESS_TOKEN";
|
|
73
|
+
}
|
|
74
|
+
interface ApiConfiguration {
|
|
75
|
+
domains?: string;
|
|
76
|
+
apis: API[];
|
|
77
|
+
signInHook?: {
|
|
78
|
+
apiName: string;
|
|
79
|
+
path: string;
|
|
80
|
+
options?: ApiOptions;
|
|
81
|
+
};
|
|
82
|
+
signOutHook?: {
|
|
83
|
+
apiName: string;
|
|
84
|
+
path: string;
|
|
85
|
+
options?: ApiOptions;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
interface AuthenticatorConfig {
|
|
89
|
+
customProviders: CustomProvider[];
|
|
90
|
+
formFields: FormField[];
|
|
91
|
+
apiConfigurations: {
|
|
92
|
+
default: ApiConfiguration;
|
|
93
|
+
secondary?: ApiConfiguration;
|
|
94
|
+
};
|
|
95
|
+
subscriptionType?: SubscriptionType;
|
|
96
|
+
}
|
|
97
|
+
interface CustomTranslations {
|
|
98
|
+
[key: string]: Record<string, string>;
|
|
99
|
+
}
|
|
100
|
+
interface State {
|
|
101
|
+
amplifyConfig: ResourcesConfig;
|
|
102
|
+
account: Account;
|
|
103
|
+
signedIn: boolean;
|
|
104
|
+
nextUrl: string | undefined | null;
|
|
105
|
+
config: AuthenticatorConfig | null;
|
|
106
|
+
language: string | undefined | null;
|
|
107
|
+
direction: "ltr" | "rtl" | "auto" | undefined | null;
|
|
108
|
+
customTranslations: CustomTranslations | null;
|
|
109
|
+
reloadAuthSession: number;
|
|
110
|
+
reloadUserAttributes: number;
|
|
111
|
+
reloadMFAPreferences: number;
|
|
112
|
+
}
|
|
113
|
+
type SubscriptionType = "PROFESSIONAL" | "AGENCY";
|
|
114
|
+
type Store = StoreDescriptor<ReduxStoreConfig<State, typeof actions, typeof selectors>>;
|
|
115
|
+
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;
|
|
116
|
+
|
|
117
|
+
interface Account {
|
|
118
|
+
username?: string;
|
|
119
|
+
loaded?: boolean;
|
|
120
|
+
userAttributes?: FetchUserAttributesOutput;
|
|
121
|
+
mfaPreferences?: FetchMFAPreferenceOutput;
|
|
122
|
+
}
|
|
123
|
+
declare const getAmplifyConfig: () => ResourcesConfig;
|
|
124
|
+
declare const configureAmplify: (resourcesConfig: ResourcesConfig, libraryOptions?: Record<string, unknown>) => void;
|
|
125
|
+
declare const loadAuthSession: (options?: FetchAuthSessionOptions) => Promise<AuthSession>;
|
|
126
|
+
declare const loadUserAttributes: () => Promise<FetchUserAttributesOutput>;
|
|
127
|
+
declare const loadMFAPreferences: () => Promise<FetchMFAPreferenceOutput>;
|
|
128
|
+
declare const clearMfaPreferences: () => Promise<void>;
|
|
129
|
+
declare const getUsername: () => Promise<string | undefined>;
|
|
130
|
+
declare const getUserAttributes: () => Promise<FetchUserAttributesOutput | undefined>;
|
|
131
|
+
declare const getMfaPreferences: () => Promise<FetchMFAPreferenceOutput | undefined>;
|
|
132
|
+
declare const isAuthenticated: () => Promise<boolean>;
|
|
133
|
+
declare const isInGroup: (group: string) => Promise<boolean>;
|
|
134
|
+
declare const getGroups: () => Promise<string[] | undefined>;
|
|
135
|
+
declare const getRoles: () => Promise<string[] | undefined>;
|
|
136
|
+
declare const getPreferredRole: () => Promise<string | undefined>;
|
|
137
|
+
declare const getScopes: () => Promise<string[] | undefined>;
|
|
138
|
+
declare const login: (signInHook: ApiConfiguration["signInHook"]) => Promise<string | undefined>;
|
|
139
|
+
declare const logout: (signOutHook: ApiConfiguration["signOutHook"]) => Promise<string | undefined>;
|
|
140
|
+
|
|
141
|
+
declare const TEXT_DOMAIN = "gatey";
|
|
142
|
+
|
|
143
|
+
declare global {
|
|
144
|
+
const Gatey: Gatey;
|
|
145
|
+
}
|
|
146
|
+
interface RoleMapping {
|
|
147
|
+
cognitoGroup?: string;
|
|
148
|
+
wordpressRole?: string;
|
|
149
|
+
}
|
|
150
|
+
interface Settings {
|
|
151
|
+
userPoolConfigurations: {
|
|
152
|
+
default: ResourcesConfig;
|
|
153
|
+
secondary?: ResourcesConfig;
|
|
154
|
+
};
|
|
155
|
+
secondaryUserPoolDomains?: string;
|
|
156
|
+
mappings: RoleMapping[];
|
|
157
|
+
loginMechanisms: LoginMechanism[];
|
|
158
|
+
signUpAttributes: SignUpAttribute[];
|
|
159
|
+
socialProviders?: SocialProvider[];
|
|
160
|
+
integrateWpLogin: boolean;
|
|
161
|
+
cookieExpiration?: number;
|
|
162
|
+
signInPage?: string;
|
|
163
|
+
redirectSignIn?: string;
|
|
164
|
+
redirectSignOut?: string;
|
|
165
|
+
reCaptchaPublicKey?: string;
|
|
166
|
+
customTranslationsUrl?: string;
|
|
167
|
+
useRecaptchaNet?: boolean;
|
|
168
|
+
useRecaptchaEnterprise?: boolean;
|
|
169
|
+
enablePoweredBy?: boolean;
|
|
170
|
+
}
|
|
171
|
+
interface SiteSettings {
|
|
172
|
+
accountId?: string;
|
|
173
|
+
siteId?: string;
|
|
174
|
+
lastUpdate?: number;
|
|
175
|
+
subscriber?: boolean;
|
|
176
|
+
siteKey?: string;
|
|
177
|
+
}
|
|
178
|
+
declare const signOut: () => void;
|
|
179
|
+
declare const setLanguage: (language?: string) => void;
|
|
180
|
+
declare const setDirection: (direction?: "ltr" | "rtl" | "auto") => void;
|
|
181
|
+
interface Cognito {
|
|
182
|
+
readonly store: Promise<Store>;
|
|
183
|
+
readonly observeStore: typeof observeStore;
|
|
184
|
+
readonly setLanguage: typeof setLanguage;
|
|
185
|
+
readonly setDirection: typeof setDirection;
|
|
186
|
+
readonly getUsername: typeof getUsername;
|
|
187
|
+
readonly getUserAttributes: typeof getUserAttributes;
|
|
188
|
+
readonly getMfaPreferences: typeof getMfaPreferences;
|
|
189
|
+
readonly clearMfaPreferences: typeof clearMfaPreferences;
|
|
190
|
+
readonly isAuthenticated: typeof isAuthenticated;
|
|
191
|
+
readonly isInGroup: typeof isInGroup;
|
|
192
|
+
readonly getGroups: typeof getGroups;
|
|
193
|
+
readonly getRoles: typeof getRoles;
|
|
194
|
+
readonly getScopes: typeof getScopes;
|
|
195
|
+
readonly getPreferredRole: typeof getPreferredRole;
|
|
196
|
+
readonly signOut: typeof signOut;
|
|
197
|
+
readonly getAmplifyConfig: typeof getAmplifyConfig;
|
|
198
|
+
readonly get: typeof get;
|
|
199
|
+
readonly post: typeof post;
|
|
200
|
+
readonly put: typeof put;
|
|
201
|
+
readonly del: typeof del;
|
|
202
|
+
readonly head: typeof head;
|
|
203
|
+
readonly patch: typeof patch;
|
|
204
|
+
toSignIn?: () => void;
|
|
205
|
+
toSignUp?: () => void;
|
|
206
|
+
toForgotPassword?: () => void;
|
|
207
|
+
}
|
|
208
|
+
interface Gatey {
|
|
209
|
+
cognito: Cognito;
|
|
210
|
+
settings: Settings;
|
|
211
|
+
siteSettings: SiteSettings;
|
|
212
|
+
nonce: string;
|
|
213
|
+
restUrl: string;
|
|
214
|
+
uploadUrl: string;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
declare const store: Promise<Store>;
|
|
218
|
+
|
|
219
|
+
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 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { ResourcesConfig } from 'aws-amplify';
|
|
2
|
+
import { get, post, put, del, head, patch } from 'aws-amplify/api';
|
|
3
|
+
import { FormFieldOptionValue, LoginMechanism, SignUpAttribute, SocialProvider } from '@aws-amplify/ui';
|
|
4
|
+
import { FetchUserAttributesOutput, FetchMFAPreferenceOutput, FetchAuthSessionOptions, AuthSession } from 'aws-amplify/auth';
|
|
5
|
+
import { CustomProvider } from '@aws-amplify/ui-react';
|
|
6
|
+
import { StoreDescriptor, ReduxStoreConfig } from '@wordpress/data/build-types/types';
|
|
7
|
+
|
|
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
|
+
};
|
|
45
|
+
};
|
|
46
|
+
declare const selectors: {
|
|
47
|
+
getAmplifyConfig(state: State): ResourcesConfig;
|
|
48
|
+
getAccount(state: State): Account;
|
|
49
|
+
getNextUrl(state: State): string | null | undefined;
|
|
50
|
+
isSignedIn(state: State): boolean;
|
|
51
|
+
getConfig(state: State): AuthenticatorConfig | null;
|
|
52
|
+
getCustomTranslations(state: State): CustomTranslations | null;
|
|
53
|
+
getLanguage(state: State): string | null | undefined;
|
|
54
|
+
getDirection(state: State): "ltr" | "rtl" | "auto" | null | undefined;
|
|
55
|
+
getState(state: State): State;
|
|
56
|
+
};
|
|
57
|
+
interface FormField {
|
|
58
|
+
name: string;
|
|
59
|
+
type: string;
|
|
60
|
+
values?: Array<FormFieldOptionValue>;
|
|
61
|
+
}
|
|
62
|
+
interface ApiOptions {
|
|
63
|
+
headers?: Record<string, string>;
|
|
64
|
+
queryParams?: Record<string, string>;
|
|
65
|
+
body?: never;
|
|
66
|
+
withCredentials?: boolean;
|
|
67
|
+
}
|
|
68
|
+
interface API {
|
|
69
|
+
name: string;
|
|
70
|
+
endpoint: string;
|
|
71
|
+
region?: string;
|
|
72
|
+
authorization: "IAM" | "ID_TOKEN" | "ACCESS_TOKEN";
|
|
73
|
+
}
|
|
74
|
+
interface ApiConfiguration {
|
|
75
|
+
domains?: string;
|
|
76
|
+
apis: API[];
|
|
77
|
+
signInHook?: {
|
|
78
|
+
apiName: string;
|
|
79
|
+
path: string;
|
|
80
|
+
options?: ApiOptions;
|
|
81
|
+
};
|
|
82
|
+
signOutHook?: {
|
|
83
|
+
apiName: string;
|
|
84
|
+
path: string;
|
|
85
|
+
options?: ApiOptions;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
interface AuthenticatorConfig {
|
|
89
|
+
customProviders: CustomProvider[];
|
|
90
|
+
formFields: FormField[];
|
|
91
|
+
apiConfigurations: {
|
|
92
|
+
default: ApiConfiguration;
|
|
93
|
+
secondary?: ApiConfiguration;
|
|
94
|
+
};
|
|
95
|
+
subscriptionType?: SubscriptionType;
|
|
96
|
+
}
|
|
97
|
+
interface CustomTranslations {
|
|
98
|
+
[key: string]: Record<string, string>;
|
|
99
|
+
}
|
|
100
|
+
interface State {
|
|
101
|
+
amplifyConfig: ResourcesConfig;
|
|
102
|
+
account: Account;
|
|
103
|
+
signedIn: boolean;
|
|
104
|
+
nextUrl: string | undefined | null;
|
|
105
|
+
config: AuthenticatorConfig | null;
|
|
106
|
+
language: string | undefined | null;
|
|
107
|
+
direction: "ltr" | "rtl" | "auto" | undefined | null;
|
|
108
|
+
customTranslations: CustomTranslations | null;
|
|
109
|
+
reloadAuthSession: number;
|
|
110
|
+
reloadUserAttributes: number;
|
|
111
|
+
reloadMFAPreferences: number;
|
|
112
|
+
}
|
|
113
|
+
type SubscriptionType = "PROFESSIONAL" | "AGENCY";
|
|
114
|
+
type Store = StoreDescriptor<ReduxStoreConfig<State, typeof actions, typeof selectors>>;
|
|
115
|
+
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;
|
|
116
|
+
|
|
117
|
+
interface Account {
|
|
118
|
+
username?: string;
|
|
119
|
+
loaded?: boolean;
|
|
120
|
+
userAttributes?: FetchUserAttributesOutput;
|
|
121
|
+
mfaPreferences?: FetchMFAPreferenceOutput;
|
|
122
|
+
}
|
|
123
|
+
declare const getAmplifyConfig: () => ResourcesConfig;
|
|
124
|
+
declare const configureAmplify: (resourcesConfig: ResourcesConfig, libraryOptions?: Record<string, unknown>) => void;
|
|
125
|
+
declare const loadAuthSession: (options?: FetchAuthSessionOptions) => Promise<AuthSession>;
|
|
126
|
+
declare const loadUserAttributes: () => Promise<FetchUserAttributesOutput>;
|
|
127
|
+
declare const loadMFAPreferences: () => Promise<FetchMFAPreferenceOutput>;
|
|
128
|
+
declare const clearMfaPreferences: () => Promise<void>;
|
|
129
|
+
declare const getUsername: () => Promise<string | undefined>;
|
|
130
|
+
declare const getUserAttributes: () => Promise<FetchUserAttributesOutput | undefined>;
|
|
131
|
+
declare const getMfaPreferences: () => Promise<FetchMFAPreferenceOutput | undefined>;
|
|
132
|
+
declare const isAuthenticated: () => Promise<boolean>;
|
|
133
|
+
declare const isInGroup: (group: string) => Promise<boolean>;
|
|
134
|
+
declare const getGroups: () => Promise<string[] | undefined>;
|
|
135
|
+
declare const getRoles: () => Promise<string[] | undefined>;
|
|
136
|
+
declare const getPreferredRole: () => Promise<string | undefined>;
|
|
137
|
+
declare const getScopes: () => Promise<string[] | undefined>;
|
|
138
|
+
declare const login: (signInHook: ApiConfiguration["signInHook"]) => Promise<string | undefined>;
|
|
139
|
+
declare const logout: (signOutHook: ApiConfiguration["signOutHook"]) => Promise<string | undefined>;
|
|
140
|
+
|
|
141
|
+
declare const TEXT_DOMAIN = "gatey";
|
|
142
|
+
|
|
143
|
+
declare global {
|
|
144
|
+
const Gatey: Gatey;
|
|
145
|
+
}
|
|
146
|
+
interface RoleMapping {
|
|
147
|
+
cognitoGroup?: string;
|
|
148
|
+
wordpressRole?: string;
|
|
149
|
+
}
|
|
150
|
+
interface Settings {
|
|
151
|
+
userPoolConfigurations: {
|
|
152
|
+
default: ResourcesConfig;
|
|
153
|
+
secondary?: ResourcesConfig;
|
|
154
|
+
};
|
|
155
|
+
secondaryUserPoolDomains?: string;
|
|
156
|
+
mappings: RoleMapping[];
|
|
157
|
+
loginMechanisms: LoginMechanism[];
|
|
158
|
+
signUpAttributes: SignUpAttribute[];
|
|
159
|
+
socialProviders?: SocialProvider[];
|
|
160
|
+
integrateWpLogin: boolean;
|
|
161
|
+
cookieExpiration?: number;
|
|
162
|
+
signInPage?: string;
|
|
163
|
+
redirectSignIn?: string;
|
|
164
|
+
redirectSignOut?: string;
|
|
165
|
+
reCaptchaPublicKey?: string;
|
|
166
|
+
customTranslationsUrl?: string;
|
|
167
|
+
useRecaptchaNet?: boolean;
|
|
168
|
+
useRecaptchaEnterprise?: boolean;
|
|
169
|
+
enablePoweredBy?: boolean;
|
|
170
|
+
}
|
|
171
|
+
interface SiteSettings {
|
|
172
|
+
accountId?: string;
|
|
173
|
+
siteId?: string;
|
|
174
|
+
lastUpdate?: number;
|
|
175
|
+
subscriber?: boolean;
|
|
176
|
+
siteKey?: string;
|
|
177
|
+
}
|
|
178
|
+
declare const signOut: () => void;
|
|
179
|
+
declare const setLanguage: (language?: string) => void;
|
|
180
|
+
declare const setDirection: (direction?: "ltr" | "rtl" | "auto") => void;
|
|
181
|
+
interface Cognito {
|
|
182
|
+
readonly store: Promise<Store>;
|
|
183
|
+
readonly observeStore: typeof observeStore;
|
|
184
|
+
readonly setLanguage: typeof setLanguage;
|
|
185
|
+
readonly setDirection: typeof setDirection;
|
|
186
|
+
readonly getUsername: typeof getUsername;
|
|
187
|
+
readonly getUserAttributes: typeof getUserAttributes;
|
|
188
|
+
readonly getMfaPreferences: typeof getMfaPreferences;
|
|
189
|
+
readonly clearMfaPreferences: typeof clearMfaPreferences;
|
|
190
|
+
readonly isAuthenticated: typeof isAuthenticated;
|
|
191
|
+
readonly isInGroup: typeof isInGroup;
|
|
192
|
+
readonly getGroups: typeof getGroups;
|
|
193
|
+
readonly getRoles: typeof getRoles;
|
|
194
|
+
readonly getScopes: typeof getScopes;
|
|
195
|
+
readonly getPreferredRole: typeof getPreferredRole;
|
|
196
|
+
readonly signOut: typeof signOut;
|
|
197
|
+
readonly getAmplifyConfig: typeof getAmplifyConfig;
|
|
198
|
+
readonly get: typeof get;
|
|
199
|
+
readonly post: typeof post;
|
|
200
|
+
readonly put: typeof put;
|
|
201
|
+
readonly del: typeof del;
|
|
202
|
+
readonly head: typeof head;
|
|
203
|
+
readonly patch: typeof patch;
|
|
204
|
+
toSignIn?: () => void;
|
|
205
|
+
toSignUp?: () => void;
|
|
206
|
+
toForgotPassword?: () => void;
|
|
207
|
+
}
|
|
208
|
+
interface Gatey {
|
|
209
|
+
cognito: Cognito;
|
|
210
|
+
settings: Settings;
|
|
211
|
+
siteSettings: SiteSettings;
|
|
212
|
+
nonce: string;
|
|
213
|
+
restUrl: string;
|
|
214
|
+
uploadUrl: string;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
declare const store: Promise<Store>;
|
|
218
|
+
|
|
219
|
+
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 };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{get as re,post as ie,put as se,del as ae,head as ce,patch as ue}from"aws-amplify/api";import{dispatch as S}from"@wordpress/data";import{Amplify as U}from"aws-amplify";import{fetchAuthSession as E,fetchUserAttributes as Z,fetchMFAPreference as ee,getCurrentUser as te,signOut as x,updateMFAPreference as ne}from"aws-amplify/auth";import{fetchAuthSession as K}from"aws-amplify/auth";import{I18n as C}from"aws-amplify/utils";import{createReduxStore as V,register as z,select as B,dispatch as P,subscribe as j}from"@wordpress/data";import{getConfig as X}from"@smart-cloud/wpsuite-core";var g="gatey_account",W="gatey";var d;typeof WpSuite<"u"?d=WpSuite.siteSettings:d={};var l=e=>{e?.username?window.localStorage.setItem(g,JSON.stringify(e)):window.localStorage.removeItem(g)},c=async e=>{let t=JSON.parse(window.localStorage.getItem(g)??"{}"),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&&(l(t),t.loaded=!0,n=!0)}catch(o){console.error(o)}return!n&&t?.username&&(l({}),Gatey.cognito.store.then(async o=>{await y(e?.signOutHook),await P(o).clearAccount()})),t},J=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})}),f(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 u();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=>{P(v).clearAccount()})}return{}}}}})},Y=async()=>{let e=null;return Gatey.settings.customTranslationsUrl&&(e=await fetch(Gatey.settings.customTranslationsUrl+(Gatey.settings.customTranslationsUrl.includes("?")?"&":"?")+"t="+d.lastUpdate).then(t=>t.ok?t.text():null).then(t=>t?JSON.parse(t):null).catch(()=>null)),e??null},q=async()=>{let e=await X("gatey");J(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 Y();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}},H={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"}}},$={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}},Q={},T=async()=>{let e=await q(),t=V("wpsuite/gatey",{reducer(n=e,o){switch(o.type){case"SET_AMPLIFY_CONFIG":return{...n,amplifyConfig:o.amplifyConfig};case"SET_ACCOUNT":return l(o.account),{...n,account:o.account};case"CLEAR_ACCOUNT":return l({}),{...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:H,selectors:$,resolvers:Q});return z(t),t},p=(e,t,n)=>{let o;function r(){let s=B(e).getState(),a=t(s);if(a!==o){let i=o;o=a,n(o,i)}}let h=j(r,e);return r(),h};var m=()=>U.getConfig(),f=(e,t)=>{U.configure(e,t)},u=e=>E(e),I=()=>Z(),R=()=>ee(),b=async(e=!0)=>{let t=e?await c():{};if(t?.username)return t;try{if((await E()).tokens)return{username:(await te()).username,userAttributes:await I(),mfaPreferences:await R()}}catch(n){console.error(n);try{await x()}catch{}}return{}},O=async()=>{await ne({totp:"DISABLED"})},w=()=>c().then(e=>e?.username),G=()=>c().then(e=>e?.userAttributes),N=()=>c().then(e=>e?.mfaPreferences),F=()=>c().then(e=>!!e?.username),_=e=>A().then(t=>t?.includes(e)||!1),A=()=>u().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()=>u().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()=>u().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)}),k=()=>u().then(e=>e.tokens?.accessToken.payload.scope?.split(" ")??[]).catch(e=>{console.error(e)}),oe=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},y=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 x()}catch{}return Gatey.settings.redirectSignOut??t};var ge=()=>{Gatey.cognito.store.then(e=>{p(e,t=>t.nextUrl,async t=>{t&&window.location.assign(t)}),S(e).clearAccount()})},le=e=>{Gatey.cognito.store.then(t=>{S(t).setLanguage(e??"en")})},pe=e=>{Gatey.cognito.store.then(t=>{S(t).setDirection(e??"auto")})};var D=!!Gatey.cognito?.store,de=Gatey.cognito?.store??T();D||(Gatey.cognito={store:de,observeStore:p,setLanguage:le,setDirection:pe,getAmplifyConfig:m,isAuthenticated:F,isInGroup:_,getUsername:w,getUserAttributes:G,getMfaPreferences:N,clearMfaPreferences:O,getGroups:A,getRoles:L,getPreferredRole:M,getScopes:k,signOut:ge,get:re,post:ie,put:se,del:ae,head:ce,patch:ue});D=!0;export{W as TEXT_DOMAIN,O as clearMfaPreferences,f as configureAmplify,m as getAmplifyConfig,A as getGroups,N as getMfaPreferences,M as getPreferredRole,L as getRoles,k as getScopes,G as getUserAttributes,F as isAuthenticated,_ as isInGroup,u as loadAuthSession,R as loadMFAPreferences,I as loadUserAttributes,oe as login,y as logout,p as observeStore,de as store};
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@smart-cloud/gatey-core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Login & SSO with Amazon Cognito",
|
|
5
|
+
"author": "Smart Cloud Solutions Inc.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.cjs",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsup --minify",
|
|
16
|
+
"lint": "eslint 'src/**/*.ts' --report-unused-disable-directives --max-warnings 0",
|
|
17
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
18
|
+
"publish": "WPSUTE_PREMIUM=true && tsup --minify && npm publish --access=public"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@aws-amplify/ui-react": "^6.13.0",
|
|
22
|
+
"@smart-cloud/wpsuite-core": "^1.0.0",
|
|
23
|
+
"@wordpress/data": "^10.31.0",
|
|
24
|
+
"aws-amplify": "^6.15.6"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^24.5.2",
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "^8.44.1",
|
|
29
|
+
"@typescript-eslint/parser": "^8.44.1",
|
|
30
|
+
"eslint": "^9.36.0",
|
|
31
|
+
"ts-node": "^10.9.2",
|
|
32
|
+
"tsup": "^8.5.0",
|
|
33
|
+
"typescript": "^5.9.2",
|
|
34
|
+
"typescript-eslint": "^8.44.1"
|
|
35
|
+
}
|
|
36
|
+
}
|