@trimble-oss/trimble-id-react 0.0.4-rc.1 → 0.0.4-rc.2
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.
|
@@ -444,7 +444,7 @@ class zt extends Error {
|
|
|
444
444
|
}
|
|
445
445
|
class Ht extends Error {
|
|
446
446
|
}
|
|
447
|
-
const D = "@trimble-oss/trimble-id-react", M = "0.0.4-rc.
|
|
447
|
+
const D = "@trimble-oss/trimble-id-react", M = "0.0.4-rc.2", qt = {
|
|
448
448
|
configurationEndpoint: "",
|
|
449
449
|
clientId: "",
|
|
450
450
|
redirectUrl: "",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(m,S){typeof exports=="object"&&typeof module<"u"?S(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"],S):(m=typeof globalThis<"u"?globalThis:m||self,S(m.ReactTID={},m.trimbleId,m.esCookie,m.jwt_decode,m.require$$0))})(this,function(m,S,j,He,T){"use strict";var Zt=Object.defineProperty;var qt=(m,S,j)=>S in m?Zt(m,S,{enumerable:!0,configurable:!0,writable:!0,value:j}):m[S]=j;var p=(m,S,j)=>(qt(m,typeof S!="symbol"?S+"":S,j),j);function $e(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 re=$e(j);class Xe{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 Qe{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 ne="@TID",Ze=`${ne}_AUTH_KEY`,qe=`${ne}_USER_KEY`;class et{constructor(t){p(this,"clientId");p(this,"prefix",ne);p(this,"authSuffix",Ze);p(this,"userSuffix",qe);this.clientId=t.client_id}getUserKey(){return`${this.prefix}_${this.userSuffix}_${this.clientId}`}getAuthKey(){return`${this.prefix}_${this.authSuffix}_${this.clientId}`}}class tt{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 rt{constructor(t){p(this,"persistentStore");p(this,"cacheStorage");p(this,"cacheKey");this.persistentStore=t.persistentStore,this.cacheKey=new et({client_id:t.clientId}),this.persistentStore==="localStorage"?this.cacheStorage=new Qe({cacheKey:this.cacheKey}):this.persistentStore==="sessionStorage"?this.cacheStorage=new tt({cacheKey:this.cacheKey}):this.cacheStorage=new Xe().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 nt=5*6e4,it=["code","state"],pe=a=>a.split("?")[0],at=a=>a.split("?")[1],me=a=>{let t=a;if(!a.startsWith("?"))try{t=new URL(a).search}catch{}return new URLSearchParams(t)},ot=(a=window.location.href,t)=>{if(t!=null){const o=pe(t),c=pe(a??"");if(o!==c)return!1}const n=me(a);for(const o of it)if(!n.has(o))return!1;return!0},st=a=>({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}),ct="@TID_COOKIE";class lt{get(t){const n=re.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),re.set(t,JSON.stringify(n),c)}remove(t,n){const o={};n!=null&&n.domain&&(o.domain=n.domain),re.remove(t,o)}}class ut{constructor(t){p(this,"cookieKey");p(this,"cookiesStorage");this.cookieKey=`${ct}.${t.clientId}`,this.cookiesStorage=new lt}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 ft extends Error{}class dt extends Error{}class ht extends Error{}const M="@trimble-oss/trimble-id-react",F="0.0.4-rc.
|
|
1
|
+
(function(m,S){typeof exports=="object"&&typeof module<"u"?S(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"],S):(m=typeof globalThis<"u"?globalThis:m||self,S(m.ReactTID={},m.trimbleId,m.esCookie,m.jwt_decode,m.require$$0))})(this,function(m,S,j,He,T){"use strict";var Zt=Object.defineProperty;var qt=(m,S,j)=>S in m?Zt(m,S,{enumerable:!0,configurable:!0,writable:!0,value:j}):m[S]=j;var p=(m,S,j)=>(qt(m,typeof S!="symbol"?S+"":S,j),j);function $e(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 re=$e(j);class Xe{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 Qe{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 ne="@TID",Ze=`${ne}_AUTH_KEY`,qe=`${ne}_USER_KEY`;class et{constructor(t){p(this,"clientId");p(this,"prefix",ne);p(this,"authSuffix",Ze);p(this,"userSuffix",qe);this.clientId=t.client_id}getUserKey(){return`${this.prefix}_${this.userSuffix}_${this.clientId}`}getAuthKey(){return`${this.prefix}_${this.authSuffix}_${this.clientId}`}}class tt{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 rt{constructor(t){p(this,"persistentStore");p(this,"cacheStorage");p(this,"cacheKey");this.persistentStore=t.persistentStore,this.cacheKey=new et({client_id:t.clientId}),this.persistentStore==="localStorage"?this.cacheStorage=new Qe({cacheKey:this.cacheKey}):this.persistentStore==="sessionStorage"?this.cacheStorage=new tt({cacheKey:this.cacheKey}):this.cacheStorage=new Xe().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 nt=5*6e4,it=["code","state"],pe=a=>a.split("?")[0],at=a=>a.split("?")[1],me=a=>{let t=a;if(!a.startsWith("?"))try{t=new URL(a).search}catch{}return new URLSearchParams(t)},ot=(a=window.location.href,t)=>{if(t!=null){const o=pe(t),c=pe(a??"");if(o!==c)return!1}const n=me(a);for(const o of it)if(!n.has(o))return!1;return!0},st=a=>({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}),ct="@TID_COOKIE";class lt{get(t){const n=re.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),re.set(t,JSON.stringify(n),c)}remove(t,n){const o={};n!=null&&n.domain&&(o.domain=n.domain),re.remove(t,o)}}class ut{constructor(t){p(this,"cookieKey");p(this,"cookiesStorage");this.cookieKey=`${ct}.${t.clientId}`,this.cookiesStorage=new lt}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 ft extends Error{}class dt extends Error{}class ht extends Error{}const M="@trimble-oss/trimble-id-react",F="0.0.4-rc.2",gt={configurationEndpoint:"",clientId:"",redirectUrl:"",logoutRedirectUrl:"",scopes:[]},vt={persistentStore:"in-memory"};class Ee{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 ut({clientId:n.clientId});const c=this.cookiesManager.get(),w=new S.OpenIdEndpointProvider(n.configurationEndpoint);let k=new S.AuthorizationCodeGrantTokenProvider(w,n.clientId,n.redirectUrl).WithScopes(n.scopes);n.logoutRedirectUrl&&(k=k.WithLogoutRedirect(n.logoutRedirectUrl)),(c==null?void 0:c.code_verifier)!=null&&(k=k.WithProofKeyForCodeExchange(c.code_verifier)),this.tokenProvider=k,this.cacheManager=new rt({clientId:n.clientId,persistentStore:o.persistentStore}),this.clientId=n.clientId,this.analyticshttpclient=new S.AnalyticsHttpClient,this.analyticshttpclient.sendInitEvent("TIDClient",this.clientId,M,F)}async loginWithRedirect(t){this.analyticshttpclient.sendMethodEvent(this.loginWithRedirect.name,this.clientId,M,F);const{onRedirect:n}=t||{},o=S.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=at(t),c=me(t),w=c.get("identity_provider")??"",k=c.get("state")??"";return await this.tokenProvider.ValidateQuery(o),await this.generateToken(w),{authState:k}}async generateToken(t){var C,d;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(),g=(d=(C=this.tokenProvider)==null?void 0:C._scopes)==null?void 0:d.join(" ");await this.cacheManager.setToken({scope:g,state:"",session_state:"",identity_provider:t,token_type:"bearer",access_token:n,refresh_token:o,id_token:c,expires_at:P});const I=He(c),R=st(I);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,M,F),await this.cacheManager.getUser()}async getAccessTokenSilently(){this.analyticshttpclient.sendMethodEvent(this.getAccessTokenSilently.name,this.clientId,M,F);let t=await this.cacheManager.getToken();if(t==null)throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name,"No token available",this.clientId,M,F),new dt("No token available");const n=new Date(new Date().getTime()+nt);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,M,F),new ft(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 logout(t){this.analyticshttpclient.sendMethodEvent(this.logout.name,this.clientId,M,F);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 S.BearerTokenHttpClientProvider(this.tokenProvider,t)}getRedirectUrl(){return this.redirectUrl}}const z=T.createContext(null),_e=()=>T.useContext(z)??{};var ie={exports:{}},Y={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
{
|
|
3
3
|
"name": "@trimble-oss/trimble-id-react",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "0.0.4-rc.
|
|
5
|
+
"version": "0.0.4-rc.2",
|
|
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.2",
|
|
35
|
+
"@trimble-oss/trimble-id": "^0.0.3-rc.2",
|
|
36
36
|
"es-cookie": "^1.4.0",
|
|
37
37
|
"husky": "^8.0.3",
|
|
38
38
|
"jwt-decode": "^3.1.2"
|