@trimble-oss/trimble-id-react 0.1.0-rc.1 → 1.0.0-rc.1
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/README.md +9 -15
- package/dist/TIDClient/TIDClient.d.ts +0 -19
- package/dist/TIDClient/index.d.ts +0 -2
- package/dist/TIDClient/interfaces.d.ts +2 -43
- package/dist/TIDClient/storage/cache-storage/CacheManager.d.ts +1 -34
- package/dist/TIDProvider/TIDProvider.d.ts +1 -9
- package/dist/index.d.ts +0 -1
- package/dist/trimble-id-react.es.js +475 -706
- package/dist/trimble-id-react.umd.js +10 -10
- package/package.json +2 -2
- package/dist/TIDClient/storage/cache-storage/CacheKey.d.ts +0 -46
- package/dist/TIDClient/storage/cache-storage/LocalStorageCache.d.ts +0 -67
- package/dist/TIDClient/storage/cache-storage/SessionStorageCache.d.ts +0 -67
- package/dist/TIDClient/storage/cache-storage/constants.d.ts +0 -15
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(m,T){typeof exports=="object"&&typeof module<"u"?T(exports,require("@trimble-oss/trimble-id"),require("es-cookie"),require("jwt-decode"),require("react")):typeof define=="function"&&define.amd?define(["exports","@trimble-oss/trimble-id","es-cookie","jwt-decode","react"],T):(m=typeof globalThis<"u"?globalThis:m||self,T(m.ReactTID={},m.trimbleId,m.esCookie,m.jwt_decode,m.require$$0))})(this,function(m,T,L,Qe,k){"use strict";var Zt=Object.defineProperty;var qt=(m,T,L)=>T in m?Zt(m,T,{enumerable:!0,configurable:!0,writable:!0,value:L}):m[T]=L;var p=(m,T,L)=>(qt(m,typeof T!="symbol"?T+"":T,L),L);function Ze(a){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const n in a)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(a,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>a[n]})}}return t.default=a,Object.freeze(t)}const ie=Ze(L);class qe{constructor(){p(this,"generateCache",function(){const t={token:void 0,user:void 0};return{async getToken(){return t.token},async getUser(){return t.user},async storeToken(n){t.token=n},async storeUser(n){t.user=n},clear(){return t.token=void 0,t.user=void 0,Promise.resolve(void 0)}}}())}}class et{constructor(t){p(this,"localStorage");p(this,"cacheKey");this.localStorage=window.localStorage,this.cacheKey=t.cacheKey}async getToken(){const t=this.getAuthKey(),n=localStorage.getItem(t);return n?JSON.parse(n):void 0}async getUser(){const t=this.getUserKey(),n=localStorage.getItem(t);return n?JSON.parse(n):void 0}async storeToken(t){const n=this.getAuthKey(),o=JSON.stringify(t);localStorage.setItem(n,o)}async storeUser(t){const n=this.getUserKey(),o=JSON.stringify(t);localStorage.setItem(n,o)}getUserKey(){return this.cacheKey.getUserKey()}getAuthKey(){return this.cacheKey.getAuthKey()}clear(){return this.localStorage.removeItem(this.getAuthKey()),this.localStorage.removeItem(this.getUserKey()),Promise.resolve(void 0)}}const ae="@TID",tt=`${ae}_AUTH_KEY`,rt=`${ae}_USER_KEY`;class nt{constructor(t){p(this,"clientId");p(this,"prefix",ae);p(this,"authSuffix",tt);p(this,"userSuffix",rt);this.clientId=t.client_id}getUserKey(){return`${this.prefix}_${this.userSuffix}_${this.clientId}`}getAuthKey(){return`${this.prefix}_${this.authSuffix}_${this.clientId}`}}class it{constructor(t){p(this,"sessionStorage");p(this,"cacheKey");this.sessionStorage=window.sessionStorage,this.cacheKey=t.cacheKey}async getToken(){const t=this.getAuthKey(),n=sessionStorage.getItem(t);return n?JSON.parse(n):void 0}async getUser(){const t=this.getUserKey(),n=sessionStorage.getItem(t);return n?JSON.parse(n):void 0}async storeToken(t){const n=this.getAuthKey(),o=JSON.stringify(t);sessionStorage.setItem(n,o)}async storeUser(t){const n=this.getUserKey(),o=JSON.stringify(t);sessionStorage.setItem(n,o)}getUserKey(){return this.cacheKey.getUserKey()}getAuthKey(){return this.cacheKey.getAuthKey()}clear(){return this.sessionStorage.removeItem(this.getAuthKey()),this.sessionStorage.removeItem(this.getUserKey()),Promise.resolve(void 0)}}class at{constructor(t){p(this,"persistentStore");p(this,"cacheStorage");p(this,"cacheKey");this.persistentStore=t.persistentStore,this.cacheKey=new nt({client_id:t.clientId}),this.persistentStore==="localStorage"?this.cacheStorage=new et({cacheKey:this.cacheKey}):this.persistentStore==="sessionStorage"?this.cacheStorage=new it({cacheKey:this.cacheKey}):this.cacheStorage=new qe().generateCache}async setToken(t){await this.cacheStorage.storeToken(t)}async setUser(t){await this.cacheStorage.storeUser(t)}async getUser(){return this.cacheStorage.getUser()}async getToken(){return this.cacheStorage.getToken()}async clear(){await this.cacheStorage.clear()}}const me=5*6e4,ot=["code","state"],Ee=a=>a.split("?")[0],st=a=>a.split("?")[1],_e=a=>{let t=a;if(!a.startsWith("?"))try{t=new URL(a).search}catch{}return new URLSearchParams(t)},ct=(a=window.location.href,t)=>{if(t!=null){const o=Ee(t),c=Ee(a??"");if(o!==c)return!1}const n=_e(a);for(const o of ot)if(!n.has(o))return!1;return!0},lt=a=>({id:a.sub,name:`${a.given_name} ${a.family_name}`,given_name:a.given_name,family_name:a.family_name,picture:a.picture,email:a.email,email_verified:a.email_verified,phone_number_verified:!1}),ut="@TID_COOKIE";class ft{get(t){const n=ie.get(t);if(n==null)throw new Error("Cookie not found");return JSON.parse(n)}set(t,n,o){let c={};window.location.protocol==="https:"&&(c={secure:!0,sameSite:"none"}),o!=null&&o.expires&&(c.expires=o.expires),o!=null&&o.domain&&(c.domain=o.domain),ie.set(t,JSON.stringify(n),c)}remove(t,n){const o={};n!=null&&n.domain&&(o.domain=n.domain),ie.remove(t,o)}}class dt{constructor(t){p(this,"cookieKey");p(this,"cookiesStorage");this.cookieKey=`${ut}.${t.clientId}`,this.cookiesStorage=new ft}save(t){this.cookiesStorage.set(this.cookieKey,t,{expires:1})}get(){try{return this.cookiesStorage.get(this.cookieKey)}catch{return}}clear(){this.cookiesStorage.remove(this.cookieKey)}}class Te extends Error{}class ke extends Error{}class ht extends Error{}const A="@trimble-oss/trimble-id-react",K="0.1.0-rc.1",gt={configurationEndpoint:"",clientId:"",redirectUrl:"",logoutRedirectUrl:"",scopes:[]},vt={persistentStore:"in-memory"};class Se{constructor(t){p(this,"tokenProvider");p(this,"cacheManager");p(this,"cookiesManager");p(this,"clientId");p(this,"redirectUrl");p(this,"analyticshttpclient");const{config:n=gt,persistentOptions:o=vt}=t;if(this.redirectUrl=n.redirectUrl,n.configurationEndpoint==null||n.configurationEndpoint=="")throw new Error("Configuration endpoint not defined");if(n.clientId==null||n.clientId=="")throw new Error("Consumer key is not defined");this.cookiesManager=new dt({clientId:n.clientId});const c=this.cookiesManager.get(),w=new T.OpenIdEndpointProvider(n.configurationEndpoint);let S=new T.AuthorizationCodeGrantTokenProvider(w,n.clientId,n.redirectUrl).WithScopes(n.scopes);n.logoutRedirectUrl&&(S=S.WithLogoutRedirect(n.logoutRedirectUrl)),(c==null?void 0:c.code_verifier)!=null&&(S=S.WithProofKeyForCodeExchange(c.code_verifier)),this.tokenProvider=S,this.cacheManager=new at({clientId:n.clientId,persistentStore:o.persistentStore}),this.clientId=n.clientId,this.analyticshttpclient=T.AnalyticsHttpClient,this.analyticshttpclient.sendInitEvent("TIDClient",this.clientId,A,K)}async loginWithRedirect(t){this.analyticshttpclient.sendMethodEvent(this.loginWithRedirect.name,this.clientId,A,K);const{onRedirect:n}=t||{},o=T.AuthorizationCodeGrantTokenProvider.GenerateCodeVerifier();this.cookiesManager.save({code_verifier:o}),this.tokenProvider=this.tokenProvider.WithProofKeyForCodeExchange(o);const c=await this.tokenProvider.GetOAuthRedirect("state");n!=null?n(c):window.location.assign(c)}async handleCallback(t=window.location.href){const n=this.cookiesManager.get();if(n==null||(n==null?void 0:n.code_verifier)==null)throw new ht("Code verifier not available");const o=st(t),c=_e(t),w=c.get("identity_provider")??"",S=c.get("state")??"";return await this.tokenProvider.ValidateQuery(o),await this.generateToken(w),{authState:S}}async generateToken(t){var C,f;const n=await this.tokenProvider.RetrieveToken(),o=await this.tokenProvider.RetrieveRefreshToken(),c=await this.tokenProvider.RetrieveIdToken(),w=await this.tokenProvider.RetrieveTokenExpiry(),P=new Date(w).getTime(),v=(f=(C=this.tokenProvider)==null?void 0:C._scopes)==null?void 0:f.join(" ");await this.cacheManager.setToken({scope:v,state:"",session_state:"",identity_provider:t,token_type:"bearer",access_token:n,refresh_token:o,id_token:c,expires_at:P});const x=Qe(c),R=lt(x);await this.cacheManager.setUser(R),await this.reloadCodeVerifier()}async reloadCodeVerifier(){const t=await this.tokenProvider.RetrieveCodeVerifier();this.cookiesManager.save({code_verifier:t}),this.tokenProvider=this.tokenProvider.WithProofKeyForCodeExchange(t)}async getUser(){return this.analyticshttpclient.sendMethodEvent(this.getUser.name,this.clientId,A,K),await this.cacheManager.getUser()}async getAccessTokenSilently(){this.analyticshttpclient.sendMethodEvent(this.getAccessTokenSilently.name,this.clientId,A,K);let t=await this.cacheManager.getToken();if(t==null)throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name,"No token available",this.clientId,A,K),new ke("No token available");const n=new Date(new Date().getTime()+me);if((t==null?void 0:t.expires_at)==null||(t==null?void 0:t.expires_at)<n.getTime()){try{await this.tokenProvider.RetrieveToken()}catch(o){throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name,o.message,this.clientId,A,K),new Te(o.message)}await this.generateToken((t==null?void 0:t.identity_provider)??""),t=await this.cacheManager.getToken()}return(t==null?void 0:t.access_token)||""}async getTokens(){this.analyticshttpclient.sendMethodEvent(this.getTokens.name,this.clientId,A,K);let t=await this.cacheManager.getToken();if(t==null)throw this.analyticshttpclient.sendExceptionEvent(this.getTokens.name,"No token available",this.clientId,A,K),new ke("No token available");const n=new Date(new Date().getTime()+me);if((t==null?void 0:t.expires_at)==null||(t==null?void 0:t.expires_at)<n.getTime()){try{await this.tokenProvider.RetrieveToken()}catch(o){throw this.analyticshttpclient.sendExceptionEvent(this.getTokens.name,o.message,this.clientId,A,K),new Te(o.message)}await this.generateToken((t==null?void 0:t.identity_provider)??""),t=await this.cacheManager.getToken()}return{access_token:(t==null?void 0:t.access_token)||"",expires_at:(t==null?void 0:t.expires_at)||0,id_token:(t==null?void 0:t.id_token)||""}}async logout(t){this.analyticshttpclient.sendMethodEvent(this.logout.name,this.clientId,A,K);const{onRedirect:n,disabledAutoRedirect:o}=t||{};this.cacheManager&&await this.cacheManager.clear(),this.cookiesManager&&this.cookiesManager.clear();const c=await this.tokenProvider.GetOAuthLogoutRedirect("state");if(n!=null)return n(c);o||window.location.assign(c)}async checkSession(){try{await this.getAccessTokenSilently()}catch{return!1}return!0}async loadUserSession(){await this.loadCacheSessionIntoSDK(),await this.checkSession()||await this.cacheManager.clear()}async loadCacheSessionIntoSDK(){const t=await this.cacheManager.getToken();if(t==null)return;const n=t.access_token,o=t.refresh_token||"",c=t.id_token,w=t.expires_at;this.tokenProvider=this.tokenProvider.WithAccessToken(n,w).WithRefreshToken(o).WithIdToken(c)}getBearerTokenHttpClient(t){return new T.BearerTokenHttpClientProvider(this.tokenProvider,t)}getRedirectUrl(){return this.redirectUrl}}const z=k.createContext(null),Re=()=>k.useContext(z)??{};var oe={exports:{}},Y={};/**
|
|
1
|
+
(function(p,k){typeof exports=="object"&&typeof module<"u"?k(exports,require("@trimble-oss/trimble-id"),require("es-cookie"),require("jwt-decode"),require("react")):typeof define=="function"&&define.amd?define(["exports","@trimble-oss/trimble-id","es-cookie","jwt-decode","react"],k):(p=typeof globalThis<"u"?globalThis:p||self,k(p.ReactTID={},p.trimbleId,p.esCookie,p.jwt_decode,p.require$$0))})(this,function(p,k,L,Xe,T){"use strict";var Bt=Object.defineProperty;var Jt=(p,k,L)=>k in p?Bt(p,k,{enumerable:!0,configurable:!0,writable:!0,value:L}):p[k]=L;var I=(p,k,L)=>(Jt(p,typeof k!="symbol"?k+"":k,L),L);function Qe(i){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const a in i)if(a!=="default"){const o=Object.getOwnPropertyDescriptor(i,a);Object.defineProperty(t,a,o.get?o:{enumerable:!0,get:()=>i[a]})}}return t.default=i,Object.freeze(t)}const re=Qe(L);class Ze{constructor(){I(this,"generateCache",function(){const t={token:void 0,user:void 0};return{async getToken(){return t.token},async getUser(){return t.user},async storeToken(a){t.token=a},async storeUser(a){t.user=a},clear(){return t.token=void 0,t.user=void 0,Promise.resolve(void 0)}}}())}}class $e{constructor(){I(this,"cacheStorage");this.cacheStorage=new Ze().generateCache}async setToken(t){await this.cacheStorage.storeToken(t)}async setUser(t){await this.cacheStorage.storeUser(t)}async getUser(){return this.cacheStorage.getUser()}async getToken(){return this.cacheStorage.getToken()}async clear(){await this.cacheStorage.clear()}}const pe=5*6e4,qe=["code","state"],ye=i=>i.split("?")[0],et=i=>i.split("?")[1],Ee=i=>{let t=i;if(!i.startsWith("?"))try{t=new URL(i).search}catch{}return new URLSearchParams(t)},tt=(i=window.location.href,t)=>{if(t!=null){const o=ye(t),u=ye(i??"");if(o!==u)return!1}const a=Ee(i);for(const o of qe)if(!a.has(o))return!1;return!0},rt=i=>({id:i.sub,name:`${i.given_name} ${i.family_name}`,given_name:i.given_name,family_name:i.family_name,picture:i.picture,email:i.email,email_verified:i.email_verified}),nt="@TID_COOKIE";class at{get(t){const a=re.get(t);if(a==null)throw new Error("Cookie not found");return JSON.parse(a)}set(t,a,o){let u={};window.location.protocol==="https:"&&(u={secure:!0,sameSite:"none"}),o!=null&&o.expires&&(u.expires=o.expires),o!=null&&o.domain&&(u.domain=o.domain),re.set(t,JSON.stringify(a),u)}remove(t,a){const o={};a!=null&&a.domain&&(o.domain=a.domain),re.remove(t,o)}}class it{constructor(t){I(this,"cookieKey");I(this,"cookiesStorage");this.cookieKey=`${nt}.${t.clientId}`,this.cookiesStorage=new at}save(t){this.cookiesStorage.set(this.cookieKey,t,{expires:1})}get(){try{return this.cookiesStorage.get(this.cookieKey)}catch{return}}clear(){this.cookiesStorage.remove(this.cookieKey)}}class me extends Error{}class _e extends Error{}class ot extends Error{}const A="@trimble-oss/trimble-id-react",D="1.0.0-rc.1",st={configurationEndpoint:"",clientId:"",redirectUrl:"",logoutRedirectUrl:"",scopes:[]};class ke{constructor(t){I(this,"tokenProvider");I(this,"cacheManager");I(this,"cookiesManager");I(this,"clientId");I(this,"redirectUrl");I(this,"analyticshttpclient");const{config:a=st}=t;if(this.redirectUrl=a.redirectUrl,a.configurationEndpoint==null||a.configurationEndpoint=="")throw new Error("Configuration endpoint not defined");if(a.clientId==null||a.clientId=="")throw new Error("Consumer key is not defined");this.cookiesManager=new it({clientId:a.clientId});const o=this.cookiesManager.get(),u=new k.OpenIdEndpointProvider(a.configurationEndpoint);let m=new k.AuthorizationCodeGrantTokenProvider(u,a.clientId,a.redirectUrl).WithScopes(a.scopes);a.logoutRedirectUrl&&(m=m.WithLogoutRedirect(a.logoutRedirectUrl)),(o==null?void 0:o.code_verifier)!=null&&(m=m.WithProofKeyForCodeExchange(o.code_verifier)),this.tokenProvider=m,this.cacheManager=new $e,this.clientId=a.clientId,this.analyticshttpclient=k.AnalyticsHttpClient,this.analyticshttpclient.sendInitEvent("TIDClient",this.clientId,A,D)}async loginWithRedirect(t){this.analyticshttpclient.sendMethodEvent(this.loginWithRedirect.name,this.clientId,A,D);const{onRedirect:a}=t||{},o=k.AuthorizationCodeGrantTokenProvider.GenerateCodeVerifier();this.cookiesManager.save({code_verifier:o}),this.tokenProvider=this.tokenProvider.WithProofKeyForCodeExchange(o);const u=await this.tokenProvider.GetOAuthRedirect("state");a!=null?a(u):window.location.assign(u)}async handleCallback(t=window.location.href){const a=this.cookiesManager.get();if(a==null||(a==null?void 0:a.code_verifier)==null)throw new ot("Code verifier not available");const o=et(t),u=Ee(t),m=u.get("identity_provider")??"",O=u.get("state")??"";return await this.tokenProvider.ValidateQuery(o),await this.generateToken(m),{authState:O}}async generateToken(t){var f,C;const a=await this.tokenProvider.RetrieveToken(),o=await this.tokenProvider.RetrieveRefreshToken(),u=await this.tokenProvider.RetrieveIdToken(),m=await this.tokenProvider.RetrieveTokenExpiry(),b=new Date(m).getTime(),y=(C=(f=this.tokenProvider)==null?void 0:f._scopes)==null?void 0:C.join(" ");await this.cacheManager.setToken({scope:y,state:"",session_state:"",identity_provider:t,token_type:"bearer",access_token:a,refresh_token:o,id_token:u,expires_at:b});const M=Xe(u),R=rt(M);await this.cacheManager.setUser(R),await this.reloadCodeVerifier()}async reloadCodeVerifier(){const t=await this.tokenProvider.RetrieveCodeVerifier();this.cookiesManager.save({code_verifier:t}),this.tokenProvider=this.tokenProvider.WithProofKeyForCodeExchange(t)}async getUser(){return this.analyticshttpclient.sendMethodEvent(this.getUser.name,this.clientId,A,D),await this.cacheManager.getUser()}async getAccessTokenSilently(){this.analyticshttpclient.sendMethodEvent(this.getAccessTokenSilently.name,this.clientId,A,D);let t=await this.cacheManager.getToken();if(t==null)throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name,"No token available",this.clientId,A,D),new _e("No token available");const a=new Date(new Date().getTime()+pe);if((t==null?void 0:t.expires_at)==null||(t==null?void 0:t.expires_at)<a.getTime()){try{await this.tokenProvider.RetrieveToken()}catch(o){throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name,o.message,this.clientId,A,D),new me(o.message)}await this.generateToken((t==null?void 0:t.identity_provider)??""),t=await this.cacheManager.getToken()}return(t==null?void 0:t.access_token)||""}async getTokens(){this.analyticshttpclient.sendMethodEvent(this.getTokens.name,this.clientId,A,D);let t=await this.cacheManager.getToken();if(t==null)throw this.analyticshttpclient.sendExceptionEvent(this.getTokens.name,"No token available",this.clientId,A,D),new _e("No token available");const a=new Date(new Date().getTime()+pe);if((t==null?void 0:t.expires_at)==null||(t==null?void 0:t.expires_at)<a.getTime()){try{await this.tokenProvider.RetrieveToken()}catch(o){throw this.analyticshttpclient.sendExceptionEvent(this.getTokens.name,o.message,this.clientId,A,D),new me(o.message)}await this.generateToken((t==null?void 0:t.identity_provider)??""),t=await this.cacheManager.getToken()}return{access_token:(t==null?void 0:t.access_token)||"",expires_at:(t==null?void 0:t.expires_at)||0,id_token:(t==null?void 0:t.id_token)||""}}async logout(t){this.analyticshttpclient.sendMethodEvent(this.logout.name,this.clientId,A,D);const{onRedirect:a,disabledAutoRedirect:o}=t||{};this.cacheManager&&await this.cacheManager.clear(),this.cookiesManager&&this.cookiesManager.clear();const u=await this.tokenProvider.GetOAuthLogoutRedirect("state");if(a!=null)return a(u);o||window.location.assign(u)}async checkSession(){try{await this.getAccessTokenSilently()}catch{return!1}return!0}async loadUserSession(){await this.loadCacheSessionIntoSDK(),await this.checkSession()||await this.cacheManager.clear()}async loadCacheSessionIntoSDK(){const t=await this.cacheManager.getToken();if(t==null)return;const a=t.access_token,o=t.refresh_token||"",u=t.id_token,m=t.expires_at;this.tokenProvider=this.tokenProvider.WithAccessToken(a,m).WithRefreshToken(o).WithIdToken(u)}getBearerTokenHttpClient(t){return new k.BearerTokenHttpClientProvider(this.tokenProvider,t)}getRedirectUrl(){return this.redirectUrl}}const z=T.createContext(null),Te=()=>T.useContext(z)??{};var ne={exports:{}},K={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var Re;function ct(){if(Re)return K;Re=1;var i=T,t=Symbol.for("react.element"),a=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,u=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,m={key:!0,ref:!0,__self:!0,__source:!0};function O(b,y,M){var R,f={},C=null,x=null;M!==void 0&&(C=""+M),y.key!==void 0&&(C=""+y.key),y.ref!==void 0&&(x=y.ref);for(R in y)o.call(y,R)&&!m.hasOwnProperty(R)&&(f[R]=y[R]);if(b&&b.defaultProps)for(R in y=b.defaultProps,y)f[R]===void 0&&(f[R]=y[R]);return{$$typeof:t,type:b,key:C,ref:x,props:f,_owner:u.current}}return K.Fragment=a,K.jsx=O,K.jsxs=O,K}var Y={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
18
|
-
`+
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
21
|
-
`+
|
|
17
|
+
*/var we;function lt(){return we||(we=1,process.env.NODE_ENV!=="production"&&function(){var i=T,t=Symbol.for("react.element"),a=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),u=Symbol.for("react.strict_mode"),m=Symbol.for("react.profiler"),O=Symbol.for("react.provider"),b=Symbol.for("react.context"),y=Symbol.for("react.forward_ref"),M=Symbol.for("react.suspense"),R=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),C=Symbol.for("react.lazy"),x=Symbol.for("react.offscreen"),G=Symbol.iterator,ie="@@iterator";function H(e){if(e===null||typeof e!="object")return null;var r=G&&e[G]||e[ie];return typeof r=="function"?r:null}var j=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function _(e){{for(var r=arguments.length,n=new Array(r>1?r-1:0),s=1;s<r;s++)n[s-1]=arguments[s];X("error",e,n)}}function X(e,r,n){{var s=j.ReactDebugCurrentFrame,d=s.getStackAddendum();d!==""&&(r+="%s",n=n.concat([d]));var h=n.map(function(l){return String(l)});h.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,h)}}var Q=!1,oe=!1,v=!1,S=!1,se=!1,be;be=Symbol.for("react.module.reference");function Et(e){return!!(typeof e=="string"||typeof e=="function"||e===o||e===m||se||e===u||e===M||e===R||S||e===x||Q||oe||v||typeof e=="object"&&e!==null&&(e.$$typeof===C||e.$$typeof===f||e.$$typeof===O||e.$$typeof===b||e.$$typeof===y||e.$$typeof===be||e.getModuleId!==void 0))}function mt(e,r,n){var s=e.displayName;if(s)return s;var d=r.displayName||r.name||"";return d!==""?n+"("+d+")":n}function Ce(e){return e.displayName||"Context"}function U(e){if(e==null)return null;if(typeof e.tag=="number"&&_("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case o:return"Fragment";case a:return"Portal";case m:return"Profiler";case u:return"StrictMode";case M:return"Suspense";case R:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case b:var r=e;return Ce(r)+".Consumer";case O:var n=e;return Ce(n._context)+".Provider";case y:return mt(e,e.render,"ForwardRef");case f:var s=e.displayName||null;return s!==null?s:U(e.type)||"Memo";case C:{var d=e,h=d._payload,l=d._init;try{return U(l(h))}catch{return null}}}return null}var W=Object.assign,B=0,Se,Pe,Oe,xe,Ie,Ae,De;function Me(){}Me.__reactDisabledLog=!0;function _t(){{if(B===0){Se=console.log,Pe=console.info,Oe=console.warn,xe=console.error,Ie=console.group,Ae=console.groupCollapsed,De=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Me,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}B++}}function kt(){{if(B--,B===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:W({},e,{value:Se}),info:W({},e,{value:Pe}),warn:W({},e,{value:Oe}),error:W({},e,{value:xe}),group:W({},e,{value:Ie}),groupCollapsed:W({},e,{value:Ae}),groupEnd:W({},e,{value:De})})}B<0&&_("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ce=j.ReactCurrentDispatcher,le;function Z(e,r,n){{if(le===void 0)try{throw Error()}catch(d){var s=d.stack.trim().match(/\n( *(at )?)/);le=s&&s[1]||""}return`
|
|
18
|
+
`+le+e}}var ue=!1,$;{var Tt=typeof WeakMap=="function"?WeakMap:Map;$=new Tt}function je(e,r){if(!e||ue)return"";{var n=$.get(e);if(n!==void 0)return n}var s;ue=!0;var d=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var h;h=ce.current,ce.current=null,_t();try{if(r){var l=function(){throw Error()};if(Object.defineProperty(l.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(l,[])}catch(F){s=F}Reflect.construct(e,[],l)}else{try{l.call()}catch(F){s=F}e.call(l.prototype)}}else{try{throw Error()}catch(F){s=F}e()}}catch(F){if(F&&s&&typeof F.stack=="string"){for(var c=F.stack.split(`
|
|
19
|
+
`),w=s.stack.split(`
|
|
20
|
+
`),g=c.length-1,E=w.length-1;g>=1&&E>=0&&c[g]!==w[E];)E--;for(;g>=1&&E>=0;g--,E--)if(c[g]!==w[E]){if(g!==1||E!==1)do if(g--,E--,E<0||c[g]!==w[E]){var P=`
|
|
21
|
+
`+c[g].replace(" at new "," at ");return e.displayName&&P.includes("<anonymous>")&&(P=P.replace("<anonymous>",e.displayName)),typeof e=="function"&&$.set(e,P),P}while(g>=1&&E>=0);break}}}finally{ue=!1,ce.current=h,kt(),Error.prepareStackTrace=d}var V=e?e.displayName||e.name:"",He=V?Z(V):"";return typeof e=="function"&&$.set(e,He),He}function Rt(e,r,n){return je(e,!1)}function wt(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function q(e,r,n){if(e==null)return"";if(typeof e=="function")return je(e,wt(e));if(typeof e=="string")return Z(e);switch(e){case M:return Z("Suspense");case R:return Z("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case y:return Rt(e.render);case f:return q(e.type,r,n);case C:{var s=e,d=s._payload,h=s._init;try{return q(h(d),r,n)}catch{}}}return""}var ee=Object.prototype.hasOwnProperty,Ue={},Fe=j.ReactDebugCurrentFrame;function te(e){if(e){var r=e._owner,n=q(e.type,e._source,r?r.type:null);Fe.setExtraStackFrame(n)}else Fe.setExtraStackFrame(null)}function bt(e,r,n,s,d){{var h=Function.call.bind(ee);for(var l in e)if(h(e,l)){var c=void 0;try{if(typeof e[l]!="function"){var w=Error((s||"React class")+": "+n+" type `"+l+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[l]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw w.name="Invariant Violation",w}c=e[l](r,l,s,n,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(g){c=g}c&&!(c instanceof Error)&&(te(d),_("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",s||"React class",n,l,typeof c),te(null)),c instanceof Error&&!(c.message in Ue)&&(Ue[c.message]=!0,te(d),_("Failed %s type: %s",n,c.message),te(null))}}}var Ct=Array.isArray;function fe(e){return Ct(e)}function St(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,n=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n}}function Pt(e){try{return Le(e),!1}catch{return!0}}function Le(e){return""+e}function We(e){if(Pt(e))return _("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",St(e)),Le(e)}var J=j.ReactCurrentOwner,Ot={key:!0,ref:!0,__self:!0,__source:!0},Ne,Ve,de;de={};function xt(e){if(ee.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function It(e){if(ee.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function At(e,r){if(typeof e.ref=="string"&&J.current&&r&&J.current.stateNode!==r){var n=U(J.current.type);de[n]||(_('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',U(J.current.type),e.ref),de[n]=!0)}}function Dt(e,r){{var n=function(){Ne||(Ne=!0,_("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}}function Mt(e,r){{var n=function(){Ve||(Ve=!0,_("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};n.isReactWarning=!0,Object.defineProperty(e,"ref",{get:n,configurable:!0})}}var jt=function(e,r,n,s,d,h,l){var c={$$typeof:t,type:e,key:r,ref:n,props:l,_owner:h};return c._store={},Object.defineProperty(c._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(c,"_self",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.defineProperty(c,"_source",{configurable:!1,enumerable:!1,writable:!1,value:d}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c};function Ut(e,r,n,s,d){{var h,l={},c=null,w=null;n!==void 0&&(We(n),c=""+n),It(r)&&(We(r.key),c=""+r.key),xt(r)&&(w=r.ref,At(r,d));for(h in r)ee.call(r,h)&&!Ot.hasOwnProperty(h)&&(l[h]=r[h]);if(e&&e.defaultProps){var g=e.defaultProps;for(h in g)l[h]===void 0&&(l[h]=g[h])}if(c||w){var E=typeof e=="function"?e.displayName||e.name||"Unknown":e;c&&Dt(l,E),w&&Mt(l,E)}return jt(e,c,w,d,s,J.current,l)}}var he=j.ReactCurrentOwner,Ke=j.ReactDebugCurrentFrame;function N(e){if(e){var r=e._owner,n=q(e.type,e._source,r?r.type:null);Ke.setExtraStackFrame(n)}else Ke.setExtraStackFrame(null)}var ve;ve=!1;function ge(e){return typeof e=="object"&&e!==null&&e.$$typeof===t}function Ye(){{if(he.current){var e=U(he.current.type);if(e)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+e+"`."}return""}}function
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function Ft(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),n=e.lineNumber;return`
|
|
24
24
|
|
|
25
|
-
Check your code at `+r+":"+
|
|
25
|
+
Check your code at `+r+":"+n+"."}return""}}var Ge={};function Lt(e){{var r=Ye();if(!r){var n=typeof e=="string"?e:e.displayName||e.name;n&&(r=`
|
|
26
26
|
|
|
27
|
-
Check the top-level render call using <`+
|
|
27
|
+
Check the top-level render call using <`+n+">.")}return r}}function Be(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var n=Lt(r);if(Ge[n])return;Ge[n]=!0;var s="";e&&e._owner&&e._owner!==he.current&&(s=" It was passed a child from "+U(e._owner.type)+"."),N(e),_('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',n,s),N(null)}}function Je(e,r){{if(typeof e!="object")return;if(fe(e))for(var n=0;n<e.length;n++){var s=e[n];ge(s)&&Be(s,r)}else if(ge(e))e._store&&(e._store.validated=!0);else if(e){var d=H(e);if(typeof d=="function"&&d!==e.entries)for(var h=d.call(e),l;!(l=h.next()).done;)ge(l.value)&&Be(l.value,r)}}}function Wt(e){{var r=e.type;if(r==null||typeof r=="string")return;var n;if(typeof r=="function")n=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===y||r.$$typeof===f))n=r.propTypes;else return;if(n){var s=U(r);bt(n,e.props,"prop",s,e)}else if(r.PropTypes!==void 0&&!ve){ve=!0;var d=U(r);_("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",d||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&_("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Nt(e){{for(var r=Object.keys(e.props),n=0;n<r.length;n++){var s=r[n];if(s!=="children"&&s!=="key"){N(e),_("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",s),N(null);break}}e.ref!==null&&(N(e),_("Invalid attribute `ref` supplied to `React.Fragment`."),N(null))}}function ze(e,r,n,s,d,h){{var l=Et(e);if(!l){var c="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(c+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var w=Ft(d);w?c+=w:c+=Ye();var g;e===null?g="null":fe(e)?g="array":e!==void 0&&e.$$typeof===t?(g="<"+(U(e.type)||"Unknown")+" />",c=" Did you accidentally export a JSX literal instead of a component?"):g=typeof e,_("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",g,c)}var E=Ut(e,r,n,d,h);if(E==null)return E;if(l){var P=r.children;if(P!==void 0)if(s)if(fe(P)){for(var V=0;V<P.length;V++)Je(P[V],e);Object.freeze&&Object.freeze(P)}else _("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Je(P,e)}return e===o?Nt(E):Wt(E),E}}function Vt(e,r,n){return ze(e,r,n,!0)}function Kt(e,r,n){return ze(e,r,n,!1)}var Yt=Kt,Gt=Vt;Y.Fragment=o,Y.jsx=Yt,Y.jsxs=Gt}()),Y}process.env.NODE_ENV==="production"?ne.exports=ct():ne.exports=lt();var ae=ne.exports;const ut=(i,t)=>{switch(t.type){case"INIT":return{...i,isLoading:!1,isAuthenticated:t.user!=null,user:t.user,error:void 0};case"GET_TOKENS_COMPLETE":case"HANDLE_CALLBACK_COMPLETE":case"GET_ACCESS_TOKEN_COMPLETE":return{...i,isLoading:!1,isAuthenticated:t.user!=null,user:t.user,error:void 0};case"LOGOUT":return{...i,isAuthenticated:!1,user:void 0};case"ERROR":return{...i,isLoading:!1,error:t.error}}},ft={isLoading:!0,isAuthenticated:!1},dt=i=>{if(i==null||Object.keys(i).length<=0)return!0;const t=Object.keys(i);for(const a of t)if(i[a]!=null&&i[a]!=="")return!1;return!0},ht=i=>!dt(i.config),vt=i=>{const{children:t,configurationEndpoint:a,clientId:o,redirectUrl:u,logoutRedirectUrl:m,scopes:O,onRedirectCallback:b,checkRedirectUrlMatch:y}=i;if(T.useContext(z)!=null)throw new Error("TID Provider already defined");const R={config:{configurationEndpoint:a??"",clientId:o??"",redirectUrl:u??"",logoutRedirectUrl:m??"",scopes:O??[""]}},[f]=T.useState(i.tidClient??new ke(R)),[C,x]=T.useReducer(ut,ft),G=T.useRef(!1),ie=T.useMemo(()=>y?f.getRedirectUrl():void 0,[y,f]);T.useEffect(()=>{G.current||(i.tidClient!=null&&ht({config:{configurationEndpoint:a,clientId:o,redirectUrl:u,logoutRedirectUrl:m,scopes:O}})&&console.warn("When TID client is pass as prop, any client configuration property sent directly to the TID Provider component will be ignored"),G.current=!0,(async()=>{try{let v;if(tt(void 0,ie)){const{authState:S}=await f.handleCallback();v=await f.getUser(),b!=null&&b(S)}else await f.loadUserSession(),v=await f.getUser();x({type:"INIT",user:v})}catch(v){let S=v;typeof v=="string"&&(S=new Error(v)),x({type:"ERROR",error:S})}})())},[f,b]);const H=T.useCallback(async()=>{const v=await f.getAccessTokenSilently(),S=await f.getUser();return x({type:"GET_ACCESS_TOKEN_COMPLETE",user:S}),v},[f]),j=T.useCallback(async()=>{const v=await f.getTokens(),S=await f.getUser();return x({type:"GET_TOKENS_COMPLETE",user:S}),v},[f]),_=T.useCallback(async v=>{await f.loginWithRedirect(v)},[f]),X=T.useCallback(async v=>{await f.logout(v),(v==null?void 0:v.disabledAutoRedirect)!=null&&v.disabledAutoRedirect&&x({type:"LOGOUT"})},[f]),Q=T.useCallback(async v=>{const{authState:S}=await f.handleCallback(v),se=await f.getUser();return x({type:"HANDLE_CALLBACK_COMPLETE",user:se}),{authState:S}},[f]),oe=T.useMemo(()=>({...C,getAccessTokenSilently:H,getTokens:j,loginWithRedirect:_,handleCallback:Q,logout:X}),[C,H,j,_,Q,X]);return ae.jsx(z.Provider,{value:oe,children:t})},gt=Te,pt=vt,yt=({renderComponent:i,loader:t})=>{const{isAuthenticated:a,isLoading:o,loginWithRedirect:u}=Te();return T.useEffect(()=>{!o&&!a&&(async()=>await u())()},[o,a,u]),a?i:t||ae.jsx(ae.Fragment,{})};p.AuthenticationGuard=yt,p.TIDClient=ke,p.TIDContext=z,p.TIDProvider=pt,p.useAuth=gt,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
{
|
|
3
3
|
"name": "@trimble-oss/trimble-id-react",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "1.0.0-rc.1",
|
|
6
6
|
"homepage": "https://github.com/trimble-oss/trimble-id-sdk-docs-for-react",
|
|
7
7
|
"author": "Trimble developers <developers@trimble.com>",
|
|
8
8
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"module": "./dist/trimble-id-react.es.js",
|
|
33
33
|
"types": "./dist/index.d.ts",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@trimble-oss/trimble-id": "0.0.6",
|
|
35
|
+
"@trimble-oss/trimble-id": "^0.0.6",
|
|
36
36
|
"es-cookie": "^1.4.0",
|
|
37
37
|
"husky": "^8.0.3",
|
|
38
38
|
"jwt-decode": "^3.1.2"
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
interface CacheKeyOptions {
|
|
2
|
-
/**
|
|
3
|
-
* Client id of the application created in trimble developer console
|
|
4
|
-
* @type {string}
|
|
5
|
-
*/
|
|
6
|
-
client_id: string;
|
|
7
|
-
}
|
|
8
|
-
/** Class representing the caching keys for storing and retrieving user and token from auth */
|
|
9
|
-
export declare class CacheKey {
|
|
10
|
-
/**
|
|
11
|
-
* Client id of the application created in trimble developer console
|
|
12
|
-
* @type {string}
|
|
13
|
-
*/
|
|
14
|
-
private readonly clientId;
|
|
15
|
-
/**
|
|
16
|
-
* Prefix value of the key, by default the prefix is based on the constant PREFIX_KEY
|
|
17
|
-
* @type {string}
|
|
18
|
-
*/
|
|
19
|
-
private readonly prefix;
|
|
20
|
-
/**
|
|
21
|
-
* Suffix value use it to generate the key to store and retrieve the token, by default the prefix is based on the constant AUTH_KEY
|
|
22
|
-
* @type {string}
|
|
23
|
-
*/
|
|
24
|
-
private readonly authSuffix;
|
|
25
|
-
/**
|
|
26
|
-
* Suffix value use it to generate the key to store and retrieve the user, by default the prefix is based on the constant USER_KEY
|
|
27
|
-
* @type {string}
|
|
28
|
-
*/
|
|
29
|
-
private readonly userSuffix;
|
|
30
|
-
/**
|
|
31
|
-
* Initialized the cache key
|
|
32
|
-
* @param {CacheKeyOptions} cacheKeyOptions - Cache key options to edit the default values
|
|
33
|
-
*/
|
|
34
|
-
constructor(cacheKeyOptions: CacheKeyOptions);
|
|
35
|
-
/**
|
|
36
|
-
* Get key to store/retrieve user
|
|
37
|
-
* @return {string} Key for the user
|
|
38
|
-
*/
|
|
39
|
-
getUserKey(): string;
|
|
40
|
-
/**
|
|
41
|
-
* Get key to store/retrieve token
|
|
42
|
-
* @return {string} Key for the token
|
|
43
|
-
*/
|
|
44
|
-
getAuthKey(): string;
|
|
45
|
-
}
|
|
46
|
-
export {};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { CacheStorage, TIDAuthToken, TIDUser } from '../../interfaces';
|
|
2
|
-
import { CacheKey } from './CacheKey';
|
|
3
|
-
export interface LocalStorageCacheOptions {
|
|
4
|
-
/**
|
|
5
|
-
* The cache key represents the keys for storing and retrieving user and token from auth
|
|
6
|
-
* @type {CacheKey}
|
|
7
|
-
*/
|
|
8
|
-
cacheKey: CacheKey;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Class representing localstorage caching
|
|
12
|
-
* NOTE: This type storage do not expired so it will persist even if the user close the browser
|
|
13
|
-
*/
|
|
14
|
-
export declare class LocalStorageCache implements CacheStorage {
|
|
15
|
-
/**
|
|
16
|
-
* Local storage from the browser
|
|
17
|
-
* @type {Storage}
|
|
18
|
-
*/
|
|
19
|
-
private readonly localStorage;
|
|
20
|
-
/**
|
|
21
|
-
* The cache key represents the keys for storing and retrieving user and token from auth
|
|
22
|
-
* @type {CacheKey}
|
|
23
|
-
*/
|
|
24
|
-
private readonly cacheKey;
|
|
25
|
-
/**
|
|
26
|
-
* Initialized configuration to store information into local storage
|
|
27
|
-
* @param {LocalStorageCacheOptions} options - Configuration for caching in localstorage
|
|
28
|
-
*/
|
|
29
|
-
constructor(options: LocalStorageCacheOptions);
|
|
30
|
-
/**
|
|
31
|
-
* Get token store in localstorage
|
|
32
|
-
* @return {Promise<TIDAuthToken | undefined>} - Token store in localstorage
|
|
33
|
-
*/
|
|
34
|
-
getToken(): Promise<TIDAuthToken | undefined>;
|
|
35
|
-
/**
|
|
36
|
-
* Get user store in localstorage
|
|
37
|
-
* @return {Promise<TIDUser | undefined>} - User store in localstorage
|
|
38
|
-
*/
|
|
39
|
-
getUser(): Promise<TIDUser | undefined>;
|
|
40
|
-
/**
|
|
41
|
-
* Store token in localstorage
|
|
42
|
-
* @param {TIDAuthToken} token - Token that you want to store in localstorage
|
|
43
|
-
* @return {Promise<void>} Empty promise
|
|
44
|
-
*/
|
|
45
|
-
storeToken(authToken: TIDAuthToken): Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Store user in cache
|
|
48
|
-
* @param {TIDUser} user - User that you want to store in localstorage
|
|
49
|
-
* @return {Promise<void>} Empty promise
|
|
50
|
-
*/
|
|
51
|
-
storeUser(user: TIDUser): Promise<void>;
|
|
52
|
-
/**
|
|
53
|
-
* Get the full key from the cachekey for the user
|
|
54
|
-
* @return {string} - Full key to get the token from the localstorage
|
|
55
|
-
*/
|
|
56
|
-
getUserKey(): string;
|
|
57
|
-
/**
|
|
58
|
-
* Get the full key from the cachekey for the token
|
|
59
|
-
* @return {string} - Full key to get the token from the localstorage
|
|
60
|
-
*/
|
|
61
|
-
getAuthKey(): string;
|
|
62
|
-
/**
|
|
63
|
-
* The clear the cache from the localstorage
|
|
64
|
-
* @return {Promise<void>} Empty promise
|
|
65
|
-
*/
|
|
66
|
-
clear(): Promise<void>;
|
|
67
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { CacheStorage, TIDAuthToken, TIDUser } from '../../interfaces';
|
|
2
|
-
import { CacheKey } from './CacheKey';
|
|
3
|
-
export interface SessionStorageCacheOptions {
|
|
4
|
-
/**
|
|
5
|
-
* The cache key represents the keys for storing and retrieving user and token from auth
|
|
6
|
-
* @type {CacheKey}
|
|
7
|
-
*/
|
|
8
|
-
cacheKey: CacheKey;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Class representing session storage caching
|
|
12
|
-
* NOTE: This type storage is cleared when the page session ends
|
|
13
|
-
*/
|
|
14
|
-
export declare class SessionStorageCache implements CacheStorage {
|
|
15
|
-
/**
|
|
16
|
-
* Session storage from the browser
|
|
17
|
-
* @type {Storage}
|
|
18
|
-
*/
|
|
19
|
-
private readonly sessionStorage;
|
|
20
|
-
/**
|
|
21
|
-
* The cache key represents the keys for storing and retrieving user and token from auth
|
|
22
|
-
* @type {CacheKey}
|
|
23
|
-
*/
|
|
24
|
-
private readonly cacheKey;
|
|
25
|
-
/**
|
|
26
|
-
* Initialized configuration to store information into session storage
|
|
27
|
-
* @param {SessionStorageCacheOptions} options - Configuration for caching in session storage
|
|
28
|
-
*/
|
|
29
|
-
constructor(options: SessionStorageCacheOptions);
|
|
30
|
-
/**
|
|
31
|
-
* Get token store in session storage
|
|
32
|
-
* @return {Promise<TIDAuthToken | undefined>} - Token store in session storage
|
|
33
|
-
*/
|
|
34
|
-
getToken(): Promise<TIDAuthToken | undefined>;
|
|
35
|
-
/**
|
|
36
|
-
* Get user store in session storage
|
|
37
|
-
* @return {Promise<TIDUser | undefined>} - User store in session storage
|
|
38
|
-
*/
|
|
39
|
-
getUser(): Promise<TIDUser | undefined>;
|
|
40
|
-
/**
|
|
41
|
-
* Store token in session storage
|
|
42
|
-
* @param {TIDAuthToken} authToken - Token that you want to store in session storage
|
|
43
|
-
* @return {Promise<void>} Empty promise
|
|
44
|
-
*/
|
|
45
|
-
storeToken(authToken: TIDAuthToken): Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Store user in cache
|
|
48
|
-
* @param {TIDUser} user - User that you want to store in session storage
|
|
49
|
-
* @return {Promise<void>} Empty promise
|
|
50
|
-
*/
|
|
51
|
-
storeUser(user: TIDUser): Promise<void>;
|
|
52
|
-
/**
|
|
53
|
-
* Get the full key from the cachekey for the user
|
|
54
|
-
* @return {string} - Full key to get the token from the session storage
|
|
55
|
-
*/
|
|
56
|
-
getUserKey(): string;
|
|
57
|
-
/**
|
|
58
|
-
* Get the full key from the cachekey for the token
|
|
59
|
-
* @return {string} - Full key to get the token from the session storage
|
|
60
|
-
*/
|
|
61
|
-
getAuthKey(): string;
|
|
62
|
-
/**
|
|
63
|
-
* The clear the cache from the session storage
|
|
64
|
-
* @return {Promise<void>} Empty promise
|
|
65
|
-
*/
|
|
66
|
-
clear(): Promise<void>;
|
|
67
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default value of the prefix key use it to store the token and the user
|
|
3
|
-
* @type {string}
|
|
4
|
-
*/
|
|
5
|
-
export declare const PREFIX_KEY: string;
|
|
6
|
-
/**
|
|
7
|
-
* Default value of the suffix key use it to store the token
|
|
8
|
-
* @type {string}
|
|
9
|
-
*/
|
|
10
|
-
export declare const AUTH_KEY: string;
|
|
11
|
-
/**
|
|
12
|
-
* Default value of the suffix key use it to store the user
|
|
13
|
-
* @type {string}
|
|
14
|
-
*/
|
|
15
|
-
export declare const USER_KEY: string;
|