UNPKG

@frank-auth/react

Version:

Flexible and customizable React UI components for Frank Authentication

3 lines (2 loc) 5.64 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),g=require("../provider/config-provider.cjs"),d=require("./use-auth.cjs");function r(){const e=g.useConfig(),{activeOrganization:n}=d.useAuth(),a=o.useCallback(i=>e.features[i],[e.features]),s=o.useCallback(i=>{if(!e.features[i])throw new Error(`Feature ${i} is not enabled`)},[e.features]),{isConfigValid:t,configErrors:u}=o.useMemo(()=>{const i=[];if(e.publishableKey||i.push("Publishable key is required"),e.userType||i.push("User type is required"),e.publishableKey&&!/^pk_(test|live)_[a-zA-Z0-9_]+$/.test(e.publishableKey)&&i.push("Invalid publishable key format"),e.apiUrl)try{new URL(e.apiUrl)}catch{i.push("Invalid API URL format")}return e.userType&&!["internal","external","end_user"].includes(e.userType)&&i.push("Invalid user type"),{isConfigValid:i.length===0,configErrors:i}},[e.publishableKey,e.userType,e.apiUrl]),c=o.useMemo(()=>!!e.organizationConfig,[e.organizationConfig]),l=o.useMemo(()=>!!(e.organizationSettings?.branding?.logoUrl||e.organizationSettings?.branding?.primaryColor||e.organizationSettings?.branding?.customCss),[e.organizationSettings]);return{config:e.config,publishableKey:e.publishableKey,apiUrl:e.apiUrl,userType:e.userType,debug:e.debug,titleAlignment:e.config?.appearance?.titleAlignment??"left",theme:e.theme,appearance:e.appearance,localization:e.localization,components:e.components,linksPath:e.linksPath,organization:e.organizationConfig,organizationSettings:e.organizationSettings,features:e.features,updateConfig:e.updateConfig,setTheme:e.setTheme,setAppearance:e.setAppearance,setLocale:e.setLocale,resetToDefaults:e.resetToDefaults,hasFeature:a,requireFeature:s,isConfigValid:t,configErrors:u,isLoaded:e.isLoaded,isMultiTenant:c,isCustomBranded:l}}function p(){const{features:e,hasFeature:n,requireFeature:a}=r();return{features:e,hasFeature:n,requireFeature:a,canSignUp:n("signUp"),canSignIn:n("signIn"),canResetPassword:n("passwordReset"),hasMFA:n("mfa"),hasPasskeys:n("passkeys"),hasOAuth:n("oauth"),hasMagicLink:n("magicLink"),hasSSO:n("sso"),hasOrganizationManagement:n("organizationManagement"),hasUserProfile:n("userProfile"),hasSessionManagement:n("sessionManagement")}}function f(){const{theme:e,setTheme:n,appearance:a,setAppearance:s}=r();return{theme:e,appearance:a,setTheme:n,setAppearance:s,mode:e.mode,colors:e.colors,typography:e.typography,spacing:e.spacing,borderRadius:e.borderRadius,shadows:e.shadows,layout:a.layout,components:a.components,branding:a.branding,setMode:t=>n({mode:t}),setPrimaryColor:t=>n({colors:{...e.colors,primary:{...e.colors.primary,DEFAULT:t}}}),setSecondaryColor:t=>n({colors:{...e.colors,secondary:{...e.colors.secondary,DEFAULT:t}}})}}function m(){const{localization:e,setLocale:n}=r();return{localization:e,setLocale:n,currentLocale:e.defaultLocale,supportedLocales:e.supportedLocales,dateFormat:e.dateFormat,timeFormat:e.timeFormat,direction:e.direction,isRTL:e.direction==="rtl",setEnglish:()=>n("en"),setSpanish:()=>n("es"),setFrench:()=>n("fr"),setGerman:()=>n("de")}}function h(){const{organization:e,organizationSettings:n,isMultiTenant:a,isCustomBranded:s,features:t}=r(),u=o.useMemo(()=>e?{sso:e.features?.sso||!1,mfa:e.features?.mfa||!1,auditLogs:e.features?.auditLogs||!1,customBranding:e.features?.customBranding||!1,apiAccess:e.features?.apiAccess||!1}:{},[e]);return{organization:e,organizationSettings:n,isMultiTenant:a,isCustomBranded:s,features:u,organizationId:e?.id||null,organizationName:e?.name||null,organizationSlug:e?.slug||null,allowPublicSignup:n?.allowPublicSignup||!1,requireEmailVerification:n?.requireEmailVerification||!1,requirePhoneVerification:n?.requirePhoneVerification||!1,mfaRequired:n?.mfaRequired||!1,allowedMfaMethods:n?.allowedMfaMethods||[],branding:n?.branding,logo:n?.branding?.logo,primaryColor:n?.branding?.primaryColor,secondaryColor:n?.branding?.secondaryColor,customCSS:n?.branding?.customCSS,limits:e?.limits,maxUsers:e?.limits?.maxUsers||0,maxSessions:e?.limits?.maxSessions||0,apiRequestLimit:e?.limits?.apiRequestLimit||0}}function C(){const{components:e}=r(),n=o.useCallback((s,t)=>e[s]||t,[e]),a=o.useCallback(s=>!!e[s],[e]);return{components:e,getComponent:n,hasOverride:a,hasCustomLayout:a("Layout"),hasCustomHeader:a("Header"),hasCustomFooter:a("Footer"),hasCustomSignInForm:a("SignInForm"),hasCustomSignUpForm:a("SignUpForm"),hasCustomUserProfile:a("UserProfile"),hasCustomButton:a("Button"),hasCustomInput:a("Input"),hasCustomCard:a("Card"),hasCustomModal:a("Modal")}}function y(){const{isConfigValid:e,configErrors:n,debug:a,publishableKey:s,apiUrl:t,userType:u}=r(),c=o.useMemo(()=>{const l=[];return s?.startsWith("pk_test_")&&typeof window<"u"&&window.location.hostname!=="localhost"&&!window.location.hostname.includes("127.0.0.1")&&l.push("Using test publishable key in production environment"),t?.startsWith("http://")&&typeof window<"u"&&window.location.protocol==="https:"&&l.push("Using HTTP API URL on HTTPS site"),l},[s,t]);return{isValid:e,errors:n,warnings:c,debug:a,hasErrors:n.length>0,hasWarnings:c.length>0,isProduction:!s?.startsWith("pk_test_"),isTestMode:s?.startsWith("pk_test_"),validatePublishableKey:()=>s?/^pk_(test|live|standalone)_[a-zA-Z0-9_]+$/.test(s):!1,validateApiUrl:()=>{if(!t)return!0;try{return new URL(t),!0}catch{return!1}},validateUserType:()=>["internal","external","end_user"].includes(u)}}exports.useComponentConfiguration=C;exports.useConfig=r;exports.useConfigValidation=y;exports.useFeatureFlags=p;exports.useLocalizationConfig=m;exports.useOrganizationConfiguration=h;exports.useThemeConfig=f; //# sourceMappingURL=use-config.cjs.map