@descope/react-sdk 2.23.11 → 2.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/AuthProvider/AuthProvider.js +1 -1
- package/dist/cjs/components/AuthProvider/AuthProvider.js.map +1 -1
- package/dist/cjs/constants.js +1 -1
- package/dist/cjs/utils.js +1 -1
- package/dist/cjs/utils.js.map +1 -1
- package/dist/esm/components/AuthProvider/AuthProvider.js +1 -1
- package/dist/esm/components/AuthProvider/AuthProvider.js.map +1 -1
- package/dist/esm/constants.js +1 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/utils.js +1 -1
- package/dist/esm/utils.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/types/sdk.d.ts +18 -18
- package/dist/types/utils.d.ts +1 -0
- package/package.json +12 -12
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../../hooks/Context.js"),s=require("../../utils.js"),r=require("./useSdk.js");function o(e){return e&&e.__esModule?e:{default:e}}var n=o(e);exports.default=({projectId:o,baseUrl:a="",baseStaticUrl:i="",baseCdnUrl:u="",sessionTokenViaCookie:c=!1,hooks:d,persistTokens:l=!0,autoRefresh:h=!0,oidcConfig:f,storeLastAuthenticatedUser:k=!0,keepLastAuthenticatedUserAfterLogout:g=!1,refreshCookieName:S="",getExternalToken:U,customStorage:C,children:L})=>{const[A
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../../hooks/Context.js"),s=require("../../utils.js"),r=require("./useSdk.js");function o(e){return e&&e.__esModule?e:{default:e}}var n=o(e);exports.default=({projectId:o,baseUrl:a="",baseStaticUrl:i="",baseCdnUrl:u="",sessionTokenViaCookie:c=!1,hooks:d,persistTokens:l=!0,autoRefresh:h=!0,oidcConfig:f,storeLastAuthenticatedUser:k=!0,keepLastAuthenticatedUserAfterLogout:g=!1,refreshCookieName:S="",getExternalToken:U,customStorage:C,children:L})=>{const[p,A]=e.useState(),[m,b]=e.useState(),[j,v]=e.useState(),[T,I]=e.useState(!1),[x,E]=e.useState(!1),[R,q]=e.useState(!1),[N,V]=e.useState(!!f),_=e.useRef(!1),M=r.default({projectId:o,baseUrl:a,persistTokens:l,autoRefresh:h,sessionTokenViaCookie:c,hooks:d,oidcConfig:f,storeLastAuthenticatedUser:k,keepLastAuthenticatedUserAfterLogout:g,refreshCookieName:S,getExternalToken:U,customStorage:C});e.useEffect((()=>{if(M){const e=M.onSessionTokenChange(b),t=M.onUserChange(A),s=M.onIsAuthenticatedChange(I),r=M.onClaimsChange(v);return()=>{e(),t(),s(),r()}}}),[M]);const w=e.useRef(!1),y=e.useRef(!1);e.useEffect((()=>{M&&f&&!_.current&&(_.current=!0,M.oidc.finishLoginIfNeed().finally((()=>{V(!1),w.current=!0})))}),[]);const F=e.useCallback((()=>{s.isDescopeBridge()||w.current||(w.current=!0,q(!0),s.withValidation(null==M?void 0:M.refresh)(void 0,!0).then((()=>{q(!1)})))}),[M]),O=e.useCallback((()=>{y.current||(y.current=!0,E(!0),s.withValidation(M.me)().then((()=>{E(!1)})))}),[M]),P=e.useMemo((()=>({fetchUser:O,user:p,isUserLoading:x,isUserFetched:y.current,fetchSession:F,session:m,isAuthenticated:T,isSessionLoading:R,isOidcLoading:N,isSessionFetched:w.current,projectId:o,baseUrl:a,baseStaticUrl:i,baseCdnUrl:u,storeLastAuthenticatedUser:k,keepLastAuthenticatedUserAfterLogout:g,refreshCookieName:S,customStorage:C,setUser:A,setSession:b,setIsAuthenticated:I,claims:j,sdk:M})),[O,p,x,y.current,F,m,T,R,N,w.current,o,a,i,u,g,S,C,A,b,I,j,M]);return n.default.createElement(t.default.Provider,{value:P},L)};
|
|
2
2
|
//# sourceMappingURL=AuthProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthProvider.js","sources":["../../../../src/components/AuthProvider/AuthProvider.tsx"],"sourcesContent":["import React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { CookieConfig, OidcConfig } from '@descope/web-js-sdk';\nimport { Claims } from '@descope/core-js-sdk';\nimport { CustomStorage } from '@descope/web-component';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { withValidation } from '../../utils';\nimport useSdk from './useSdk';\n\ntype Hooks = Parameters<typeof useSdk>[0]['hooks'];\n\ninterface IAuthProviderProps {\n projectId: string;\n baseUrl?: string;\n // allows to override the base URL that is used to fetch static files\n baseStaticUrl?: string;\n // allows to override the base URL that is used to fetch external script files\n baseCdnUrl?: string;\n // Default is true. If true, tokens will be stored on local storage and can accessed with getToken function\n persistTokens?: boolean;\n // Default is true. If true, the SDK will automatically refresh the session token when it is about to expire\n autoRefresh?: boolean;\n // If true, session token (jwt) will be stored on cookie. Otherwise, the session token will be\n // stored on local storage and can accessed with getSessionToken function\n // Use this option if session token will stay small (less than 1k)\n // NOTE: Session token can grow, especially in cases of using authorization, or adding custom claims\n sessionTokenViaCookie?: CookieConfig;\n hooks?: Hooks;\n // If truthy he SDK refresh and logout functions will use the OIDC client\n // Accepts boolean or OIDC configuration\n oidcConfig?: OidcConfig;\n // Default is true. If true, last authenticated user will be stored on local storage and can accessed with getUser function\n storeLastAuthenticatedUser?: boolean;\n // If true, last authenticated user will not be removed after logout\n keepLastAuthenticatedUserAfterLogout?: boolean;\n // Use this option if the authentication is done via cookie, and configured with a different name\n // Currently, this is done using Descope Flows\n refreshCookieName?: string;\n // Function to get external token, for seamless migration from external system\n getExternalToken?: () => Promise<string>;\n // Custom storage object for authentication related data\n customStorage?: CustomStorage;\n children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n baseCdnUrl = '',\n sessionTokenViaCookie = false,\n hooks = undefined,\n persistTokens = true,\n autoRefresh = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n getExternalToken = undefined,\n customStorage = undefined,\n children = undefined,\n}) => {\n const [user, setUser] = useState<User>();\n const [session, setSession] = useState<string>();\n const [claims, setClaims] = useState<Claims>();\n const [isAuthenticated, setIsAuthenticated] = useState(false);\n\n const [isUserLoading, setIsUserLoading] = useState(false);\n const [isSessionLoading, setIsSessionLoading] = useState(false);\n\n // if oidc config is enabled, we attempt to finish the login, so we start as loading\n const [isOidcLoading, setIsOidcLoading] = useState(!!oidcConfig);\n const isOidcFinishedLogin = useRef(false);\n\n const sdk = useSdk({\n projectId,\n baseUrl,\n persistTokens,\n autoRefresh,\n sessionTokenViaCookie,\n hooks,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n getExternalToken,\n customStorage,\n });\n\n useEffect(() => {\n if (sdk) {\n const unsubscribeSessionToken = sdk.onSessionTokenChange(setSession);\n const unsubscribeUser = sdk.onUserChange(setUser);\n const unsubscribeIsAuthenticated =\n sdk.onIsAuthenticatedChange(setIsAuthenticated);\n const unsubscribeClaims = sdk.onClaimsChange(setClaims);\n\n return () => {\n unsubscribeSessionToken();\n unsubscribeUser();\n unsubscribeIsAuthenticated();\n unsubscribeClaims();\n };\n }\n return undefined;\n }, [sdk]);\n\n const isSessionFetched = useRef(false);\n const isUserFetched = useRef(false);\n\n // if oidc config is enabled, and we have oidc params in the url\n // we will finish the login (this should run only once)\n useEffect(() => {\n if (sdk && oidcConfig && !isOidcFinishedLogin.current) {\n isOidcFinishedLogin.current = true;\n sdk.oidc.finishLoginIfNeed().finally(() => {\n setIsOidcLoading(false);\n // We want that the session will fetched only once\n isSessionFetched.current = true;\n });\n }\n }, []);\n\n const fetchSession = useCallback(() => {\n // We want that the session will fetched only once\n if (isSessionFetched.current) return;\n isSessionFetched.current = true;\n\n setIsSessionLoading(true);\n withValidation(sdk?.refresh)(undefined, true).then(() => {\n setIsSessionLoading(false);\n });\n }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetched.current) return;\n isUserFetched.current = true;\n\n setIsUserLoading(true);\n withValidation(sdk.me)().then(() => {\n setIsUserLoading(false);\n });\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetched: isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched: isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n }),\n [\n fetchUser,\n user,\n isUserLoading,\n isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n ],\n );\n return <Context.Provider value={value}>{children}</Context.Provider>;\n};\n\nexport default AuthProvider;\n"],"names":["projectId","baseUrl","baseStaticUrl","baseCdnUrl","sessionTokenViaCookie","hooks","persistTokens","autoRefresh","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","getExternalToken","customStorage","children","user","setUser","useState","session","setSession","claims","setClaims","isAuthenticated","setIsAuthenticated","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","isOidcLoading","setIsOidcLoading","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","unsubscribeClaims","onClaimsChange","isSessionFetched","isUserFetched","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","withValidation","refresh","undefined","then","fetchUser","me","value","useMemo","React","default","createElement","Context","Provider"],"mappings":"kQAoD6C,EAC3CA,YACAC,UAAU,GACVC,gBAAgB,GAChBC,aAAa,GACbC,yBAAwB,EACxBC,QACAC,iBAAgB,EAChBC,eAAc,EACdC,aACAC,8BAA6B,EAC7BC,wCAAuC,EACvCC,oBAAoB,GACpBC,mBACAC,gBACAC,eAEA,MAAOC,EAAMC,GAAWC,EAAQA,YACzBC,EAASC,GAAcF,EAAQA,YAC/BG,EAAQC,GAAaJ,EAAQA,YAC7BK,EAAiBC,GAAsBN,EAAQA,UAAC,IAEhDO,EAAeC,GAAoBR,EAAQA,UAAC,IAC5CS,EAAkBC,GAAuBV,EAAQA,UAAC,IAGlDW,EAAeC,GAAoBZ,EAAAA,WAAWT,GAC/CsB,EAAsBC,UAAO,GAE7BC,EAAMC,EAAAA,QAAO,CACjBjC,YACAC,UACAK,gBACAC,cACAH,wBACAC,QACAG,aACAC,6BACAC,uCACAC,oBACAC,mBACAC,kBAGFqB,EAAAA,WAAU,KACR,GAAIF,EAAK,CACP,MAAMG,EAA0BH,EAAII,qBAAqBjB,GACnDkB,EAAkBL,EAAIM,aAAatB,GACnCuB,EACJP,EAAIQ,wBAAwBjB,GACxBkB,EAAoBT,EAAIU,eAAerB,GAE7C,MAAO,KACLc,IACAE,IACAE,IACAE,GAAmB,CAEtB,CACe,GACf,CAACT,IAEJ,MAAMW,EAAmBZ,UAAO,GAC1Ba,EAAgBb,UAAO,GAI7BG,EAAAA,WAAU,KACJF,GAAOxB,IAAesB,EAAoBe,UAC5Cf,EAAoBe,SAAU,EAC9Bb,EAAIc,KAAKC,oBAAoBC,SAAQ,KACnCnB,GAAiB,GAEjBc,EAAiBE,SAAU,CAAI,IAElC,GACA,IAEH,MAAMI,EAAeC,EAAAA,aAAY,
|
|
1
|
+
{"version":3,"file":"AuthProvider.js","sources":["../../../../src/components/AuthProvider/AuthProvider.tsx"],"sourcesContent":["import React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { CookieConfig, OidcConfig } from '@descope/web-js-sdk';\nimport { Claims } from '@descope/core-js-sdk';\nimport { CustomStorage } from '@descope/web-component';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { isDescopeBridge, withValidation } from '../../utils';\nimport useSdk from './useSdk';\n\ntype Hooks = Parameters<typeof useSdk>[0]['hooks'];\n\ninterface IAuthProviderProps {\n projectId: string;\n baseUrl?: string;\n // allows to override the base URL that is used to fetch static files\n baseStaticUrl?: string;\n // allows to override the base URL that is used to fetch external script files\n baseCdnUrl?: string;\n // Default is true. If true, tokens will be stored on local storage and can accessed with getToken function\n persistTokens?: boolean;\n // Default is true. If true, the SDK will automatically refresh the session token when it is about to expire\n autoRefresh?: boolean;\n // If true, session token (jwt) will be stored on cookie. Otherwise, the session token will be\n // stored on local storage and can accessed with getSessionToken function\n // Use this option if session token will stay small (less than 1k)\n // NOTE: Session token can grow, especially in cases of using authorization, or adding custom claims\n sessionTokenViaCookie?: CookieConfig;\n hooks?: Hooks;\n // If truthy he SDK refresh and logout functions will use the OIDC client\n // Accepts boolean or OIDC configuration\n oidcConfig?: OidcConfig;\n // Default is true. If true, last authenticated user will be stored on local storage and can accessed with getUser function\n storeLastAuthenticatedUser?: boolean;\n // If true, last authenticated user will not be removed after logout\n keepLastAuthenticatedUserAfterLogout?: boolean;\n // Use this option if the authentication is done via cookie, and configured with a different name\n // Currently, this is done using Descope Flows\n refreshCookieName?: string;\n // Function to get external token, for seamless migration from external system\n getExternalToken?: () => Promise<string>;\n // Custom storage object for authentication related data\n customStorage?: CustomStorage;\n children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n baseCdnUrl = '',\n sessionTokenViaCookie = false,\n hooks = undefined,\n persistTokens = true,\n autoRefresh = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n getExternalToken = undefined,\n customStorage = undefined,\n children = undefined,\n}) => {\n const [user, setUser] = useState<User>();\n const [session, setSession] = useState<string>();\n const [claims, setClaims] = useState<Claims>();\n const [isAuthenticated, setIsAuthenticated] = useState(false);\n\n const [isUserLoading, setIsUserLoading] = useState(false);\n const [isSessionLoading, setIsSessionLoading] = useState(false);\n\n // if oidc config is enabled, we attempt to finish the login, so we start as loading\n const [isOidcLoading, setIsOidcLoading] = useState(!!oidcConfig);\n const isOidcFinishedLogin = useRef(false);\n\n const sdk = useSdk({\n projectId,\n baseUrl,\n persistTokens,\n autoRefresh,\n sessionTokenViaCookie,\n hooks,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n getExternalToken,\n customStorage,\n });\n\n useEffect(() => {\n if (sdk) {\n const unsubscribeSessionToken = sdk.onSessionTokenChange(setSession);\n const unsubscribeUser = sdk.onUserChange(setUser);\n const unsubscribeIsAuthenticated =\n sdk.onIsAuthenticatedChange(setIsAuthenticated);\n const unsubscribeClaims = sdk.onClaimsChange(setClaims);\n\n return () => {\n unsubscribeSessionToken();\n unsubscribeUser();\n unsubscribeIsAuthenticated();\n unsubscribeClaims();\n };\n }\n return undefined;\n }, [sdk]);\n\n const isSessionFetched = useRef(false);\n const isUserFetched = useRef(false);\n\n // if oidc config is enabled, and we have oidc params in the url\n // we will finish the login (this should run only once)\n useEffect(() => {\n if (sdk && oidcConfig && !isOidcFinishedLogin.current) {\n isOidcFinishedLogin.current = true;\n sdk.oidc.finishLoginIfNeed().finally(() => {\n setIsOidcLoading(false);\n // We want that the session will fetched only once\n isSessionFetched.current = true;\n });\n }\n }, []);\n\n const fetchSession = useCallback(() => {\n // Don't load the session in native flows\n if (isDescopeBridge()) return;\n\n // We want that the session will fetched only once\n if (isSessionFetched.current) return;\n isSessionFetched.current = true;\n\n setIsSessionLoading(true);\n withValidation(sdk?.refresh)(undefined, true).then(() => {\n setIsSessionLoading(false);\n });\n }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetched.current) return;\n isUserFetched.current = true;\n\n setIsUserLoading(true);\n withValidation(sdk.me)().then(() => {\n setIsUserLoading(false);\n });\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetched: isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched: isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n }),\n [\n fetchUser,\n user,\n isUserLoading,\n isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n ],\n );\n return <Context.Provider value={value}>{children}</Context.Provider>;\n};\n\nexport default AuthProvider;\n"],"names":["projectId","baseUrl","baseStaticUrl","baseCdnUrl","sessionTokenViaCookie","hooks","persistTokens","autoRefresh","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","getExternalToken","customStorage","children","user","setUser","useState","session","setSession","claims","setClaims","isAuthenticated","setIsAuthenticated","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","isOidcLoading","setIsOidcLoading","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","unsubscribeClaims","onClaimsChange","isSessionFetched","isUserFetched","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","isDescopeBridge","withValidation","refresh","undefined","then","fetchUser","me","value","useMemo","React","default","createElement","Context","Provider"],"mappings":"kQAoD6C,EAC3CA,YACAC,UAAU,GACVC,gBAAgB,GAChBC,aAAa,GACbC,yBAAwB,EACxBC,QACAC,iBAAgB,EAChBC,eAAc,EACdC,aACAC,8BAA6B,EAC7BC,wCAAuC,EACvCC,oBAAoB,GACpBC,mBACAC,gBACAC,eAEA,MAAOC,EAAMC,GAAWC,EAAQA,YACzBC,EAASC,GAAcF,EAAQA,YAC/BG,EAAQC,GAAaJ,EAAQA,YAC7BK,EAAiBC,GAAsBN,EAAQA,UAAC,IAEhDO,EAAeC,GAAoBR,EAAQA,UAAC,IAC5CS,EAAkBC,GAAuBV,EAAQA,UAAC,IAGlDW,EAAeC,GAAoBZ,EAAAA,WAAWT,GAC/CsB,EAAsBC,UAAO,GAE7BC,EAAMC,EAAAA,QAAO,CACjBjC,YACAC,UACAK,gBACAC,cACAH,wBACAC,QACAG,aACAC,6BACAC,uCACAC,oBACAC,mBACAC,kBAGFqB,EAAAA,WAAU,KACR,GAAIF,EAAK,CACP,MAAMG,EAA0BH,EAAII,qBAAqBjB,GACnDkB,EAAkBL,EAAIM,aAAatB,GACnCuB,EACJP,EAAIQ,wBAAwBjB,GACxBkB,EAAoBT,EAAIU,eAAerB,GAE7C,MAAO,KACLc,IACAE,IACAE,IACAE,GAAmB,CAEtB,CACe,GACf,CAACT,IAEJ,MAAMW,EAAmBZ,UAAO,GAC1Ba,EAAgBb,UAAO,GAI7BG,EAAAA,WAAU,KACJF,GAAOxB,IAAesB,EAAoBe,UAC5Cf,EAAoBe,SAAU,EAC9Bb,EAAIc,KAAKC,oBAAoBC,SAAQ,KACnCnB,GAAiB,GAEjBc,EAAiBE,SAAU,CAAI,IAElC,GACA,IAEH,MAAMI,EAAeC,EAAAA,aAAY,KAE3BC,qBAGAR,EAAiBE,UACrBF,EAAiBE,SAAU,EAE3BlB,GAAoB,GACpByB,EAAAA,eAAepB,aAAA,EAAAA,EAAKqB,QAApBD,MAA6BE,GAAW,GAAMC,MAAK,KACjD5B,GAAoB,EAAM,IAC1B,GACD,CAACK,IAEEwB,EAAYN,EAAAA,aAAY,KAExBN,EAAcC,UAClBD,EAAcC,SAAU,EAExBpB,GAAiB,GACjB2B,EAAAA,eAAepB,EAAIyB,GAAnBL,GAAyBG,MAAK,KAC5B9B,GAAiB,EAAM,IACvB,GACD,CAACO,IAEE0B,EAAQC,EAAAA,SACZ,KAAO,CACLH,YACAzC,OACAS,gBACAoB,cAAeA,EAAcC,QAC7BI,eACA/B,UACAI,kBACAI,mBACAE,gBACAe,iBAAkBA,EAAiBE,QACnC7C,YACAC,UACAC,gBACAC,aACAM,6BACAC,uCACAC,oBACAE,gBACAG,UACAG,aACAI,qBACAH,SACAY,SAEF,CACEwB,EACAzC,EACAS,EACAoB,EAAcC,QACdI,EACA/B,EACAI,EACAI,EACAE,EACAe,EAAiBE,QACjB7C,EACAC,EACAC,EACAC,EACAO,EACAC,EACAE,EACAG,EACAG,EACAI,EACAH,EACAY,IAGJ,OAAO4B,EAAAC,QAAAC,cAACC,UAAQC,SAAQ,CAACN,MAAOA,GAAQ5C,EAA4B"}
|
package/dist/cjs/constants.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const e="undefined"!=typeof window;exports.IS_BROWSER=e,exports.baseHeaders={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.
|
|
1
|
+
"use strict";const e="undefined"!=typeof window;exports.IS_BROWSER=e,exports.baseHeaders={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.24.0"};
|
|
2
2
|
//# sourceMappingURL=constants.js.map
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";exports.withValidation=
|
|
1
|
+
"use strict";exports.isDescopeBridge=()=>"undefined"!=typeof window&&!!window.descopeBridge,exports.withValidation=e=>(...r)=>{if(!e)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return e(...r)},exports.wrapInTry=e=>(...r)=>{let o;try{o=e(...r)}catch(e){console.error(e)}return o};
|
|
2
2
|
//# sourceMappingURL=utils.js.map
|
package/dist/cjs/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["/**\n * Wrap a function with a validation that it exists\n * @param fn The function to wrap with the validation\n * @throws if function does not exist, an error with the relevant message will be thrown\n */\nexport const withValidation =\n <T extends Array<any>, U>(fn: (...args: T) => U) =>\n (...args: T): U => {\n if (!fn) {\n throw Error(\n `You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`,\n );\n }\n return fn(...args);\n };\n\nexport const wrapInTry =\n <T extends Array<any>, U>(fn: (...args: T) => U) =>\n (...args: T): U => {\n let res: U;\n try {\n res = fn(...args);\n } catch (err) {\n console.error(err); // eslint-disable-line no-console\n }\n return res;\n };\n"],"names":["fn","args","Error","res","err","console","error"],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["/**\n * Wrap a function with a validation that it exists\n * @param fn The function to wrap with the validation\n * @throws if function does not exist, an error with the relevant message will be thrown\n */\nexport const withValidation =\n <T extends Array<any>, U>(fn: (...args: T) => U) =>\n (...args: T): U => {\n if (!fn) {\n throw Error(\n `You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`,\n );\n }\n return fn(...args);\n };\n\nexport const wrapInTry =\n <T extends Array<any>, U>(fn: (...args: T) => U) =>\n (...args: T): U => {\n let res: U;\n try {\n res = fn(...args);\n } catch (err) {\n console.error(err); // eslint-disable-line no-console\n }\n return res;\n };\n\n// Detect if running in a native flow (e.g., mobile app with Descope bridge in a webview)\nexport const isDescopeBridge = () =>\n typeof window !== 'undefined' && !!window['descopeBridge'];\n"],"names":["window","fn","args","Error","res","err","console","error"],"mappings":"qCA6B+B,IACX,oBAAXA,UAA4BA,OAAsB,qCAxB/BC,GAC1B,IAAIC,KACF,IAAKD,EACH,MAAME,MACJ,0HAGJ,OAAOF,KAAMC,EAAK,oBAIMD,GAC1B,IAAIC,KACF,IAAIE,EACJ,IACEA,EAAMH,KAAMC,EACb,CAAC,MAAOG,GACPC,QAAQC,MAAMF,EACf,CACD,OAAOD,CAAG"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e,{useState as t,useRef as s,useEffect as r,useCallback as o,useMemo as n}from"react";import i from"../../hooks/Context.js";import{withValidation as
|
|
1
|
+
import e,{useState as t,useRef as s,useEffect as r,useCallback as o,useMemo as n}from"react";import i from"../../hooks/Context.js";import{isDescopeBridge as a,withValidation as c}from"../../utils.js";import u from"./useSdk.js";const d=({projectId:d,baseUrl:h="",baseStaticUrl:f="",baseCdnUrl:k="",sessionTokenViaCookie:l=!1,hooks:g,persistTokens:m=!0,autoRefresh:U=!0,oidcConfig:C,storeLastAuthenticatedUser:p=!0,keepLastAuthenticatedUserAfterLogout:L=!1,refreshCookieName:A="",getExternalToken:S,customStorage:b,children:T})=>{const[j,I]=t(),[v,x]=t(),[N,E]=t(),[F,R]=t(!1),[V,y]=t(!1),[O,P]=t(!1),[q,w]=t(!!C),z=s(!1),B=u({projectId:d,baseUrl:h,persistTokens:m,autoRefresh:U,sessionTokenViaCookie:l,hooks:g,oidcConfig:C,storeLastAuthenticatedUser:p,keepLastAuthenticatedUserAfterLogout:L,refreshCookieName:A,getExternalToken:S,customStorage:b});r((()=>{if(B){const e=B.onSessionTokenChange(x),t=B.onUserChange(I),s=B.onIsAuthenticatedChange(R),r=B.onClaimsChange(E);return()=>{e(),t(),s(),r()}}}),[B]);const D=s(!1),G=s(!1);r((()=>{B&&C&&!z.current&&(z.current=!0,B.oidc.finishLoginIfNeed().finally((()=>{w(!1),D.current=!0})))}),[]);const H=o((()=>{a()||D.current||(D.current=!0,P(!0),c(null==B?void 0:B.refresh)(void 0,!0).then((()=>{P(!1)})))}),[B]),J=o((()=>{G.current||(G.current=!0,y(!0),c(B.me)().then((()=>{y(!1)})))}),[B]),K=n((()=>({fetchUser:J,user:j,isUserLoading:V,isUserFetched:G.current,fetchSession:H,session:v,isAuthenticated:F,isSessionLoading:O,isOidcLoading:q,isSessionFetched:D.current,projectId:d,baseUrl:h,baseStaticUrl:f,baseCdnUrl:k,storeLastAuthenticatedUser:p,keepLastAuthenticatedUserAfterLogout:L,refreshCookieName:A,customStorage:b,setUser:I,setSession:x,setIsAuthenticated:R,claims:N,sdk:B})),[J,j,V,G.current,H,v,F,O,q,D.current,d,h,f,k,L,A,b,I,x,R,N,B]);return e.createElement(i.Provider,{value:K},T)};export{d as default};
|
|
2
2
|
//# sourceMappingURL=AuthProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthProvider.js","sources":["../../../../src/components/AuthProvider/AuthProvider.tsx"],"sourcesContent":["import React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { CookieConfig, OidcConfig } from '@descope/web-js-sdk';\nimport { Claims } from '@descope/core-js-sdk';\nimport { CustomStorage } from '@descope/web-component';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { withValidation } from '../../utils';\nimport useSdk from './useSdk';\n\ntype Hooks = Parameters<typeof useSdk>[0]['hooks'];\n\ninterface IAuthProviderProps {\n projectId: string;\n baseUrl?: string;\n // allows to override the base URL that is used to fetch static files\n baseStaticUrl?: string;\n // allows to override the base URL that is used to fetch external script files\n baseCdnUrl?: string;\n // Default is true. If true, tokens will be stored on local storage and can accessed with getToken function\n persistTokens?: boolean;\n // Default is true. If true, the SDK will automatically refresh the session token when it is about to expire\n autoRefresh?: boolean;\n // If true, session token (jwt) will be stored on cookie. Otherwise, the session token will be\n // stored on local storage and can accessed with getSessionToken function\n // Use this option if session token will stay small (less than 1k)\n // NOTE: Session token can grow, especially in cases of using authorization, or adding custom claims\n sessionTokenViaCookie?: CookieConfig;\n hooks?: Hooks;\n // If truthy he SDK refresh and logout functions will use the OIDC client\n // Accepts boolean or OIDC configuration\n oidcConfig?: OidcConfig;\n // Default is true. If true, last authenticated user will be stored on local storage and can accessed with getUser function\n storeLastAuthenticatedUser?: boolean;\n // If true, last authenticated user will not be removed after logout\n keepLastAuthenticatedUserAfterLogout?: boolean;\n // Use this option if the authentication is done via cookie, and configured with a different name\n // Currently, this is done using Descope Flows\n refreshCookieName?: string;\n // Function to get external token, for seamless migration from external system\n getExternalToken?: () => Promise<string>;\n // Custom storage object for authentication related data\n customStorage?: CustomStorage;\n children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n baseCdnUrl = '',\n sessionTokenViaCookie = false,\n hooks = undefined,\n persistTokens = true,\n autoRefresh = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n getExternalToken = undefined,\n customStorage = undefined,\n children = undefined,\n}) => {\n const [user, setUser] = useState<User>();\n const [session, setSession] = useState<string>();\n const [claims, setClaims] = useState<Claims>();\n const [isAuthenticated, setIsAuthenticated] = useState(false);\n\n const [isUserLoading, setIsUserLoading] = useState(false);\n const [isSessionLoading, setIsSessionLoading] = useState(false);\n\n // if oidc config is enabled, we attempt to finish the login, so we start as loading\n const [isOidcLoading, setIsOidcLoading] = useState(!!oidcConfig);\n const isOidcFinishedLogin = useRef(false);\n\n const sdk = useSdk({\n projectId,\n baseUrl,\n persistTokens,\n autoRefresh,\n sessionTokenViaCookie,\n hooks,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n getExternalToken,\n customStorage,\n });\n\n useEffect(() => {\n if (sdk) {\n const unsubscribeSessionToken = sdk.onSessionTokenChange(setSession);\n const unsubscribeUser = sdk.onUserChange(setUser);\n const unsubscribeIsAuthenticated =\n sdk.onIsAuthenticatedChange(setIsAuthenticated);\n const unsubscribeClaims = sdk.onClaimsChange(setClaims);\n\n return () => {\n unsubscribeSessionToken();\n unsubscribeUser();\n unsubscribeIsAuthenticated();\n unsubscribeClaims();\n };\n }\n return undefined;\n }, [sdk]);\n\n const isSessionFetched = useRef(false);\n const isUserFetched = useRef(false);\n\n // if oidc config is enabled, and we have oidc params in the url\n // we will finish the login (this should run only once)\n useEffect(() => {\n if (sdk && oidcConfig && !isOidcFinishedLogin.current) {\n isOidcFinishedLogin.current = true;\n sdk.oidc.finishLoginIfNeed().finally(() => {\n setIsOidcLoading(false);\n // We want that the session will fetched only once\n isSessionFetched.current = true;\n });\n }\n }, []);\n\n const fetchSession = useCallback(() => {\n // We want that the session will fetched only once\n if (isSessionFetched.current) return;\n isSessionFetched.current = true;\n\n setIsSessionLoading(true);\n withValidation(sdk?.refresh)(undefined, true).then(() => {\n setIsSessionLoading(false);\n });\n }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetched.current) return;\n isUserFetched.current = true;\n\n setIsUserLoading(true);\n withValidation(sdk.me)().then(() => {\n setIsUserLoading(false);\n });\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetched: isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched: isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n }),\n [\n fetchUser,\n user,\n isUserLoading,\n isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n ],\n );\n return <Context.Provider value={value}>{children}</Context.Provider>;\n};\n\nexport default AuthProvider;\n"],"names":["AuthProvider","projectId","baseUrl","baseStaticUrl","baseCdnUrl","sessionTokenViaCookie","hooks","persistTokens","autoRefresh","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","getExternalToken","customStorage","children","user","setUser","useState","session","setSession","claims","setClaims","isAuthenticated","setIsAuthenticated","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","isOidcLoading","setIsOidcLoading","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","unsubscribeClaims","onClaimsChange","isSessionFetched","isUserFetched","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","withValidation","refresh","undefined","then","fetchUser","me","value","useMemo","React","createElement","Context","Provider"],"mappings":"
|
|
1
|
+
{"version":3,"file":"AuthProvider.js","sources":["../../../../src/components/AuthProvider/AuthProvider.tsx"],"sourcesContent":["import React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { CookieConfig, OidcConfig } from '@descope/web-js-sdk';\nimport { Claims } from '@descope/core-js-sdk';\nimport { CustomStorage } from '@descope/web-component';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { isDescopeBridge, withValidation } from '../../utils';\nimport useSdk from './useSdk';\n\ntype Hooks = Parameters<typeof useSdk>[0]['hooks'];\n\ninterface IAuthProviderProps {\n projectId: string;\n baseUrl?: string;\n // allows to override the base URL that is used to fetch static files\n baseStaticUrl?: string;\n // allows to override the base URL that is used to fetch external script files\n baseCdnUrl?: string;\n // Default is true. If true, tokens will be stored on local storage and can accessed with getToken function\n persistTokens?: boolean;\n // Default is true. If true, the SDK will automatically refresh the session token when it is about to expire\n autoRefresh?: boolean;\n // If true, session token (jwt) will be stored on cookie. Otherwise, the session token will be\n // stored on local storage and can accessed with getSessionToken function\n // Use this option if session token will stay small (less than 1k)\n // NOTE: Session token can grow, especially in cases of using authorization, or adding custom claims\n sessionTokenViaCookie?: CookieConfig;\n hooks?: Hooks;\n // If truthy he SDK refresh and logout functions will use the OIDC client\n // Accepts boolean or OIDC configuration\n oidcConfig?: OidcConfig;\n // Default is true. If true, last authenticated user will be stored on local storage and can accessed with getUser function\n storeLastAuthenticatedUser?: boolean;\n // If true, last authenticated user will not be removed after logout\n keepLastAuthenticatedUserAfterLogout?: boolean;\n // Use this option if the authentication is done via cookie, and configured with a different name\n // Currently, this is done using Descope Flows\n refreshCookieName?: string;\n // Function to get external token, for seamless migration from external system\n getExternalToken?: () => Promise<string>;\n // Custom storage object for authentication related data\n customStorage?: CustomStorage;\n children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n baseCdnUrl = '',\n sessionTokenViaCookie = false,\n hooks = undefined,\n persistTokens = true,\n autoRefresh = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n getExternalToken = undefined,\n customStorage = undefined,\n children = undefined,\n}) => {\n const [user, setUser] = useState<User>();\n const [session, setSession] = useState<string>();\n const [claims, setClaims] = useState<Claims>();\n const [isAuthenticated, setIsAuthenticated] = useState(false);\n\n const [isUserLoading, setIsUserLoading] = useState(false);\n const [isSessionLoading, setIsSessionLoading] = useState(false);\n\n // if oidc config is enabled, we attempt to finish the login, so we start as loading\n const [isOidcLoading, setIsOidcLoading] = useState(!!oidcConfig);\n const isOidcFinishedLogin = useRef(false);\n\n const sdk = useSdk({\n projectId,\n baseUrl,\n persistTokens,\n autoRefresh,\n sessionTokenViaCookie,\n hooks,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n getExternalToken,\n customStorage,\n });\n\n useEffect(() => {\n if (sdk) {\n const unsubscribeSessionToken = sdk.onSessionTokenChange(setSession);\n const unsubscribeUser = sdk.onUserChange(setUser);\n const unsubscribeIsAuthenticated =\n sdk.onIsAuthenticatedChange(setIsAuthenticated);\n const unsubscribeClaims = sdk.onClaimsChange(setClaims);\n\n return () => {\n unsubscribeSessionToken();\n unsubscribeUser();\n unsubscribeIsAuthenticated();\n unsubscribeClaims();\n };\n }\n return undefined;\n }, [sdk]);\n\n const isSessionFetched = useRef(false);\n const isUserFetched = useRef(false);\n\n // if oidc config is enabled, and we have oidc params in the url\n // we will finish the login (this should run only once)\n useEffect(() => {\n if (sdk && oidcConfig && !isOidcFinishedLogin.current) {\n isOidcFinishedLogin.current = true;\n sdk.oidc.finishLoginIfNeed().finally(() => {\n setIsOidcLoading(false);\n // We want that the session will fetched only once\n isSessionFetched.current = true;\n });\n }\n }, []);\n\n const fetchSession = useCallback(() => {\n // Don't load the session in native flows\n if (isDescopeBridge()) return;\n\n // We want that the session will fetched only once\n if (isSessionFetched.current) return;\n isSessionFetched.current = true;\n\n setIsSessionLoading(true);\n withValidation(sdk?.refresh)(undefined, true).then(() => {\n setIsSessionLoading(false);\n });\n }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetched.current) return;\n isUserFetched.current = true;\n\n setIsUserLoading(true);\n withValidation(sdk.me)().then(() => {\n setIsUserLoading(false);\n });\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetched: isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched: isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n }),\n [\n fetchUser,\n user,\n isUserLoading,\n isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n ],\n );\n return <Context.Provider value={value}>{children}</Context.Provider>;\n};\n\nexport default AuthProvider;\n"],"names":["AuthProvider","projectId","baseUrl","baseStaticUrl","baseCdnUrl","sessionTokenViaCookie","hooks","persistTokens","autoRefresh","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","getExternalToken","customStorage","children","user","setUser","useState","session","setSession","claims","setClaims","isAuthenticated","setIsAuthenticated","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","isOidcLoading","setIsOidcLoading","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","unsubscribeClaims","onClaimsChange","isSessionFetched","isUserFetched","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","isDescopeBridge","withValidation","refresh","undefined","then","fetchUser","me","value","useMemo","React","createElement","Context","Provider"],"mappings":"mOAoDA,MAAMA,EAAuC,EAC3CC,YACAC,UAAU,GACVC,gBAAgB,GAChBC,aAAa,GACbC,yBAAwB,EACxBC,QACAC,iBAAgB,EAChBC,eAAc,EACdC,aACAC,8BAA6B,EAC7BC,wCAAuC,EACvCC,oBAAoB,GACpBC,mBACAC,gBACAC,eAEA,MAAOC,EAAMC,GAAWC,KACjBC,EAASC,GAAcF,KACvBG,EAAQC,GAAaJ,KACrBK,EAAiBC,GAAsBN,GAAS,IAEhDO,EAAeC,GAAoBR,GAAS,IAC5CS,EAAkBC,GAAuBV,GAAS,IAGlDW,EAAeC,GAAoBZ,IAAWT,GAC/CsB,EAAsBC,GAAO,GAE7BC,EAAMC,EAAO,CACjBjC,YACAC,UACAK,gBACAC,cACAH,wBACAC,QACAG,aACAC,6BACAC,uCACAC,oBACAC,mBACAC,kBAGFqB,GAAU,KACR,GAAIF,EAAK,CACP,MAAMG,EAA0BH,EAAII,qBAAqBjB,GACnDkB,EAAkBL,EAAIM,aAAatB,GACnCuB,EACJP,EAAIQ,wBAAwBjB,GACxBkB,EAAoBT,EAAIU,eAAerB,GAE7C,MAAO,KACLc,IACAE,IACAE,IACAE,GAAmB,CAEtB,CACe,GACf,CAACT,IAEJ,MAAMW,EAAmBZ,GAAO,GAC1Ba,EAAgBb,GAAO,GAI7BG,GAAU,KACJF,GAAOxB,IAAesB,EAAoBe,UAC5Cf,EAAoBe,SAAU,EAC9Bb,EAAIc,KAAKC,oBAAoBC,SAAQ,KACnCnB,GAAiB,GAEjBc,EAAiBE,SAAU,CAAI,IAElC,GACA,IAEH,MAAMI,EAAeC,GAAY,KAE3BC,KAGAR,EAAiBE,UACrBF,EAAiBE,SAAU,EAE3BlB,GAAoB,GACpByB,EAAepB,aAAA,EAAAA,EAAKqB,QAApBD,MAA6BE,GAAW,GAAMC,MAAK,KACjD5B,GAAoB,EAAM,IAC1B,GACD,CAACK,IAEEwB,EAAYN,GAAY,KAExBN,EAAcC,UAClBD,EAAcC,SAAU,EAExBpB,GAAiB,GACjB2B,EAAepB,EAAIyB,GAAnBL,GAAyBG,MAAK,KAC5B9B,GAAiB,EAAM,IACvB,GACD,CAACO,IAEE0B,EAAQC,GACZ,KAAO,CACLH,YACAzC,OACAS,gBACAoB,cAAeA,EAAcC,QAC7BI,eACA/B,UACAI,kBACAI,mBACAE,gBACAe,iBAAkBA,EAAiBE,QACnC7C,YACAC,UACAC,gBACAC,aACAM,6BACAC,uCACAC,oBACAE,gBACAG,UACAG,aACAI,qBACAH,SACAY,SAEF,CACEwB,EACAzC,EACAS,EACAoB,EAAcC,QACdI,EACA/B,EACAI,EACAI,EACAE,EACAe,EAAiBE,QACjB7C,EACAC,EACAC,EACAC,EACAO,EACAC,EACAE,EACAG,EACAG,EACAI,EACAH,EACAY,IAGJ,OAAO4B,EAAAC,cAACC,EAAQC,SAAQ,CAACL,MAAOA,GAAQ5C,EAA4B"}
|
package/dist/esm/constants.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.
|
|
1
|
+
const e={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.24.0"},d="undefined"!=typeof window;export{d as IS_BROWSER,e as baseHeaders};
|
|
2
2
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["declare const BUILD_VERSION: string;\n\nexport const baseHeaders = {\n 'x-descope-sdk-name': 'react',\n 'x-descope-sdk-version': BUILD_VERSION,\n};\n\n// This sdk can be used in SSR apps\nexport const IS_BROWSER = typeof window !== 'undefined';\n"],"names":["baseHeaders","IS_BROWSER","window"],"mappings":"AAEa,MAAAA,EAAc,CACzB,qBAAsB,QACtB,wBAAyB,
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["declare const BUILD_VERSION: string;\n\nexport const baseHeaders = {\n 'x-descope-sdk-name': 'react',\n 'x-descope-sdk-version': BUILD_VERSION,\n};\n\n// This sdk can be used in SSR apps\nexport const IS_BROWSER = typeof window !== 'undefined';\n"],"names":["baseHeaders","IS_BROWSER","window"],"mappings":"AAEa,MAAAA,EAAc,CACzB,qBAAsB,QACtB,wBAAyB,UAIdC,EAA+B,oBAAXC"}
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const
|
|
1
|
+
const o=o=>(...e)=>{if(!o)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return o(...e)},e=o=>(...e)=>{let r;try{r=o(...e)}catch(o){console.error(o)}return r},r=()=>"undefined"!=typeof window&&!!window.descopeBridge;export{r as isDescopeBridge,o as withValidation,e as wrapInTry};
|
|
2
2
|
//# sourceMappingURL=utils.js.map
|
package/dist/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["/**\n * Wrap a function with a validation that it exists\n * @param fn The function to wrap with the validation\n * @throws if function does not exist, an error with the relevant message will be thrown\n */\nexport const withValidation =\n <T extends Array<any>, U>(fn: (...args: T) => U) =>\n (...args: T): U => {\n if (!fn) {\n throw Error(\n `You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`,\n );\n }\n return fn(...args);\n };\n\nexport const wrapInTry =\n <T extends Array<any>, U>(fn: (...args: T) => U) =>\n (...args: T): U => {\n let res: U;\n try {\n res = fn(...args);\n } catch (err) {\n console.error(err); // eslint-disable-line no-console\n }\n return res;\n };\n"],"names":["withValidation","fn","args","Error","wrapInTry","res","err","console","error"],"mappings":"AAKO,MAAMA,EACeC,GAC1B,IAAIC,KACF,IAAKD,EACH,MAAME,MACJ,0HAGJ,OAAOF,KAAMC,EAAK,EAGTE,EACeH,GAC1B,IAAIC,KACF,IAAIG,EACJ,IACEA,EAAMJ,KAAMC,EACb,CAAC,MAAOI,GACPC,QAAQC,MAAMF,EACf,CACD,OAAOD,CAAG"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["/**\n * Wrap a function with a validation that it exists\n * @param fn The function to wrap with the validation\n * @throws if function does not exist, an error with the relevant message will be thrown\n */\nexport const withValidation =\n <T extends Array<any>, U>(fn: (...args: T) => U) =>\n (...args: T): U => {\n if (!fn) {\n throw Error(\n `You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`,\n );\n }\n return fn(...args);\n };\n\nexport const wrapInTry =\n <T extends Array<any>, U>(fn: (...args: T) => U) =>\n (...args: T): U => {\n let res: U;\n try {\n res = fn(...args);\n } catch (err) {\n console.error(err); // eslint-disable-line no-console\n }\n return res;\n };\n\n// Detect if running in a native flow (e.g., mobile app with Descope bridge in a webview)\nexport const isDescopeBridge = () =>\n typeof window !== 'undefined' && !!window['descopeBridge'];\n"],"names":["withValidation","fn","args","Error","wrapInTry","res","err","console","error","isDescopeBridge","window"],"mappings":"AAKO,MAAMA,EACeC,GAC1B,IAAIC,KACF,IAAKD,EACH,MAAME,MACJ,0HAGJ,OAAOF,KAAMC,EAAK,EAGTE,EACeH,GAC1B,IAAIC,KACF,IAAIG,EACJ,IACEA,EAAMJ,KAAMC,EACb,CAAC,MAAOI,GACPC,QAAQC,MAAMF,EACf,CACD,OAAOD,CAAG,EAIDI,EAAkB,IACX,oBAAXC,UAA4BA,OAAsB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -117,10 +117,10 @@ declare const createSdkWrapper: <P extends {
|
|
|
117
117
|
}, "loginId" | "name">;
|
|
118
118
|
}, conditionInteractionId?: string, interactionId?: string, componentsVersion?: string, flowVersions?: Record<string, number>, input?: {
|
|
119
119
|
[x: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any[])[])[])[])[])[])[])[])[])[])[];
|
|
120
|
-
}) => Promise<_1.SdkResponse<_1.FlowResponse>>;
|
|
120
|
+
}, isCustomScreen?: any) => Promise<_1.SdkResponse<_1.FlowResponse>>;
|
|
121
121
|
next: (executionId: string, stepId: string, interactionId: string, version?: number, componentsVersion?: string, input?: {
|
|
122
122
|
[x: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any[])[])[])[])[])[])[])[])[])[])[];
|
|
123
|
-
}) => Promise<_1.SdkResponse<_1.FlowResponse>>;
|
|
123
|
+
}, isCustomScreen?: any) => Promise<_1.SdkResponse<_1.FlowResponse>>;
|
|
124
124
|
};
|
|
125
125
|
webauthn: {
|
|
126
126
|
signUp: ((identifier: string, name: string, passkeyOptions?: _1.PasskeyOptions) => Promise<_1.SdkResponse<_1.JWTResponse>>) & {
|
|
@@ -763,10 +763,10 @@ declare const createSdkWrapper: <P extends {
|
|
|
763
763
|
}, "loginId" | "name">;
|
|
764
764
|
}, conditionInteractionId?: string, interactionId?: string, componentsVersion?: string, flowVersions?: Record<string, number>, input?: {
|
|
765
765
|
[x: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any[])[])[])[])[])[])[])[])[])[])[];
|
|
766
|
-
}) => Promise<_1.SdkResponse<_1.FlowResponse>>;
|
|
766
|
+
}, isCustomScreen?: any) => Promise<_1.SdkResponse<_1.FlowResponse>>;
|
|
767
767
|
next: (executionId: string, stepId: string, interactionId: string, version?: number, componentsVersion?: string, input?: {
|
|
768
768
|
[x: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any[])[])[])[])[])[])[])[])[])[])[];
|
|
769
|
-
}) => Promise<_1.SdkResponse<_1.FlowResponse>>;
|
|
769
|
+
}, isCustomScreen?: any) => Promise<_1.SdkResponse<_1.FlowResponse>>;
|
|
770
770
|
};
|
|
771
771
|
webauthn: {
|
|
772
772
|
signUp: ((identifier: string, name: string, passkeyOptions?: _1.PasskeyOptions) => Promise<_1.SdkResponse<_1.JWTResponse>>) & {
|
|
@@ -1409,10 +1409,10 @@ declare const createSdkWrapper: <P extends {
|
|
|
1409
1409
|
}, "loginId" | "name">;
|
|
1410
1410
|
}, conditionInteractionId?: string, interactionId?: string, componentsVersion?: string, flowVersions?: Record<string, number>, input?: {
|
|
1411
1411
|
[x: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any[])[])[])[])[])[])[])[])[])[])[];
|
|
1412
|
-
}) => Promise<_1.SdkResponse<_1.FlowResponse>>;
|
|
1412
|
+
}, isCustomScreen?: any) => Promise<_1.SdkResponse<_1.FlowResponse>>;
|
|
1413
1413
|
next: (executionId: string, stepId: string, interactionId: string, version?: number, componentsVersion?: string, input?: {
|
|
1414
1414
|
[x: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any[])[])[])[])[])[])[])[])[])[])[];
|
|
1415
|
-
}) => Promise<_1.SdkResponse<_1.FlowResponse>>;
|
|
1415
|
+
}, isCustomScreen?: any) => Promise<_1.SdkResponse<_1.FlowResponse>>;
|
|
1416
1416
|
};
|
|
1417
1417
|
webauthn: {
|
|
1418
1418
|
signUp: ((identifier: string, name: string, passkeyOptions?: _1.PasskeyOptions) => Promise<_1.SdkResponse<_1.JWTResponse>>) & {
|