@descope/web-js-sdk 1.54.7 → 1.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.d.ts +13 -13
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as oidc_client_ts from 'oidc-client-ts';
|
|
2
2
|
import * as _descope_core_js_sdk from '@descope/core-js-sdk';
|
|
3
|
-
export { FlowNextOptions, FlowStartOptions, JWTResponse, UserFamily, UserResponse } from '@descope/core-js-sdk';
|
|
3
|
+
export { FlowNextOptions, FlowStartOptions, JWTResponse, LogoutOptions, LogoutResponse, UserFamily, UserResponse } from '@descope/core-js-sdk';
|
|
4
4
|
|
|
5
5
|
type OidcConfigOptions = {
|
|
6
6
|
applicationId?: string;
|
|
@@ -158,7 +158,7 @@ declare const decoratedCreateSdk: <A extends CookieConfig>({ persistTokens: isPe
|
|
|
158
158
|
customStorage?: CustomStorage;
|
|
159
159
|
} & FingerprintOptions & FlowNonceOptions & AutoRefreshOptions & LastLoggedInUserOptions & PersistTokensOptions<A>) => A extends false ? ((({
|
|
160
160
|
refresh: (token?: string, tryRefresh?: boolean) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
161
|
-
logout: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<
|
|
161
|
+
logout: (token?: string, options?: _descope_core_js_sdk.LogoutOptions) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.LogoutResponse>>;
|
|
162
162
|
flow: {
|
|
163
163
|
start: (flowId: string, options?: Pick<_descope_core_js_sdk.FlowStartOptions, "tenant" | "redirectUrl" | "redirectAuth" | "oidcIdpStateId" | "samlIdpStateId" | "wsfedIdpStateId" | "samlIdpUsername" | "ssoAppId" | "thirdPartyAppId" | "oidcLoginHint" | "preview" | "abTestingKey" | "client" | "locale" | "oidcPrompt" | "oidcErrorRedirectUri" | "oidcResource" | "nativeOptions" | "thirdPartyAppStateId" | "applicationScopes" | "outboundAppId" | "outboundAppScopes"> & {
|
|
164
164
|
lastAuth?: Omit<{
|
|
@@ -915,7 +915,7 @@ declare const decoratedCreateSdk: <A extends CookieConfig>({ persistTokens: isPe
|
|
|
915
915
|
}>>;
|
|
916
916
|
};
|
|
917
917
|
selectTenant: (tenantId: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
918
|
-
logoutAll: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<
|
|
918
|
+
logoutAll: (token?: string, options?: _descope_core_js_sdk.LogoutOptions) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.LogoutResponse>>;
|
|
919
919
|
me: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.UserResponse>>;
|
|
920
920
|
myTenants: (tenants: true | string[], token?: string) => Promise<_descope_core_js_sdk.SdkResponse<{
|
|
921
921
|
tenants: {
|
|
@@ -933,7 +933,7 @@ declare const decoratedCreateSdk: <A extends CookieConfig>({ persistTokens: isPe
|
|
|
933
933
|
httpClient: _descope_core_js_sdk.HttpClient;
|
|
934
934
|
} | {
|
|
935
935
|
refresh: (token?: string, tryRefresh?: boolean) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
936
|
-
logout: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<
|
|
936
|
+
logout: (token?: string, options?: _descope_core_js_sdk.LogoutOptions) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.LogoutResponse>>;
|
|
937
937
|
flow: {
|
|
938
938
|
start: (flowId: string, options?: Pick<_descope_core_js_sdk.FlowStartOptions, "tenant" | "redirectUrl" | "redirectAuth" | "oidcIdpStateId" | "samlIdpStateId" | "wsfedIdpStateId" | "samlIdpUsername" | "ssoAppId" | "thirdPartyAppId" | "oidcLoginHint" | "preview" | "abTestingKey" | "client" | "locale" | "oidcPrompt" | "oidcErrorRedirectUri" | "oidcResource" | "nativeOptions" | "thirdPartyAppStateId" | "applicationScopes" | "outboundAppId" | "outboundAppScopes"> & {
|
|
939
939
|
lastAuth?: Omit<{
|
|
@@ -1690,7 +1690,7 @@ declare const decoratedCreateSdk: <A extends CookieConfig>({ persistTokens: isPe
|
|
|
1690
1690
|
}>>;
|
|
1691
1691
|
};
|
|
1692
1692
|
selectTenant: (tenantId: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
1693
|
-
logoutAll: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<
|
|
1693
|
+
logoutAll: (token?: string, options?: _descope_core_js_sdk.LogoutOptions) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.LogoutResponse>>;
|
|
1694
1694
|
me: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.UserResponse>>;
|
|
1695
1695
|
myTenants: (tenants: true | string[], token?: string) => Promise<_descope_core_js_sdk.SdkResponse<{
|
|
1696
1696
|
tenants: {
|
|
@@ -1708,7 +1708,7 @@ declare const decoratedCreateSdk: <A extends CookieConfig>({ persistTokens: isPe
|
|
|
1708
1708
|
httpClient: _descope_core_js_sdk.HttpClient;
|
|
1709
1709
|
} | {
|
|
1710
1710
|
refresh: (token?: string, tryRefresh?: boolean) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
1711
|
-
logout: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<
|
|
1711
|
+
logout: (token?: string, options?: _descope_core_js_sdk.LogoutOptions) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.LogoutResponse>>;
|
|
1712
1712
|
flow: {
|
|
1713
1713
|
start: (flowId: string, options?: Pick<_descope_core_js_sdk.FlowStartOptions, "tenant" | "redirectUrl" | "redirectAuth" | "oidcIdpStateId" | "samlIdpStateId" | "wsfedIdpStateId" | "samlIdpUsername" | "ssoAppId" | "thirdPartyAppId" | "oidcLoginHint" | "preview" | "abTestingKey" | "client" | "locale" | "oidcPrompt" | "oidcErrorRedirectUri" | "oidcResource" | "nativeOptions" | "thirdPartyAppStateId" | "applicationScopes" | "outboundAppId" | "outboundAppScopes"> & {
|
|
1714
1714
|
lastAuth?: Omit<{
|
|
@@ -2465,7 +2465,7 @@ declare const decoratedCreateSdk: <A extends CookieConfig>({ persistTokens: isPe
|
|
|
2465
2465
|
}>>;
|
|
2466
2466
|
};
|
|
2467
2467
|
selectTenant: (tenantId: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
2468
|
-
logoutAll: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<
|
|
2468
|
+
logoutAll: (token?: string, options?: _descope_core_js_sdk.LogoutOptions) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.LogoutResponse>>;
|
|
2469
2469
|
me: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.UserResponse>>;
|
|
2470
2470
|
myTenants: (tenants: true | string[], token?: string) => Promise<_descope_core_js_sdk.SdkResponse<{
|
|
2471
2471
|
tenants: {
|
|
@@ -2493,7 +2493,7 @@ declare const decoratedCreateSdk: <A extends CookieConfig>({ persistTokens: isPe
|
|
|
2493
2493
|
getLastUserDisplayName: () => string;
|
|
2494
2494
|
} : (((({
|
|
2495
2495
|
refresh: (token?: string, tryRefresh?: boolean) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
2496
|
-
logout: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<
|
|
2496
|
+
logout: (token?: string, options?: _descope_core_js_sdk.LogoutOptions) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.LogoutResponse>>;
|
|
2497
2497
|
flow: {
|
|
2498
2498
|
start: (flowId: string, options?: Pick<_descope_core_js_sdk.FlowStartOptions, "tenant" | "redirectUrl" | "redirectAuth" | "oidcIdpStateId" | "samlIdpStateId" | "wsfedIdpStateId" | "samlIdpUsername" | "ssoAppId" | "thirdPartyAppId" | "oidcLoginHint" | "preview" | "abTestingKey" | "client" | "locale" | "oidcPrompt" | "oidcErrorRedirectUri" | "oidcResource" | "nativeOptions" | "thirdPartyAppStateId" | "applicationScopes" | "outboundAppId" | "outboundAppScopes"> & {
|
|
2499
2499
|
lastAuth?: Omit<{
|
|
@@ -3250,7 +3250,7 @@ declare const decoratedCreateSdk: <A extends CookieConfig>({ persistTokens: isPe
|
|
|
3250
3250
|
}>>;
|
|
3251
3251
|
};
|
|
3252
3252
|
selectTenant: (tenantId: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
3253
|
-
logoutAll: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<
|
|
3253
|
+
logoutAll: (token?: string, options?: _descope_core_js_sdk.LogoutOptions) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.LogoutResponse>>;
|
|
3254
3254
|
me: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.UserResponse>>;
|
|
3255
3255
|
myTenants: (tenants: true | string[], token?: string) => Promise<_descope_core_js_sdk.SdkResponse<{
|
|
3256
3256
|
tenants: {
|
|
@@ -3268,7 +3268,7 @@ declare const decoratedCreateSdk: <A extends CookieConfig>({ persistTokens: isPe
|
|
|
3268
3268
|
httpClient: _descope_core_js_sdk.HttpClient;
|
|
3269
3269
|
} | {
|
|
3270
3270
|
refresh: (token?: string, tryRefresh?: boolean) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
3271
|
-
logout: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<
|
|
3271
|
+
logout: (token?: string, options?: _descope_core_js_sdk.LogoutOptions) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.LogoutResponse>>;
|
|
3272
3272
|
flow: {
|
|
3273
3273
|
start: (flowId: string, options?: Pick<_descope_core_js_sdk.FlowStartOptions, "tenant" | "redirectUrl" | "redirectAuth" | "oidcIdpStateId" | "samlIdpStateId" | "wsfedIdpStateId" | "samlIdpUsername" | "ssoAppId" | "thirdPartyAppId" | "oidcLoginHint" | "preview" | "abTestingKey" | "client" | "locale" | "oidcPrompt" | "oidcErrorRedirectUri" | "oidcResource" | "nativeOptions" | "thirdPartyAppStateId" | "applicationScopes" | "outboundAppId" | "outboundAppScopes"> & {
|
|
3274
3274
|
lastAuth?: Omit<{
|
|
@@ -4025,7 +4025,7 @@ declare const decoratedCreateSdk: <A extends CookieConfig>({ persistTokens: isPe
|
|
|
4025
4025
|
}>>;
|
|
4026
4026
|
};
|
|
4027
4027
|
selectTenant: (tenantId: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
4028
|
-
logoutAll: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<
|
|
4028
|
+
logoutAll: (token?: string, options?: _descope_core_js_sdk.LogoutOptions) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.LogoutResponse>>;
|
|
4029
4029
|
me: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.UserResponse>>;
|
|
4030
4030
|
myTenants: (tenants: true | string[], token?: string) => Promise<_descope_core_js_sdk.SdkResponse<{
|
|
4031
4031
|
tenants: {
|
|
@@ -4043,7 +4043,7 @@ declare const decoratedCreateSdk: <A extends CookieConfig>({ persistTokens: isPe
|
|
|
4043
4043
|
httpClient: _descope_core_js_sdk.HttpClient;
|
|
4044
4044
|
} | {
|
|
4045
4045
|
refresh: (token?: string, tryRefresh?: boolean) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
4046
|
-
logout: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<
|
|
4046
|
+
logout: (token?: string, options?: _descope_core_js_sdk.LogoutOptions) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.LogoutResponse>>;
|
|
4047
4047
|
flow: {
|
|
4048
4048
|
start: (flowId: string, options?: Pick<_descope_core_js_sdk.FlowStartOptions, "tenant" | "redirectUrl" | "redirectAuth" | "oidcIdpStateId" | "samlIdpStateId" | "wsfedIdpStateId" | "samlIdpUsername" | "ssoAppId" | "thirdPartyAppId" | "oidcLoginHint" | "preview" | "abTestingKey" | "client" | "locale" | "oidcPrompt" | "oidcErrorRedirectUri" | "oidcResource" | "nativeOptions" | "thirdPartyAppStateId" | "applicationScopes" | "outboundAppId" | "outboundAppScopes"> & {
|
|
4049
4049
|
lastAuth?: Omit<{
|
|
@@ -4800,7 +4800,7 @@ declare const decoratedCreateSdk: <A extends CookieConfig>({ persistTokens: isPe
|
|
|
4800
4800
|
}>>;
|
|
4801
4801
|
};
|
|
4802
4802
|
selectTenant: (tenantId: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
4803
|
-
logoutAll: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<
|
|
4803
|
+
logoutAll: (token?: string, options?: _descope_core_js_sdk.LogoutOptions) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.LogoutResponse>>;
|
|
4804
4804
|
me: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.UserResponse>>;
|
|
4805
4805
|
myTenants: (tenants: true | string[], token?: string) => Promise<_descope_core_js_sdk.SdkResponse<{
|
|
4806
4806
|
tenants: {
|
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__rest as e}from"tslib";import{jwtDecode as t}from"jwt-decode";import n,{wrapWith as o}from"@descope/core-js-sdk";import i from"js-cookie";import{load as r,defaultScriptUrlPattern as s,defaultEndpoint as a}from"@fingerprintjs/fingerprintjs-pro";const l="3.2.0",c="undefined"!=typeof window,d=Math.pow(2,31)-1,u=2e4,f=`https://descopecdn.com/npm/oidc-client-ts@${l}/dist/browser/oidc-client-ts.min.js`,p=`https://cdn.jsdelivr.net/npm/oidc-client-ts@${l}/dist/browser/oidc-client-ts.min.js`;const v=["/v1/auth/refresh","/v1/auth/try-refresh","/v1/auth/me","/v1/auth/me/tenants","/v1/auth/me/history"];let g;const w=e=>{try{return t(e).exp}catch(e){return null}},h=e=>{const{refresh_expire_in:t,refresh_token:n}=e;return t?Math.floor(Date.now()/1e3)+t:w(n)},m=e=>{const{expires_in:t,expires_at:n,access_token:o}=e;return n||(t?Math.floor(Date.now()/1e3)+t:o?w(o):void 0)},y=t=>{const{access_token:n,id_token:o,refresh_token:i,refresh_expire_in:r}=t,s=e(t,["access_token","id_token","refresh_token","refresh_expire_in"]);return Object.assign({sessionJwt:t.sessionJwt||n,idToken:o,refreshJwt:t.refreshJwt||i,sessionExpiration:t.sessionExpiration||m(t),cookieExpiration:t.cookieExpiration||h(t)},s)},b=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var i;return n[o]=[].concat((null===(i=e.hooks)||void 0===i?void 0:i[o])||[]).concat((null==t?void 0:t[o])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},k=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json()),n=(null==t?void 0:t.authInfo)||t||{};return y(n)},S=()=>c&&!!window.descopeBridge,I=(e,t)=>{if(!((null==t?void 0:t.status)>=400&&(null==t?void 0:t.status)<500))return!1;const n=(null==e?void 0:e.path)||"";return v.includes(n)},_=void 0!==g||c&&void 0!==window.localStorage,O=(e,t)=>{var n,o;return null===(o=null===(n=g||c&&window.localStorage)||void 0===n?void 0:n.setItem)||void 0===o?void 0:o.call(n,e,t)},x=e=>{var t,n;return null===(n=null===(t=g||c&&window.localStorage)||void 0===t?void 0:t.getItem)||void 0===n?void 0:n.call(t,e)},D=e=>{var t,n;return null===(n=null===(t=g||c&&window.localStorage)||void 0===t?void 0:t.removeItem)||void 0===n?void 0:n.call(t,e)},j=e=>{var t,n,o,i,r;return null!==(r=null!==(n=null===(t=null==g?void 0:g.key)||void 0===t?void 0:t.call(g,e))&&void 0!==n?n:c&&(null===(i=null===(o=window.localStorage)||void 0===o?void 0:o.key)||void 0===i?void 0:i.call(o,e)))&&void 0!==r?r:null},A=e=>{var t,n;return c&&(null===(n=null===(t=window.localStorage)||void 0===t?void 0:t.getItem)||void 0===n?void 0:n.call(t,e))||null},C=e=>{var t,n;try{c&&(null===(n=null===(t=window.localStorage)||void 0===t?void 0:t.removeItem)||void 0===n||n.call(t,e))}catch(e){}},U=(...e)=>{console.debug(...e)},T=(...e)=>{console.warn(...e)},R=e=>e?e.getTime()-(new Date).getTime():0,$="DS",E="DSR",N="DSI",J="DSRCN";function P(e,t,n){if(t){const{cookieDomain:o,cookiePath:r,cookieSameSite:s,cookieExpiration:a,cookieSecure:l}=n,c=new Date(1e3*a),d=q(o);i.set(e,t,{path:r,domain:d?o:void 0,expires:c,sameSite:s,secure:l})}}function q(e){const t=window.location.hostname.split("."),n=null==e?void 0:e.split(".");return t.slice(-(null==n?void 0:n.length)).join(".")===e}const L=e=>(null==e?void 0:e.cookieName)||$,K=e=>(null==e?void 0:e.cookieName)||E;function V(e="",t){return i.get(K(t))||x(`${e}${E}`)||""}function F(e="",t){return i.get(L(t))||x(`${e}${$}`)||""}function M(e=""){return x(`${e}${N}`)||""}function H(e="",t,n,o){D(`${e}${E}`),D(`${e}${$}`),D(`${e}${N}`),D(`${e}${J}`);const r=L(t);i.remove(r,null==o?void 0:o.session);const s=K(n);i.remove(s,null==o?void 0:o.refresh)}const B=(e,t,n)=>o=>{const i=Object.assign(o,{token:o.token||V(e,t)});if(!n){const t=function(e=""){return x(`${e}${J}`)}(e);t&&(i.headers=Object.assign(Object.assign({},i.headers||{}),{"x-descope-refresh-cookie-name":t}))}const r=function(e=""){return x(`${e}DTD`)||""}(e);r&&(i.headers=Object.assign(Object.assign({},i.headers||{}),{"x-descope-trusted-device-token":r}));const s=function(e=""){return x(`${e}DKD`)||""}(e);return s&&(i.headers=Object.assign(Object.assign({},i.headers||{}),{"x-descope-known-device-token":s})),i},z=c&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",G="vsid",W="vrid",X="fp",Z=(e=!1)=>{const t=x(X);if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},Q=async(e,t=z)=>{try{if(Z())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),o=new URL(t);o.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const i=new URL(t);i.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const l=i.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",c=r({apiKey:e,endpoint:[o.toString(),a],scriptUrlPattern:[l,s]}),d=await c,{requestId:u}=await d.get({linkedId:n}),f=((e,t)=>({[G]:e,[W]:t}))(n,u);(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};O(X,JSON.stringify(t))})(f)}catch(e){console.warn("Could not load fingerprint",e)}},Y=()=>{D(X)},ee=e=>{const t=Z(!0);return t&&e.body&&(e.body.fpData=t),e},te="descopeFlowNonce",ne="X-Descope-Flow-Nonce",oe="/v1/flow/start",ie="/v1/flow/next",re=(e,t=te)=>`${t}${e}`,se=(e,t=te)=>{try{const n=re(e,t),o=x(n);if(!o)return null;const i=JSON.parse(o);return i.expiry<Date.now()?(ae(e,t),null):{value:i.value,seq:i.seq}}catch(e){return console.error("Error getting flow nonce:",e),null}},ae=(e,t=te)=>{try{const n=re(e,t);D(n)}catch(e){console.error("Error removing flow nonce:",e)}},le=e=>{var t;return(null===(t=/.*\|#\|(.*)/.exec(e))||void 0===t?void 0:t[1])||null},ce=async(e,t)=>{try{const n=t.headers.get(ne),o=null===n?void 0:(e=>{const t=e.indexOf(".");if(t<=0)return;const n=e.slice(0,t);if(!/^\d+$/.test(n))return;const o=Number(n);return Number.isSafeInteger(o)?o:void 0})(n);let i=await t.clone().json().then((e=>(null==e?void 0:e.executionId)||null)).catch((()=>null));return i||(i=de(e)),{nonce:n,seq:o,executionId:le(i)}}catch(e){return{nonce:null,seq:void 0,executionId:null}}},de=e=>{var t;return e.path===ie&&(null===(t=e.body)||void 0===t?void 0:t.executionId)?le(e.body.executionId):null},ue="dls_last_user_login_id",fe="dls_last_user_display_name",pe=e=>O(ue,e),ve=()=>x(ue),ge=()=>x(fe),we=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,i=ve(),r=ge();i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r);return await e(...t)},he=e=>t=>async(...n)=>{const o=await t(...n);return e||(D(ue),D(fe)),o},me="DSLI",ye=e=>async(...t)=>{const n=await e(...t);return C(me),n};function be(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const ke=(e,t,n,o)=>i=>async(...r)=>{const s=await i(...r);return H(e,t,n,null==o?void 0:o()),s};async function Se(e,t){const n=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Ae(n.publicKey.challenge),n.publicKey.user.id=Ae(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Ae(e.id)})),n}(e);t&&(n.signal=t.signal);try{const e=await navigator.credentials.create(n);return o=e,JSON.stringify({id:o.id,rawId:Ce(o.rawId),type:o.type,response:{attestationObject:Ce(o.response.attestationObject),clientDataJSON:Ce(o.response.clientDataJSON)}})}catch(e){throw await Oe(e,n,!0)}var o}async function Ie(e,t){const n=De(e);t&&(n.signal=t.signal);try{return je(await navigator.credentials.get(n))}catch(e){throw await Oe(e,n,!1)}}async function _e(e,t){const n=De(e);n.signal=t.signal,n.mediation="conditional";try{return je(await navigator.credentials.get(n))}catch(e){throw await Oe(e,n,!1)}}async function Oe(e,t,n){if(e&&"object"==typeof e)try{e.reason=await async function(e,t,n){var o,i;const r=null==e?void 0:e.name;if("AbortError"===r&&(null==t?void 0:t.signal)instanceof AbortSignal)return"aborted";if("InvalidStateError"===r&&n)return"authenticator_already_registered";if("NotSupportedError"===r)return"no_supported_algorithm";if("ConstraintError"===r)return"authenticator_constraints_unsupported";if("SecurityError"===r){const e=window.location.hostname;return"localhost"===e||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e)?"invalid_rpid":"invalid_domain"}if(!await xe())return"webauthn_unsupported";const s="platform"===(null===(i=null===(o=null==t?void 0:t.publicKey)||void 0===o?void 0:o.authenticatorSelection)||void 0===i?void 0:i.authenticatorAttachment);return n&&s&&!await xe(!0)?"platform_authenticator_unsupported":"NotAllowedError"===r?"not_allowed":"unknown"}(e,t,n)}catch(e){}return e}async function xe(e=!1){var t,n;if(!c)return Promise.resolve(!1);if(S()){const e=null===(n=null===(t=window.descopeBridge)||void 0===t?void 0:t.hostInfo)||void 0===n?void 0:n.webauthn;if("boolean"==typeof e)return e}const o=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return o&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():o}function De(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Ae(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Ae(e.id)})),n}function je(e){return JSON.stringify({id:e.id,rawId:Ce(e.rawId),type:e.type,response:{authenticatorData:Ce(e.response.authenticatorData),clientDataJSON:Ce(e.response.clientDataJSON),signature:Ce(e.response.signature),userHandle:e.response.userHandle?Ce(e.response.userHandle):void 0}})}function Ae(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Ce(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Ue,Te=(Ue=e=>({async signUp(t,n,o){const i=await e.webauthn.signUp.start(t,window.location.origin,n,o);if(!i.ok)return i;const r=await Se(i.data.options);return await e.webauthn.signUp.finish(i.data.transactionId,r)},async signIn(t,n){const o=await e.webauthn.signIn.start(t,window.location.origin,void 0,void 0,n);if(!o.ok)return o;const i=await Ie(o.data.options);return await e.webauthn.signIn.finish(o.data.transactionId,i)},async signUpOrIn(t,n){var o;const i=await e.webauthn.signUpOrIn.start(t,window.location.origin,n);if(!i.ok)return i;if(null===(o=i.data)||void 0===o?void 0:o.create){const t=await Se(i.data.options);return await e.webauthn.signUp.finish(i.data.transactionId,t)}{const t=await Ie(i.data.options);return await e.webauthn.signIn.finish(i.data.transactionId,t)}},async update(t,n,o){const i=await e.webauthn.update.start(t,window.location.origin,n,o);if(!i.ok)return i;const r=await Se(i.data.options);return await e.webauthn.update.finish(i.data.transactionId,r)},helpers:{create:Se,get:Ie,isSupported:xe,conditional:_e}}),(...e)=>{const t=Ue(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t});const Re={config:"/fedcm/config"};async function $e(e,t){var n;try{await Ee(e,t)}catch(e){null===(n=null==t?void 0:t.onFailed)||void 0===n||n.call(t,e)}}async function Ee(e,t){var n,o;const i=await async function(e,t="google",n,o,i){const r=(()=>{if(window.crypto&&window.crypto.getRandomValues){const e=new Uint8Array(16);return window.crypto.getRandomValues(e),Array.from(e,(e=>e.toString(16).padStart(2,"0"))).join("")}return Math.random().toString(36).substring(2)})(),s=await async function(){return new Promise(((e,t)=>{if(window.google)return void e(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?e(window.google.accounts.id):t("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){t("Failed to load Google GSI client script - failed to load")}}))}(),a=await e.oauth.getOneTapClientId(t);if(!a.ok)throw new Error("Failed to get OneTap client ID for provider "+t);const l=a.data.clientId;return new Promise((e=>{var a,c;const d=n=>{e({provider:t,nonce:r,credential:null==n?void 0:n.credential})};s.initialize(Object.assign(Object.assign({},n),{itp_support:null===(a=null==n?void 0:n.itp_support)||void 0===a||a,use_fedcm_for_prompt:null===(c=null==n?void 0:n.use_fedcm_for_prompt)||void 0===c||c,client_id:l,callback:d,nonce:r})),s.prompt((e=>{var t,n;if(i&&(null==e?void 0:e.isDismissedMoment())){const n=null===(t=e.getDismissedReason)||void 0===t?void 0:t.call(e);return null==i||i(n),void d()}if(o&&(null==e?void 0:e.isSkippedMoment())){const t=null===(n=e.getSkippedReason)||void 0===n?void 0:n.call(e);return null==o||o(t),void d()}}))}))}(e,t.provider,t.oneTapConfig,t.onSkipped,t.onDismissed);if(!i.credential)return null;if(null==t?void 0:t.onCodeReceived){const o=await e.oauth.verifyOneTapIDToken(i.provider,i.credential,i.nonce,null==t?void 0:t.loginOptions);if(!o.ok||!o.data)throw new Error("Failed to verify OneTap client ID for provider "+i.provider);null===(n=null==t?void 0:t.onCodeReceived)||void 0===n||n.call(t,o.data.code)}else{const n=await e.oauth.exchangeOneTapIDToken(i.provider,i.credential,i.nonce,null==t?void 0:t.loginOptions);if(!n.ok||!n.data)throw new Error("Failed to exchange OneTap client ID for provider "+i.provider);null===(o=null==t?void 0:t.onAuthenticated)||void 0===o||o.call(t,n.data)}}var Ne=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await xe(),o=Object.assign(Object.assign({location:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return t[1]=o,e.flow.start(...t)}});const Je=()=>window.location.search.includes("code")&&window.location.search.includes("state");let Pe;const qe=(e,t)=>new Promise(((n,o)=>{if(!e.length)return o(new Error("No URLs provided to loadScriptWithFallback"));const i=t();if(i)return n(i);const r=e.shift(),s=document.createElement("script");s.src=r,s.id=(e=>{let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return Math.abs(t).toString(16)})(r),s.onload=()=>{const e=t();if(e)return n(e);throw new Error("Could not get entry after loading script from URL")},s.addEventListener("error",(()=>{qe(e,t),s.setAttribute("data-error","true")})),document.body.appendChild(s)}));const Le=async(e,t,n)=>{Pe||(Pe=(async()=>{try{return require("oidc-client-ts")}catch(e){return qe([f,p],(()=>window.oidc))}})());const{OidcClient:o,WebStorageStateStore:i}=await Pe;if(!o)throw new Error("oidc-client-ts is not installed. Please install it by running `npm install oidc-client-ts`");const r=(null==n?void 0:n.redirectUri)||window.location.href;let s,a,l,c;if(null==n?void 0:n.issuer){if(!n.clientId)throw new Error("clientId is required when providing a custom issuer/authority");s=n.issuer,a=n.clientId,l=`${a}_user`,c="openid"}else(null==n?void 0:n.applicationId)?(s=e.httpClient.buildUrl(t),s=`${s}/${n.applicationId}`,a=t,l=`${a}_user`,c="openid email roles descope.custom_claims offline_access"):(s=e.httpClient.buildUrl(t),a=t,l=`${a}_user`,c="openid email roles descope.custom_claims offline_access");const d={authority:s,client_id:a,redirect_uri:r,response_type:"code",scope:(null==n?void 0:n.scope)||c,stateStore:new i({store:window.localStorage,prefix:a}),loadUserInfo:!0,fetchRequestCredentials:"same-origin"};return(null==n?void 0:n.redirectUri)&&(d.redirect_uri=n.redirectUri),{client:new o(d),stateUserKey:l}},Ke=(e,t,n)=>{const o=async()=>{let o,i;return o&&i||({client:o,stateUserKey:i}=await Le(e,t,n)),{client:o,stateUserKey:i}},i=async(t="")=>{var n;const{client:i,stateUserKey:r}=await o(),s=await i.processSigninResponse(t||window.location.href);var a;return await(null===(n=e.httpClient.hooks)||void 0===n?void 0:n.afterRequest({},new Response(JSON.stringify(s)))),O(r,JSON.stringify({id_token:(a=s).id_token,session_state:a.session_state,profile:a.profile})),(()=>{const e=new URL(window.location.href);e.searchParams.delete("code"),e.searchParams.delete("state"),window.history.replaceState({},document.title,e.toString())})(),s};return{loginWithRedirect:async(t={},n=!1)=>{var i;const{client:r}=await o(),s=await r.createSigninRequest(t),{url:a}=s;return n||(await(null===(i=e.httpClient.hooks)||void 0===i?void 0:i.afterRequest({},new Response(JSON.stringify(s)))),window.location.href=a),{ok:!0,data:s}},finishLogin:i,finishLoginIfNeed:async(e="")=>{if(Je())return await i(e)},refreshToken:async t=>{var n;const{client:i,stateUserKey:r}=await o(),s=(e=>{const t=x(e);return t?JSON.parse(t):null})(r);if(!s)throw new Error("User not found in storage to refresh token");let a=t;if(!a){const t={};e.httpClient.hooks.beforeRequest(t),a=t.token}const l=await i.useRefreshToken({state:{refresh_token:a,session_state:s.session_state,profile:s.profile}});return await(null===(n=e.httpClient.hooks)||void 0===n?void 0:n.afterRequest({},new Response(JSON.stringify(l)))),l},logout:async(e,t=!1)=>{const{client:n,stateUserKey:i}=await o();e||(e={}),e.id_token_hint=e.id_token_hint||M(),e.post_logout_redirect_uri=e.post_logout_redirect_uri||window.location.href;const r=await n.createSignoutRequest(e),{url:s}=r;return D(i),t||window.location.replace(s),r}}},Ve=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>t=>{var n;return n=t.customStorage,g=n,e(t)}),(t=>n=>{var{fpKey:o,fpLoad:i}=n,r=e(n,["fpKey","fpLoad"]);return c?(o&&i&&Q(o).catch((()=>null)),t(b(r,{beforeRequest:ee}))):t(r)}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.54.7"},t.baseHeaders)}))),(e=>t=>{const n=be(),i=be(),r=be(),s=be(),a=e(b(t,{afterRequest:async(e,t)=>{if(I(e,t))U("Session invalidated, notifying subscribers with empty values"),i.pub(null),r.pub(null),n.pub(null),s.pub(null);else{const e=await(async e=>{const t=await k(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)})(t);e&&r.pub(e);const{sessionJwt:o,sessionExpiration:a,claims:l}=await k(t);o&&i.pub(o),l&&s.pub(l),(a||o)&&n.pub(a||42)}}})),l=o(a,["logout","logoutAll","oidc.logout"],(e=>async(...t)=>{const o=await e(...t);return i.pub(null),r.pub(null),n.pub(null),s.pub(null),o}));return Object.assign(l,{onSessionTokenChange:i.sub,onUserChange:r.sub,onClaimsChange:s.sub,onIsAuthenticatedChange:e=>n.sub((t=>{e(!!t)}))})}),(t=>n=>{var o;const{enableFlowNonce:i=!0,nonceStoragePrefix:r=te}=n,s=e(n,["enableFlowNonce","nonceStoragePrefix"]);if(!i)return t(s);((e=te)=>{try{if(!_)return;for(let i=0;i<(t=void 0,n=void 0,o=void 0,null!==(o=null!==(t=null==g?void 0:g.length)&&void 0!==t?t:c&&(null===(n=window.localStorage)||void 0===n?void 0:n.length))&&void 0!==o?o:0);i++){const t=j(i);if(t&&t.startsWith(e)){const e=x(t);if(e)try{JSON.parse(e).expiry<Date.now()&&D(t)}catch(e){D(t)}}}}catch(e){console.error("Error cleaning up expired nonces:",e)}var t,n,o})(r);const a=t(b(s,{afterRequest:async(e,t)=>{var n;if(e.path!==oe&&e.path!==ie)return;const{nonce:o,seq:i,executionId:s}=await ce(e,t);if(!o||!s)return;const a=e.path===oe,l=null===(n=se(s,r))||void 0===n?void 0:n.seq;if(!a&&void 0!==i&&void 0!==l&&i<=l)return;((e,t,n,o=te,i)=>{try{const r=re(e,o),s=n?172800:10800,a={value:t,expiry:Date.now()+1e3*s,isStart:n,seq:i};O(r,JSON.stringify(a))}catch(e){console.error("Error setting flow nonce:",e)}})(s,o,a,r,null!=i?i:a?void 0:l)},beforeRequest:e=>{if(e.path===ie){const t=de(e);if(t){const n=((e,t=te)=>{var n,o;return null!==(o=null===(n=se(e,t))||void 0===n?void 0:n.value)&&void 0!==o?o:null})(t,r);n&&(e.headers=e.headers||{},e.headers[ne]=n)}}return e}}));if(null===(o=a.flow)||void 0===o?void 0:o.next){let e=Promise.resolve();const t=a.flow.next.bind(a.flow);a.flow.next=async(...n)=>{const o=e;let i;e=new Promise((e=>{i=e})),await o;try{return await t(...n)}finally{i()}}}return a}),(e=>t=>{const n=e(b(t,{afterRequest:async(e,t)=>{if(I(e,t))return void C(me);const n=await k(t);(null==n?void 0:n.sessionExpiration)&&((e,t)=>{var n,o;try{c&&(null===(o=null===(n=window.localStorage)||void 0===n?void 0:n.setItem)||void 0===o||o.call(n,e,t))}catch(e){}})(me,String(n.sessionExpiration))}}));return o(n,["logout","logoutAll","oidc.logout"],ye)}),(n=>i=>{var{autoRefresh:r}=i,s=e(i,["autoRefresh"]);const a=!!r,l="object"==typeof r&&(null==r?void 0:r.customActivityTracking);if(!a||S())return Object.assign(n(s),{markUserActive:()=>{T("markUserActive() called but has no effect")}});const{clearAllTimers:f,setTimer:p}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})();let v,g,w=null,h=!1,m=!1;l&&(U("Activity-based refresh enabled"),w=(()=>{let e=!0;return{hadActivity:()=>e,reset:()=>{e=!1},markActive:()=>{e=!0}}})()),c&&document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&v&&new Date>v&&(U("Expiration time passed, refreshing session"),_())}));const y=n(b(s,{afterRequest:async(e,n)=>{const{sessionJwt:o,refreshJwt:i,sessionExpiration:r,nextRefreshSeconds:s}=await k(n);if(I(e,n))U("Session invalidated, canceling all timers"),f(),v=void 0;else if(o||r){if(v=((e,n)=>{if(n)return new Date(1e3*n);U("Could not extract expiration time from session token, trying to decode the token");try{const n=t(e);if(n.exp)return new Date(1e3*n.exp)}catch(e){return null}})(o,r),!v)return void U("Could not extract expiration time from session token");g=i,h=s>0;let e=((e,t)=>{let n;return t>0?(n=1e3*t,U(`Using provided nextRefreshSeconds: ${t}s`)):n=R(e)-u,n>d&&(U(`Timeout is too large (${n}ms), setting it to ${d}ms`),n=d),n})(v,s);f(),e<=u&&(e=Math.max(R(v),u));const n=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});U(`Setting refresh timer for ${n}. (${e}ms)`),w&&(w.reset(),m=!1),p((()=>{if(c&&"hidden"===document.visibilityState)U("Skipping refresh due to timer - document is hidden");else{if(w&&h&&!w.hadActivity())return U("Skipping refresh due to timer - user is idle"),void(m=!0);U("Refreshing session due to timer"),_()}}),e)}}})),_=()=>y.refresh(V()||g).catch((e=>{T("Automatic session refresh failed",e)}));return Object.assign(o(y,["logout","logoutAll","oidc.logout"],(e=>async(...t)=>{const n=await e(...t);return U("Clearing all timers"),f(),n})),{markUserActive:w?()=>{U("markUserActive() called"),h||U("markUserActive() called but server does not have inactivity timeout configured (no nextRefreshSeconds)"),w.markActive(),m&&(U("User became active after skipped refresh, triggering refresh"),m=!1,f(),_())}:()=>{T("markUserActive() called but customActivityTracking is not enabled — this call has no effect")}})}),(t=>n=>{var{storeLastAuthenticatedUser:i=!0,keepLastAuthenticatedUserAfterLogout:r=!1}=n,s=e(n,["storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout"]);if(!i)return Object.assign(t(s),{getLastUserLoginId:ve,getLastUserDisplayName:ge});const a=t(b(s,{afterRequest:async(e,t)=>{var n;const{userInfo:o,lastAuth:i}=await(async e=>{if(!(null==e?void 0:e.ok))return{userInfo:void 0,lastAuth:void 0};const t=await(null==e?void 0:e.clone().json()),n=y((null==t?void 0:t.authInfo)||t||{});return{userInfo:(null==n?void 0:n.user)||((null==n?void 0:n.hasOwnProperty("userId"))?n:void 0),lastAuth:t.lastAuth}})(t),r=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],s=null==o?void 0:o.name;r?(pe(r),(e=>{O(fe,e)})(s)):(null==i?void 0:i.loginId)&&pe(i.loginId)}}));let l=o(a,["flow.start"],we);return l=o(l,["logout","logoutAll"],he(r)),Object.assign(l,{getLastUserLoginId:ve,getLastUserDisplayName:ge})}),(t=>n=>{var{persistTokens:r,sessionTokenViaCookie:s,refreshTokenViaCookie:a,storagePrefix:l,refreshCookieName:d}=n,u=e(n,["persistTokens","sessionTokenViaCookie","refreshTokenViaCookie","storagePrefix","refreshCookieName"]);if(!r||!c)return t(Object.assign({refreshCookieName:d},u));let f;const p=t(b(Object.assign({refreshCookieName:d},u),{beforeRequest:B(l,a,d),afterRequest:async(e,t)=>{if(I(e,t))U("Session invalidated, clearing persisted tokens"),H(l,s,a,f);else{const e=await k(t);e.cookieName?O(`${l||""}${J}`,e.cookieName):e.refreshJwt&&D(`${l||""}${J}`);const n=((e={},t=!1,n="",o=!1)=>{var r,s,a,l;const{sessionJwt:c,refreshJwt:d,trustedDeviceJwt:u,knownDeviceJwt:f}=e;let p;if(d)if(o){D(`${n}${E}`);const t=o.sameSite||"Strict",i=null===(r=o.secure)||void 0===r||r,a=null!==(s=o.domain)&&void 0!==s?s:e.cookieDomain,l=K(o);i&&"https:"!==window.location.protocol&&T("Refresh token cookie is configured with secure=true but the page is not using HTTPS. The cookie will not be set. To fix this, pass refreshTokenViaCookie: { secure: process.env['NODE_ENV'] !== 'development' }");const c=Object.assign(Object.assign({},e),{cookieSameSite:t,cookieSecure:i,cookieDomain:a});P(l,d,c);const u=q(a);p=Object.assign(Object.assign({},p),{refresh:{path:c.cookiePath,domain:u?a:void 0}})}else{const e=K(o);i.remove(e),O(`${n}${E}`,d)}if(c)if(t){const n=t.sameSite||"Strict",o=null===(a=t.secure)||void 0===a||a,i=null!==(l=t.domain)&&void 0!==l?l:e.cookieDomain,r=L(t);o&&"https:"!==window.location.protocol&&T("Session token cookie is configured with secure=true but the page is not using HTTPS. The cookie will not be set. To fix this, pass sessionTokenViaCookie: { secure: process.env['NODE_ENV'] !== 'development' }");const s=Object.assign(Object.assign({},e),{cookieSameSite:n,cookieSecure:o,cookieDomain:i});P(r,c,s);const d=q(i);p=Object.assign(Object.assign({},p),{session:{path:s.cookiePath,domain:d?i:void 0}})}else O(`${n}${$}`,c);return e.idToken&&O(`${n}${N}`,e.idToken),u&&O(`${n}DTD`,u),f&&O(`${n}DKD`,f),p})(e,s,l,a);n&&(f=n)}}})),v=o(p,["logout","logoutAll","oidc.logout"],ke(l,s,a,(()=>f)));return Object.assign(v,{getRefreshToken:()=>V(l,a),getSessionToken:()=>F(l,s),getIdToken:()=>M(l)})}))((e=>{const t=n(e),o=Ke(t,e.projectId,e.oidcConfig);return Object.assign(Object.assign({},t),{refresh:async(n,i)=>{var r;if(S())return U(`Refresh called in native flow: ${(new Error).stack}`),Promise.resolve({ok:!1,error:{errorCode:"J171000",errorDescription:"Refresh is not supported in native flows via the web SDK"}});if(e.oidcConfig)try{return await o.refreshToken(n),Promise.resolve({ok:!0})}catch(e){return Promise.resolve({ok:!1,error:{errorCode:"J161001",errorDescription:e.toString()}})}if(i&&c&&void 0!==window.localStorage&&!A(me)&&!x(ue)&&!A("DSLI_DISABLED"))return Promise.resolve({ok:!0});const s=F(),a=V();let l="";if(e.getExternalToken)try{l=await(null===(r=e.getExternalToken)||void 0===r?void 0:r.call(e))}catch(e){U("Error getting external token while refreshing",e)}return t.refresh(n,{dcs:s?"t":"f",dcr:a?"t":"f"},l,i)},logout:async n=>{if(e.oidcConfig)try{return await o.logout({id_token_hint:n}),Promise.resolve({ok:!0})}catch(e){return Promise.resolve({ok:!1,error:{errorCode:"J161000",errorDescription:e.toString()}})}return t.logout(n)},flow:Ne(t),webauthn:Te(t),fedcm:(i=t,r=e.projectId,{onetap:{requestExchangeCode(e){$e(i,e)},requestAuthentication(e){$e(i,e)}},async oneTap(e,t,n,o,r){await Ee(i,{provider:e,oneTapConfig:t,loginOptions:n,onSkipped:o,onDismissed:r})},async launch(e){var t;const n={identity:{context:e||"signin",providers:[{configURL:i.httpClient.buildUrl(r+Re.config),clientId:r}]}},o=await(null===(t=navigator.credentials)||void 0===t?void 0:t.get(n));return i.refresh(o.token)},isSupported:()=>c&&"IdentityCredential"in window,async isLoggedIn(e){var t;const n=i.httpClient.buildUrl(r+Re.config);try{const o={identity:{context:e||"signin",providers:[{configURL:n,clientId:r}]}},i=await(null===(t=navigator.credentials)||void 0===t?void 0:t.get(o));return!!i&&!!i.token}catch(e){return!1}}}),oidc:o});var i,r}));export{E as REFRESH_TOKEN_KEY,$ as SESSION_TOKEN_KEY,Y as clearFingerprintData,Ve as createSdk,Ve as default,Q as ensureFingerprintIds,F as getSessionToken,Je as hasOidcParamsInUrl};
|
|
1
|
+
import{__rest as e}from"tslib";import{jwtDecode as t}from"jwt-decode";import n,{wrapWith as o}from"@descope/core-js-sdk";import i from"js-cookie";import{load as r,defaultScriptUrlPattern as s,defaultEndpoint as a}from"@fingerprintjs/fingerprintjs-pro";const l="3.2.0",c="undefined"!=typeof window,d=Math.pow(2,31)-1,u=2e4,v=`https://descopecdn.com/npm/oidc-client-ts@${l}/dist/browser/oidc-client-ts.min.js`,f=`https://cdn.jsdelivr.net/npm/oidc-client-ts@${l}/dist/browser/oidc-client-ts.min.js`;const p=["/v1/auth/refresh","/v1/auth/try-refresh","/v1/auth/me","/v1/auth/me/tenants","/v1/auth/me/history"];let g;const h=e=>{try{return t(e).exp}catch(e){return null}},w=e=>{const{refresh_expire_in:t,refresh_token:n}=e;return t?Math.floor(Date.now()/1e3)+t:h(n)},m=e=>{const{expires_in:t,expires_at:n,access_token:o}=e;return n||(t?Math.floor(Date.now()/1e3)+t:o?h(o):void 0)},y=t=>{const{access_token:n,id_token:o,refresh_token:i,refresh_expire_in:r}=t,s=e(t,["access_token","id_token","refresh_token","refresh_expire_in"]);return Object.assign({sessionJwt:t.sessionJwt||n,idToken:o,refreshJwt:t.refreshJwt||i,sessionExpiration:t.sessionExpiration||m(t),cookieExpiration:t.cookieExpiration||w(t)},s)},b=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var i;return n[o]=[].concat((null===(i=e.hooks)||void 0===i?void 0:i[o])||[]).concat((null==t?void 0:t[o])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},k=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json()),n=(null==t?void 0:t.authInfo)||t||{};return y(n)},S=()=>c&&!!window.descopeBridge,I=(e,t)=>{if(!((null==t?void 0:t.status)>=400&&(null==t?void 0:t.status)<500))return!1;const n=(null==e?void 0:e.path)||"";return p.includes(n)},_=void 0!==g||c&&void 0!==window.localStorage,O=(e,t)=>{var n,o;return null===(o=null===(n=g||c&&window.localStorage)||void 0===n?void 0:n.setItem)||void 0===o?void 0:o.call(n,e,t)},x=e=>{var t,n;return null===(n=null===(t=g||c&&window.localStorage)||void 0===t?void 0:t.getItem)||void 0===n?void 0:n.call(t,e)},D=e=>{var t,n;return null===(n=null===(t=g||c&&window.localStorage)||void 0===t?void 0:t.removeItem)||void 0===n?void 0:n.call(t,e)},j=e=>{var t,n,o,i,r;return null!==(r=null!==(n=null===(t=null==g?void 0:g.key)||void 0===t?void 0:t.call(g,e))&&void 0!==n?n:c&&(null===(i=null===(o=window.localStorage)||void 0===o?void 0:o.key)||void 0===i?void 0:i.call(o,e)))&&void 0!==r?r:null},A=e=>{var t,n;return c&&(null===(n=null===(t=window.localStorage)||void 0===t?void 0:t.getItem)||void 0===n?void 0:n.call(t,e))||null},C=e=>{var t,n;try{c&&(null===(n=null===(t=window.localStorage)||void 0===t?void 0:t.removeItem)||void 0===n||n.call(t,e))}catch(e){}},U=(...e)=>{console.debug(...e)},T=(...e)=>{console.warn(...e)},$=e=>e?e.getTime()-(new Date).getTime():0,R="DS",E="DSR",N="DSI",J="DSRCN";function P(e,t,n){if(t){const{cookieDomain:o,cookiePath:r,cookieSameSite:s,cookieExpiration:a,cookieSecure:l}=n,c=new Date(1e3*a),d=q(o);i.set(e,t,{path:r,domain:d?o:void 0,expires:c,sameSite:s,secure:l})}}function q(e){const t=window.location.hostname.split("."),n=null==e?void 0:e.split(".");return t.slice(-(null==n?void 0:n.length)).join(".")===e}const L=e=>(null==e?void 0:e.cookieName)||R,K=e=>(null==e?void 0:e.cookieName)||E,V=(e={},n=!1,o="",r=!1)=>{var s,a,l,c,d;const{sessionJwt:u,refreshJwt:v,trustedDeviceJwt:f,knownDeviceJwt:p}=e;let g;if(v)if(r){D(`${o}${E}`);const t=r.sameSite||"Strict",n=null===(s=r.secure)||void 0===s||s,i=null!==(a=r.domain)&&void 0!==a?a:e.cookieDomain,l=K(r);n&&"https:"!==window.location.protocol&&T("Refresh token cookie is configured with secure=true but the page is not using HTTPS. The cookie will not be set. To fix this, pass refreshTokenViaCookie: { secure: process.env['NODE_ENV'] !== 'development' }");const c=Object.assign(Object.assign({},e),{cookieSameSite:t,cookieSecure:n,cookieDomain:i});P(l,v,c);const d=q(i);g=Object.assign(Object.assign({},g),{refresh:{path:c.cookiePath,domain:d?i:void 0}})}else{const e=K(r);i.remove(e),O(`${o}${E}`,v)}if(u)if(n&&!(e=>{var n;try{return!!(null===(n=t(e,{header:!0}).alg)||void 0===n?void 0:n.startsWith("ML-DSA"))}catch(e){return!1}})(u)){D(`${o}${R}`);const t=n.sameSite||"Strict",i=null===(l=n.secure)||void 0===l||l,r=null!==(c=n.domain)&&void 0!==c?c:e.cookieDomain,s=L(n);i&&"https:"!==window.location.protocol&&T("Session token cookie is configured with secure=true but the page is not using HTTPS. The cookie will not be set. To fix this, pass sessionTokenViaCookie: { secure: process.env['NODE_ENV'] !== 'development' }");const a=Object.assign(Object.assign({},e),{cookieSameSite:t,cookieSecure:i,cookieDomain:r});P(s,u,a);const d=q(r);g=Object.assign(Object.assign({},g),{session:{path:a.cookiePath,domain:d?r:void 0}})}else{if(n){const t=null!==(d=n.domain)&&void 0!==d?d:e.cookieDomain;i.remove(L(n),{path:e.cookiePath,domain:q(t)?t:void 0})}O(`${o}${R}`,u)}return e.idToken&&O(`${o}${N}`,e.idToken),f&&O(`${o}DTD`,f),p&&O(`${o}DKD`,p),g};function F(e="",t){return i.get(K(t))||x(`${e}${E}`)||""}function M(e="",t){return i.get(L(t))||x(`${e}${R}`)||""}function H(e=""){return x(`${e}${N}`)||""}function B(e="",t,n,o){D(`${e}${E}`),D(`${e}${R}`),D(`${e}${N}`),D(`${e}${J}`);const r=L(t);i.remove(r,null==o?void 0:o.session);const s=K(n);i.remove(s,null==o?void 0:o.refresh)}const W=(e,t,n)=>o=>{const i=Object.assign(o,{token:o.token||F(e,t)});if(!n){const t=function(e=""){return x(`${e}${J}`)}(e);t&&(i.headers=Object.assign(Object.assign({},i.headers||{}),{"x-descope-refresh-cookie-name":t}))}const r=function(e=""){return x(`${e}DTD`)||""}(e);r&&(i.headers=Object.assign(Object.assign({},i.headers||{}),{"x-descope-trusted-device-token":r}));const s=function(e=""){return x(`${e}DKD`)||""}(e);return s&&(i.headers=Object.assign(Object.assign({},i.headers||{}),{"x-descope-known-device-token":s})),i},z=c&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",G="vsid",X="vrid",Z="fp",Q=(e=!1)=>{const t=x(Z);if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},Y=async(e,t=z)=>{try{if(Q())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),o=new URL(t);o.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const i=new URL(t);i.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const l=i.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",c=r({apiKey:e,endpoint:[o.toString(),a],scriptUrlPattern:[l,s]}),d=await c,{requestId:u}=await d.get({linkedId:n}),v=((e,t)=>({[G]:e,[X]:t}))(n,u);(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};O(Z,JSON.stringify(t))})(v)}catch(e){console.warn("Could not load fingerprint",e)}},ee=()=>{D(Z)},te=e=>{const t=Q(!0);return t&&e.body&&(e.body.fpData=t),e},ne="descopeFlowNonce",oe="X-Descope-Flow-Nonce",ie="/v1/flow/start",re="/v1/flow/next",se=(e,t=ne)=>`${t}${e}`,ae=(e,t=ne)=>{try{const n=se(e,t),o=x(n);if(!o)return null;const i=JSON.parse(o);return i.expiry<Date.now()?(le(e,t),null):{value:i.value,seq:i.seq}}catch(e){return console.error("Error getting flow nonce:",e),null}},le=(e,t=ne)=>{try{const n=se(e,t);D(n)}catch(e){console.error("Error removing flow nonce:",e)}},ce=e=>{var t;return(null===(t=/.*\|#\|(.*)/.exec(e))||void 0===t?void 0:t[1])||null},de=async(e,t)=>{try{const n=t.headers.get(oe),o=null===n?void 0:(e=>{const t=e.indexOf(".");if(t<=0)return;const n=e.slice(0,t);if(!/^\d+$/.test(n))return;const o=Number(n);return Number.isSafeInteger(o)?o:void 0})(n);let i=await t.clone().json().then((e=>(null==e?void 0:e.executionId)||null)).catch((()=>null));return i||(i=ue(e)),{nonce:n,seq:o,executionId:ce(i)}}catch(e){return{nonce:null,seq:void 0,executionId:null}}},ue=e=>{var t;return e.path===re&&(null===(t=e.body)||void 0===t?void 0:t.executionId)?ce(e.body.executionId):null},ve="dls_last_user_login_id",fe="dls_last_user_display_name",pe=e=>O(ve,e),ge=()=>x(ve),he=()=>x(fe),we=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,i=ge(),r=he();i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r);return await e(...t)},me=e=>t=>async(...n)=>{const o=await t(...n);return e||(D(ve),D(fe)),o},ye="DSLI",be=e=>async(...t)=>{const n=await e(...t);return C(ye),n};function ke(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const Se=(e,t,n,o)=>i=>async(...r)=>{const s=await i(...r);return B(e,t,n,null==o?void 0:o()),s};async function Ie(e,t){const n=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Ce(n.publicKey.challenge),n.publicKey.user.id=Ce(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Ce(e.id)})),n}(e);t&&(n.signal=t.signal);try{const e=await navigator.credentials.create(n);return o=e,JSON.stringify({id:o.id,rawId:Ue(o.rawId),type:o.type,authenticatorAttachment:null!==(i=o.authenticatorAttachment)&&void 0!==i?i:void 0,response:{attestationObject:Ue(o.response.attestationObject),clientDataJSON:Ue(o.response.clientDataJSON)}})}catch(e){throw await xe(e,n,!0)}var o,i}async function _e(e,t){const n=je(e);t&&(n.signal=t.signal);try{return Ae(await navigator.credentials.get(n))}catch(e){throw await xe(e,n,!1)}}async function Oe(e,t){const n=je(e);n.signal=t.signal,n.mediation="conditional";try{return Ae(await navigator.credentials.get(n))}catch(e){throw await xe(e,n,!1)}}async function xe(e,t,n){if(e&&"object"==typeof e)try{e.reason=await async function(e,t,n){var o,i;const r=null==e?void 0:e.name;if("AbortError"===r&&(null==t?void 0:t.signal)instanceof AbortSignal)return"aborted";if("InvalidStateError"===r&&n)return"authenticator_already_registered";if("NotSupportedError"===r)return"no_supported_algorithm";if("ConstraintError"===r)return"authenticator_constraints_unsupported";if("SecurityError"===r){const e=window.location.hostname;return"localhost"===e||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e)?"invalid_rpid":"invalid_domain"}if(!await De())return"webauthn_unsupported";const s="platform"===(null===(i=null===(o=null==t?void 0:t.publicKey)||void 0===o?void 0:o.authenticatorSelection)||void 0===i?void 0:i.authenticatorAttachment);return n&&s&&!await De(!0)?"platform_authenticator_unsupported":"NotAllowedError"===r?"not_allowed":"unknown"}(e,t,n)}catch(e){}return e}async function De(e=!1){var t,n;if(!c)return Promise.resolve(!1);if(S()){const e=null===(n=null===(t=window.descopeBridge)||void 0===t?void 0:t.hostInfo)||void 0===n?void 0:n.webauthn;if("boolean"==typeof e)return e}const o=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return o&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():o}function je(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Ce(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Ce(e.id)})),n}function Ae(e){var t;return JSON.stringify({id:e.id,rawId:Ue(e.rawId),type:e.type,authenticatorAttachment:null!==(t=e.authenticatorAttachment)&&void 0!==t?t:void 0,response:{authenticatorData:Ue(e.response.authenticatorData),clientDataJSON:Ue(e.response.clientDataJSON),signature:Ue(e.response.signature),userHandle:e.response.userHandle?Ue(e.response.userHandle):void 0}})}function Ce(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Ue(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Te,$e=(Te=e=>({async signUp(t,n,o){const i=await e.webauthn.signUp.start(t,window.location.origin,n,o);if(!i.ok)return i;const r=await Ie(i.data.options);return await e.webauthn.signUp.finish(i.data.transactionId,r)},async signIn(t,n){const o=await e.webauthn.signIn.start(t,window.location.origin,void 0,void 0,n);if(!o.ok)return o;const i=await _e(o.data.options);return await e.webauthn.signIn.finish(o.data.transactionId,i)},async signUpOrIn(t,n){var o;const i=await e.webauthn.signUpOrIn.start(t,window.location.origin,n);if(!i.ok)return i;if(null===(o=i.data)||void 0===o?void 0:o.create){const t=await Ie(i.data.options);return await e.webauthn.signUp.finish(i.data.transactionId,t)}{const t=await _e(i.data.options);return await e.webauthn.signIn.finish(i.data.transactionId,t)}},async update(t,n,o){const i=await e.webauthn.update.start(t,window.location.origin,n,o);if(!i.ok)return i;const r=await Ie(i.data.options);return await e.webauthn.update.finish(i.data.transactionId,r)},helpers:{create:Ie,get:_e,isSupported:De,conditional:Oe}}),(...e)=>{const t=Te(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t});const Re={config:"/fedcm/config"};async function Ee(e,t){var n;try{await Ne(e,t)}catch(e){null===(n=null==t?void 0:t.onFailed)||void 0===n||n.call(t,e)}}async function Ne(e,t){var n,o;const i=await async function(e,t="google",n,o,i){const r=(()=>{if(window.crypto&&window.crypto.getRandomValues){const e=new Uint8Array(16);return window.crypto.getRandomValues(e),Array.from(e,(e=>e.toString(16).padStart(2,"0"))).join("")}return Math.random().toString(36).substring(2)})(),s=await async function(){return new Promise(((e,t)=>{if(window.google)return void e(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?e(window.google.accounts.id):t("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){t("Failed to load Google GSI client script - failed to load")}}))}(),a=await e.oauth.getOneTapClientId(t);if(!a.ok)throw new Error("Failed to get OneTap client ID for provider "+t);const l=a.data.clientId;return new Promise((e=>{var a,c;const d=n=>{e({provider:t,nonce:r,credential:null==n?void 0:n.credential})};s.initialize(Object.assign(Object.assign({},n),{itp_support:null===(a=null==n?void 0:n.itp_support)||void 0===a||a,use_fedcm_for_prompt:null===(c=null==n?void 0:n.use_fedcm_for_prompt)||void 0===c||c,client_id:l,callback:d,nonce:r})),s.prompt((e=>{var t,n;if(i&&(null==e?void 0:e.isDismissedMoment())){const n=null===(t=e.getDismissedReason)||void 0===t?void 0:t.call(e);return null==i||i(n),void d()}if(o&&(null==e?void 0:e.isSkippedMoment())){const t=null===(n=e.getSkippedReason)||void 0===n?void 0:n.call(e);return null==o||o(t),void d()}}))}))}(e,t.provider,t.oneTapConfig,t.onSkipped,t.onDismissed);if(!i.credential)return null;if(null==t?void 0:t.onCodeReceived){const o=await e.oauth.verifyOneTapIDToken(i.provider,i.credential,i.nonce,null==t?void 0:t.loginOptions);if(!o.ok||!o.data)throw new Error("Failed to verify OneTap client ID for provider "+i.provider);null===(n=null==t?void 0:t.onCodeReceived)||void 0===n||n.call(t,o.data.code)}else{const n=await e.oauth.exchangeOneTapIDToken(i.provider,i.credential,i.nonce,null==t?void 0:t.loginOptions);if(!n.ok||!n.data)throw new Error("Failed to exchange OneTap client ID for provider "+i.provider);null===(o=null==t?void 0:t.onAuthenticated)||void 0===o||o.call(t,n.data)}}var Je=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await De(),o=Object.assign(Object.assign({location:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return t[1]=o,e.flow.start(...t)}});const Pe=()=>window.location.search.includes("code")&&window.location.search.includes("state");let qe;const Le=(e,t)=>new Promise(((n,o)=>{if(!e.length)return o(new Error("No URLs provided to loadScriptWithFallback"));const i=t();if(i)return n(i);const r=e.shift(),s=document.createElement("script");s.src=r,s.id=(e=>{let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return Math.abs(t).toString(16)})(r),s.onload=()=>{const e=t();if(e)return n(e);throw new Error("Could not get entry after loading script from URL")},s.addEventListener("error",(()=>{Le(e,t),s.setAttribute("data-error","true")})),document.body.appendChild(s)}));const Ke=async(e,t,n)=>{qe||(qe=(async()=>{try{return require("oidc-client-ts")}catch(e){return Le([v,f],(()=>window.oidc))}})());const{OidcClient:o,WebStorageStateStore:i}=await qe;if(!o)throw new Error("oidc-client-ts is not installed. Please install it by running `npm install oidc-client-ts`");const r=(null==n?void 0:n.redirectUri)||window.location.href;let s,a,l,c;if(null==n?void 0:n.issuer){if(!n.clientId)throw new Error("clientId is required when providing a custom issuer/authority");s=n.issuer,a=n.clientId,l=`${a}_user`,c="openid"}else(null==n?void 0:n.applicationId)?(s=e.httpClient.buildUrl(t),s=`${s}/${n.applicationId}`,a=t,l=`${a}_user`,c="openid email roles descope.custom_claims offline_access"):(s=e.httpClient.buildUrl(t),a=t,l=`${a}_user`,c="openid email roles descope.custom_claims offline_access");const d={authority:s,client_id:a,redirect_uri:r,response_type:"code",scope:(null==n?void 0:n.scope)||c,stateStore:new i({store:window.localStorage,prefix:a}),loadUserInfo:!0,fetchRequestCredentials:"same-origin"};return(null==n?void 0:n.redirectUri)&&(d.redirect_uri=n.redirectUri),{client:new o(d),stateUserKey:l}},Ve=(e,t,n)=>{const o=async()=>{let o,i;return o&&i||({client:o,stateUserKey:i}=await Ke(e,t,n)),{client:o,stateUserKey:i}},i=async(t="")=>{var n;const{client:i,stateUserKey:r}=await o(),s=await i.processSigninResponse(t||window.location.href);var a;return await(null===(n=e.httpClient.hooks)||void 0===n?void 0:n.afterRequest({},new Response(JSON.stringify(s)))),O(r,JSON.stringify({id_token:(a=s).id_token,session_state:a.session_state,profile:a.profile})),(()=>{const e=new URL(window.location.href);e.searchParams.delete("code"),e.searchParams.delete("state"),window.history.replaceState({},document.title,e.toString())})(),s};return{loginWithRedirect:async(t={},n=!1)=>{var i;const{client:r}=await o(),s=await r.createSigninRequest(t),{url:a}=s;return n||(await(null===(i=e.httpClient.hooks)||void 0===i?void 0:i.afterRequest({},new Response(JSON.stringify(s)))),window.location.href=a),{ok:!0,data:s}},finishLogin:i,finishLoginIfNeed:async(e="")=>{if(Pe())return await i(e)},refreshToken:async t=>{var n;const{client:i,stateUserKey:r}=await o(),s=(e=>{const t=x(e);return t?JSON.parse(t):null})(r);if(!s)throw new Error("User not found in storage to refresh token");let a=t;if(!a){const t={};e.httpClient.hooks.beforeRequest(t),a=t.token}const l=await i.useRefreshToken({state:{refresh_token:a,session_state:s.session_state,profile:s.profile}});return await(null===(n=e.httpClient.hooks)||void 0===n?void 0:n.afterRequest({},new Response(JSON.stringify(l)))),l},logout:async(e,t=!1)=>{const{client:n,stateUserKey:i}=await o();e||(e={}),e.id_token_hint=e.id_token_hint||H(),e.post_logout_redirect_uri=e.post_logout_redirect_uri||window.location.href;const r=await n.createSignoutRequest(e),{url:s}=r;return D(i),t||window.location.replace(s),r}}},Fe=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>t=>{var n;return n=t.customStorage,g=n,e(t)}),(t=>n=>{var{fpKey:o,fpLoad:i}=n,r=e(n,["fpKey","fpLoad"]);return c?(o&&i&&Y(o).catch((()=>null)),t(b(r,{beforeRequest:te}))):t(r)}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.56.0"},t.baseHeaders)}))),(e=>t=>{const n=ke(),i=ke(),r=ke(),s=ke(),a=e(b(t,{afterRequest:async(e,t)=>{if(I(e,t))U("Session invalidated, notifying subscribers with empty values"),i.pub(null),r.pub(null),n.pub(null),s.pub(null);else{const e=await(async e=>{const t=await k(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)})(t);e&&r.pub(e);const{sessionJwt:o,sessionExpiration:a,claims:l}=await k(t);o&&i.pub(o),l&&s.pub(l),(a||o)&&n.pub(a||42)}}})),l=o(a,["logout","logoutAll","oidc.logout"],(e=>async(...t)=>{const o=await e(...t);return i.pub(null),r.pub(null),n.pub(null),s.pub(null),o}));return Object.assign(l,{onSessionTokenChange:i.sub,onUserChange:r.sub,onClaimsChange:s.sub,onIsAuthenticatedChange:e=>n.sub((t=>{e(!!t)}))})}),(t=>n=>{var o;const{enableFlowNonce:i=!0,nonceStoragePrefix:r=ne}=n,s=e(n,["enableFlowNonce","nonceStoragePrefix"]);if(!i)return t(s);((e=ne)=>{try{if(!_)return;for(let i=0;i<(t=void 0,n=void 0,o=void 0,null!==(o=null!==(t=null==g?void 0:g.length)&&void 0!==t?t:c&&(null===(n=window.localStorage)||void 0===n?void 0:n.length))&&void 0!==o?o:0);i++){const t=j(i);if(t&&t.startsWith(e)){const e=x(t);if(e)try{JSON.parse(e).expiry<Date.now()&&D(t)}catch(e){D(t)}}}}catch(e){console.error("Error cleaning up expired nonces:",e)}var t,n,o})(r);const a=t(b(s,{afterRequest:async(e,t)=>{var n;if(e.path!==ie&&e.path!==re)return;const{nonce:o,seq:i,executionId:s}=await de(e,t);if(!o||!s)return;const a=e.path===ie,l=null===(n=ae(s,r))||void 0===n?void 0:n.seq;if(!a&&void 0!==i&&void 0!==l&&i<=l)return;((e,t,n,o=ne,i)=>{try{const r=se(e,o),s=n?172800:10800,a={value:t,expiry:Date.now()+1e3*s,isStart:n,seq:i};O(r,JSON.stringify(a))}catch(e){console.error("Error setting flow nonce:",e)}})(s,o,a,r,null!=i?i:a?void 0:l)},beforeRequest:e=>{if(e.path===re){const t=ue(e);if(t){const n=((e,t=ne)=>{var n,o;return null!==(o=null===(n=ae(e,t))||void 0===n?void 0:n.value)&&void 0!==o?o:null})(t,r);n&&(e.headers=e.headers||{},e.headers[oe]=n)}}return e}}));if(null===(o=a.flow)||void 0===o?void 0:o.next){let e=Promise.resolve();const t=a.flow.next.bind(a.flow);a.flow.next=async(...n)=>{const o=e;let i;e=new Promise((e=>{i=e})),await o;try{return await t(...n)}finally{i()}}}return a}),(e=>t=>{const n=e(b(t,{afterRequest:async(e,t)=>{if(I(e,t))return void C(ye);const n=await k(t);(null==n?void 0:n.sessionExpiration)&&((e,t)=>{var n,o;try{c&&(null===(o=null===(n=window.localStorage)||void 0===n?void 0:n.setItem)||void 0===o||o.call(n,e,t))}catch(e){}})(ye,String(n.sessionExpiration))}}));return o(n,["logout","logoutAll","oidc.logout"],be)}),(n=>i=>{var{autoRefresh:r}=i,s=e(i,["autoRefresh"]);const a=!!r,l="object"==typeof r&&(null==r?void 0:r.customActivityTracking);if(!a||S())return Object.assign(n(s),{markUserActive:()=>{T("markUserActive() called but has no effect")}});const{clearAllTimers:v,setTimer:f}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})();let p,g,h=null,w=!1,m=!1;l&&(U("Activity-based refresh enabled"),h=(()=>{let e=!0;return{hadActivity:()=>e,reset:()=>{e=!1},markActive:()=>{e=!0}}})()),c&&document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&p&&new Date>p&&(U("Expiration time passed, refreshing session"),_())}));const y=n(b(s,{afterRequest:async(e,n)=>{const{sessionJwt:o,refreshJwt:i,sessionExpiration:r,nextRefreshSeconds:s}=await k(n);if(I(e,n))U("Session invalidated, canceling all timers"),v(),p=void 0;else if(o||r){if(p=((e,n)=>{if(n)return new Date(1e3*n);U("Could not extract expiration time from session token, trying to decode the token");try{const n=t(e);if(n.exp)return new Date(1e3*n.exp)}catch(e){return null}})(o,r),!p)return void U("Could not extract expiration time from session token");g=i,w=s>0;let e=((e,t)=>{let n;return t>0?(n=1e3*t,U(`Using provided nextRefreshSeconds: ${t}s`)):n=$(e)-u,n>d&&(U(`Timeout is too large (${n}ms), setting it to ${d}ms`),n=d),n})(p,s);v(),e<=u&&(e=Math.max($(p),u));const n=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});U(`Setting refresh timer for ${n}. (${e}ms)`),h&&(h.reset(),m=!1),f((()=>{if(c&&"hidden"===document.visibilityState)U("Skipping refresh due to timer - document is hidden");else{if(h&&w&&!h.hadActivity())return U("Skipping refresh due to timer - user is idle"),void(m=!0);U("Refreshing session due to timer"),_()}}),e)}}})),_=()=>y.refresh(F()||g).catch((e=>{T("Automatic session refresh failed",e)}));return Object.assign(o(y,["logout","logoutAll","oidc.logout"],(e=>async(...t)=>{const n=await e(...t);return U("Clearing all timers"),v(),n})),{markUserActive:h?()=>{U("markUserActive() called"),w||U("markUserActive() called but server does not have inactivity timeout configured (no nextRefreshSeconds)"),h.markActive(),m&&(U("User became active after skipped refresh, triggering refresh"),m=!1,v(),_())}:()=>{T("markUserActive() called but customActivityTracking is not enabled — this call has no effect")}})}),(t=>n=>{var{storeLastAuthenticatedUser:i=!0,keepLastAuthenticatedUserAfterLogout:r=!1}=n,s=e(n,["storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout"]);if(!i)return Object.assign(t(s),{getLastUserLoginId:ge,getLastUserDisplayName:he});const a=t(b(s,{afterRequest:async(e,t)=>{var n;const{userInfo:o,lastAuth:i}=await(async e=>{if(!(null==e?void 0:e.ok))return{userInfo:void 0,lastAuth:void 0};const t=await(null==e?void 0:e.clone().json()),n=y((null==t?void 0:t.authInfo)||t||{});return{userInfo:(null==n?void 0:n.user)||((null==n?void 0:n.hasOwnProperty("userId"))?n:void 0),lastAuth:t.lastAuth}})(t),r=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],s=null==o?void 0:o.name;r?(pe(r),(e=>{O(fe,e)})(s)):(null==i?void 0:i.loginId)&&pe(i.loginId)}}));let l=o(a,["flow.start"],we);return l=o(l,["logout","logoutAll"],me(r)),Object.assign(l,{getLastUserLoginId:ge,getLastUserDisplayName:he})}),(t=>n=>{var{persistTokens:i,sessionTokenViaCookie:r,refreshTokenViaCookie:s,storagePrefix:a,refreshCookieName:l}=n,d=e(n,["persistTokens","sessionTokenViaCookie","refreshTokenViaCookie","storagePrefix","refreshCookieName"]);if(!i||!c)return t(Object.assign({refreshCookieName:l},d));let u;const v=t(b(Object.assign({refreshCookieName:l},d),{beforeRequest:W(a,s,l),afterRequest:async(e,t)=>{if(I(e,t))U("Session invalidated, clearing persisted tokens"),B(a,r,s,u);else{const e=await k(t);e.cookieName?O(`${a||""}${J}`,e.cookieName):e.refreshJwt&&D(`${a||""}${J}`);const n=V(e,r,a,s);n&&(u=n)}}})),f=o(v,["logout","logoutAll","oidc.logout"],Se(a,r,s,(()=>u)));return Object.assign(f,{getRefreshToken:()=>F(a,s),getSessionToken:()=>M(a,r),getIdToken:()=>H(a)})}))((e=>{const t=n(e),o=Ve(t,e.projectId,e.oidcConfig);return Object.assign(Object.assign({},t),{refresh:async(n,i)=>{var r;if(S())return U(`Refresh called in native flow: ${(new Error).stack}`),Promise.resolve({ok:!1,error:{errorCode:"J171000",errorDescription:"Refresh is not supported in native flows via the web SDK"}});if(e.oidcConfig)try{return await o.refreshToken(n),Promise.resolve({ok:!0})}catch(e){return Promise.resolve({ok:!1,error:{errorCode:"J161001",errorDescription:e.toString()}})}if(i&&c&&void 0!==window.localStorage&&!A(ye)&&!x(ve)&&!A("DSLI_DISABLED"))return Promise.resolve({ok:!0});const s=M(),a=F();let l="";if(e.getExternalToken)try{l=await(null===(r=e.getExternalToken)||void 0===r?void 0:r.call(e))}catch(e){U("Error getting external token while refreshing",e)}return t.refresh(n,{dcs:s?"t":"f",dcr:a?"t":"f"},l,i)},logout:async(n,i)=>{if(e.oidcConfig)try{return await o.logout({id_token_hint:n}),Promise.resolve({ok:!0})}catch(e){return Promise.resolve({ok:!1,error:{errorCode:"J161000",errorDescription:e.toString()}})}return t.logout(n,i)},flow:Je(t),webauthn:$e(t),fedcm:(i=t,r=e.projectId,{onetap:{requestExchangeCode(e){Ee(i,e)},requestAuthentication(e){Ee(i,e)}},async oneTap(e,t,n,o,r){await Ne(i,{provider:e,oneTapConfig:t,loginOptions:n,onSkipped:o,onDismissed:r})},async launch(e){var t;const n={identity:{context:e||"signin",providers:[{configURL:i.httpClient.buildUrl(r+Re.config),clientId:r}]}},o=await(null===(t=navigator.credentials)||void 0===t?void 0:t.get(n));return i.refresh(o.token)},isSupported:()=>c&&"IdentityCredential"in window,async isLoggedIn(e){var t;const n=i.httpClient.buildUrl(r+Re.config);try{const o={identity:{context:e||"signin",providers:[{configURL:n,clientId:r}]}},i=await(null===(t=navigator.credentials)||void 0===t?void 0:t.get(o));return!!i&&!!i.token}catch(e){return!1}}}),oidc:o});var i,r}));export{E as REFRESH_TOKEN_KEY,R as SESSION_TOKEN_KEY,ee as clearFingerprintData,Fe as createSdk,Fe as default,Y as ensureFingerprintIds,M as getSessionToken,Pe as hasOidcParamsInUrl};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|