@trimble-oss/trimble-id-react 1.0.0-rc.1 → 1.0.0-rc.3

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.
@@ -1,27 +1 @@
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
- * @license React
3
- * react-jsx-runtime.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
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
- * @license React
11
- * react-jsx-runtime.development.js
12
- *
13
- * Copyright (c) Facebook, Inc. and its affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
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
-
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
-
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
-
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"})});
1
+ (function(o,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@trimble-oss/trimble-id"),require("es-cookie"),require("jwt-decode"),require("react"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","@trimble-oss/trimble-id","es-cookie","jwt-decode","react","react/jsx-runtime"],c):(o=typeof globalThis<"u"?globalThis:o||self,c(o.ReactTID={},o.trimbleId,o.esCookie,o.jwt_decode,o.React,o.jsxRuntime))})(this,function(o,c,k,W,l,p){"use strict";var le=Object.defineProperty;var de=(o,c,k)=>c in o?le(o,c,{enumerable:!0,configurable:!0,writable:!0,value:k}):o[c]=k;var h=(o,c,k)=>(de(o,typeof c!="symbol"?c+"":c,k),k);function G(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const C=G(k);class V{constructor(){h(this,"generateCache",function(){const e={token:void 0,user:void 0};return{async getToken(){return e.token},async getUser(){return e.user},async storeToken(t){e.token=t},async storeUser(t){e.user=t},clear(){return e.token=void 0,e.user=void 0,Promise.resolve(void 0)}}}())}}class F{constructor(){h(this,"cacheStorage");this.cacheStorage=new V().generateCache}async setToken(e){await this.cacheStorage.storeToken(e)}async setUser(e){await this.cacheStorage.storeUser(e)}async getUser(){return this.cacheStorage.getUser()}async getToken(){return this.cacheStorage.getToken()}async clear(){await this.cacheStorage.clear()}}const S=5*6e4,j=["code","state"],P=i=>i.split("?")[0],q=i=>i.split("?")[1],I=i=>{let e=i;if(!i.startsWith("?"))try{e=new URL(i).search}catch{}return new URLSearchParams(e)},B=(i=window.location.href,e)=>{if(e!=null){const n=P(e),r=P(i??"");if(n!==r)return!1}const t=I(i);for(const n of j)if(!t.has(n))return!1;return!0},$=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}),H="@TID_COOKIE";class z{get(e){const t=C.get(e);if(t==null)throw new Error("Cookie not found");return JSON.parse(t)}set(e,t,n){let r={};window.location.protocol==="https:"&&(r={secure:!0,sameSite:"none"}),n!=null&&n.expires&&(r.expires=n.expires),n!=null&&n.domain&&(r.domain=n.domain),C.set(e,JSON.stringify(t),r)}remove(e,t){const n={};t!=null&&t.domain&&(n.domain=t.domain),C.remove(e,n)}}class Q{constructor(e){h(this,"cookieKey");h(this,"cookiesStorage");this.cookieKey=`${H}.${e.clientId}`,this.cookiesStorage=new z}save(e){this.cookiesStorage.set(this.cookieKey,e,{expires:1})}get(){try{return this.cookiesStorage.get(this.cookieKey)}catch{return}}clear(){this.cookiesStorage.remove(this.cookieKey)}}class R extends Error{}class M extends Error{}class J extends Error{}const u="@trimble-oss/trimble-id-react",g="1.0.0-rc.2",X={configurationEndpoint:"",clientId:"",redirectUrl:"",logoutRedirectUrl:"",scopes:[]};class x{constructor(e){h(this,"tokenProvider");h(this,"cacheManager");h(this,"cookiesManager");h(this,"clientId");h(this,"redirectUrl");h(this,"analyticshttpclient");const{config:t=X}=e;if(this.redirectUrl=t.redirectUrl,t.configurationEndpoint==null||t.configurationEndpoint=="")throw new Error("Configuration endpoint not defined");if(t.clientId==null||t.clientId=="")throw new Error("Consumer key is not defined");this.cookiesManager=new Q({clientId:t.clientId});const n=this.cookiesManager.get(),r=new c.OpenIdEndpointProvider(t.configurationEndpoint);let d=new c.AuthorizationCodeGrantTokenProvider(r,t.clientId,t.redirectUrl).WithScopes(t.scopes);t.logoutRedirectUrl&&(d=d.WithLogoutRedirect(t.logoutRedirectUrl)),(n==null?void 0:n.code_verifier)!=null&&(d=d.WithProofKeyForCodeExchange(n.code_verifier)),this.tokenProvider=d,this.cacheManager=new F,this.clientId=t.clientId,this.analyticshttpclient=c.AnalyticsHttpClient,this.analyticshttpclient.sendInitEvent("TIDClient",this.clientId,u,g)}async loginWithRedirect(e){this.analyticshttpclient.sendMethodEvent(this.loginWithRedirect.name,this.clientId,u,g);const{onRedirect:t}=e||{},n=c.AuthorizationCodeGrantTokenProvider.GenerateCodeVerifier();this.cookiesManager.save({code_verifier:n}),this.tokenProvider=this.tokenProvider.WithProofKeyForCodeExchange(n);const r=await this.tokenProvider.GetOAuthRedirect("state");t!=null?t(r):window.location.assign(r)}async handleCallback(e=window.location.href){const t=this.cookiesManager.get();if(t==null||(t==null?void 0:t.code_verifier)==null)throw new J("Code verifier not available");const n=q(e),r=I(e),d=r.get("identity_provider")??"",T=r.get("state")??"";return await this.tokenProvider.ValidateQuery(n),await this.generateToken(d),{authState:T}}async generateToken(e){var s,w;const t=await this.tokenProvider.RetrieveToken(),n=await this.tokenProvider.RetrieveRefreshToken(),r=await this.tokenProvider.RetrieveIdToken(),d=await this.tokenProvider.RetrieveTokenExpiry(),v=new Date(d).getTime(),m=(w=(s=this.tokenProvider)==null?void 0:s._scopes)==null?void 0:w.join(" ");await this.cacheManager.setToken({scope:m,state:"",session_state:"",identity_provider:e,token_type:"bearer",access_token:t,refresh_token:n,id_token:r,expires_at:v});const U=W(r),_=$(U);await this.cacheManager.setUser(_),await this.reloadCodeVerifier()}async reloadCodeVerifier(){const e=await this.tokenProvider.RetrieveCodeVerifier();this.cookiesManager.save({code_verifier:e}),this.tokenProvider=this.tokenProvider.WithProofKeyForCodeExchange(e)}async getUser(){return this.analyticshttpclient.sendMethodEvent(this.getUser.name,this.clientId,u,g),await this.cacheManager.getUser()}async getAccessTokenSilently(){this.analyticshttpclient.sendMethodEvent(this.getAccessTokenSilently.name,this.clientId,u,g);let e=await this.cacheManager.getToken();if(e==null)throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name,"No token available",this.clientId,u,g),new M("No token available");const t=new Date(new Date().getTime()+S);if((e==null?void 0:e.expires_at)==null||(e==null?void 0:e.expires_at)<t.getTime()){try{await this.tokenProvider.RetrieveToken()}catch(n){throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name,n.message,this.clientId,u,g),new R(n.message)}await this.generateToken((e==null?void 0:e.identity_provider)??""),e=await this.cacheManager.getToken()}return(e==null?void 0:e.access_token)||""}async getTokens(){this.analyticshttpclient.sendMethodEvent(this.getTokens.name,this.clientId,u,g);let e=await this.cacheManager.getToken();if(e==null)throw this.analyticshttpclient.sendExceptionEvent(this.getTokens.name,"No token available",this.clientId,u,g),new M("No token available");const t=new Date(new Date().getTime()+S);if((e==null?void 0:e.expires_at)==null||(e==null?void 0:e.expires_at)<t.getTime()){try{await this.tokenProvider.RetrieveToken()}catch(n){throw this.analyticshttpclient.sendExceptionEvent(this.getTokens.name,n.message,this.clientId,u,g),new R(n.message)}await this.generateToken((e==null?void 0:e.identity_provider)??""),e=await this.cacheManager.getToken()}return{access_token:(e==null?void 0:e.access_token)||"",expires_at:(e==null?void 0:e.expires_at)||0,id_token:(e==null?void 0:e.id_token)||""}}async logout(e){this.analyticshttpclient.sendMethodEvent(this.logout.name,this.clientId,u,g);const{onRedirect:t,disabledAutoRedirect:n}=e||{};this.cacheManager&&await this.cacheManager.clear(),this.cookiesManager&&this.cookiesManager.clear();const r=await this.tokenProvider.GetOAuthLogoutRedirect("state");if(t!=null)return t(r);n||window.location.assign(r)}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 e=await this.cacheManager.getToken();if(e==null)return;const t=e.access_token,n=e.refresh_token||"",r=e.id_token,d=e.expires_at;this.tokenProvider=this.tokenProvider.WithAccessToken(t,d).WithRefreshToken(n).WithIdToken(r)}getBearerTokenHttpClient(e){return new c.BearerTokenHttpClientProvider(this.tokenProvider,e)}getRedirectUrl(){return this.redirectUrl}}const E=l.createContext(null),A=()=>l.useContext(E)??{},Y=(i,e)=>{switch(e.type){case"INIT":return{...i,isLoading:!1,isAuthenticated:e.user!=null,user:e.user,error:void 0};case"GET_TOKENS_COMPLETE":case"HANDLE_CALLBACK_COMPLETE":case"GET_ACCESS_TOKEN_COMPLETE":return{...i,isLoading:!1,isAuthenticated:e.user!=null,user:e.user,error:void 0};case"LOGOUT":return{...i,isAuthenticated:!1,user:void 0};case"ERROR":return{...i,isLoading:!1,error:e.error}}},Z={isLoading:!0,isAuthenticated:!1},ee=i=>{if(i==null||Object.keys(i).length<=0)return!0;const e=Object.keys(i);for(const t of e)if(i[t]!=null&&i[t]!=="")return!1;return!0},te=i=>!ee(i.config),ie=i=>{const{children:e,configurationEndpoint:t,clientId:n,redirectUrl:r,logoutRedirectUrl:d,scopes:T,onRedirectCallback:v,checkRedirectUrlMatch:m}=i;if(l.useContext(E)!=null)throw new Error("TID Provider already defined");const _={config:{configurationEndpoint:t??"",clientId:n??"",redirectUrl:r??"",logoutRedirectUrl:d??"",scopes:T??[""]}},[s]=l.useState(i.tidClient??new x(_)),[w,y]=l.useReducer(Y,Z),O=l.useRef(!1),oe=l.useMemo(()=>m?s.getRedirectUrl():void 0,[m,s]);l.useEffect(()=>{O.current||(i.tidClient!=null&&te({config:{configurationEndpoint:t,clientId:n,redirectUrl:r,logoutRedirectUrl:d,scopes:T}})&&console.warn("When TID client is pass as prop, any client configuration property sent directly to the TID Provider component will be ignored"),O.current=!0,(async()=>{try{let a;if(B(void 0,oe)){const{authState:f}=await s.handleCallback();a=await s.getUser(),v!=null&&v(f)}else await s.loadUserSession(),a=await s.getUser();y({type:"INIT",user:a})}catch(a){let f=a;typeof a=="string"&&(f=new Error(a)),y({type:"ERROR",error:f})}})())},[s,v]);const D=l.useCallback(async()=>{const a=await s.getAccessTokenSilently(),f=await s.getUser();return y({type:"GET_ACCESS_TOKEN_COMPLETE",user:f}),a},[s]),b=l.useCallback(async()=>{const a=await s.getTokens(),f=await s.getUser();return y({type:"GET_TOKENS_COMPLETE",user:f}),a},[s]),L=l.useCallback(async a=>{await s.loginWithRedirect(a)},[s]),K=l.useCallback(async a=>{await s.logout(a),(a==null?void 0:a.disabledAutoRedirect)!=null&&a.disabledAutoRedirect&&y({type:"LOGOUT"})},[s]),N=l.useCallback(async a=>{const{authState:f}=await s.handleCallback(a),ce=await s.getUser();return y({type:"HANDLE_CALLBACK_COMPLETE",user:ce}),{authState:f}},[s]),ae=l.useMemo(()=>({...w,getAccessTokenSilently:D,getTokens:b,loginWithRedirect:L,handleCallback:N,logout:K}),[w,D,b,L,N,K]);return p.jsx(E.Provider,{value:ae,children:e})},ne=A,re=ie,se=({renderComponent:i,loader:e})=>{const{isAuthenticated:t,isLoading:n,loginWithRedirect:r}=A();return l.useEffect(()=>{!n&&!t&&(async()=>await r())()},[n,t,r]),t?i:e||p.jsx(p.Fragment,{})};o.AuthenticationGuard=se,o.TIDClient=x,o.TIDContext=E,o.TIDProvider=re,o.useAuth=ne,Object.defineProperty(o,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": "1.0.0-rc.1",
5
+ "version": "1.0.0-rc.3",
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",
@@ -13,7 +13,7 @@
13
13
  "type": "module",
14
14
  "scripts": {
15
15
  "build": "tsc && vite build",
16
- "test": "jest",
16
+ "test": "jest --coverage",
17
17
  "docs": "typedoc --out ./docs/documentation ./src/ --tsconfig ./tsconfig.json",
18
18
  "lint": "eslint --ext ts,tsx --report-unused-disable-directives",
19
19
  "lint:fix": "eslint --fix 'src/**/*.{jsx,ts,tsx}'",
@@ -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.7",
36
36
  "es-cookie": "^1.4.0",
37
37
  "husky": "^8.0.3",
38
38
  "jwt-decode": "^3.1.2"