UNPKG

@frank-auth/react

Version:

Flexible and customizable React UI components for Frank Authentication

5 lines (4 loc) 9.1 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(e,t,s){return{path:e,message:t,value:s}}function m(e,t,s){return{path:e,message:t,value:s}}function b(e){try{return new URL(e),!0}catch{return!1}}function p(e){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(e)}function z(e){return typeof e=="string"&&e.length>0}function u(e,t){return t.includes(e)}function y(e){const t=[];return e?typeof e!="string"?(t.push(o("publishableKey","Publishable key must be a string",e)),t):(/^pk_(test|live)_[a-zA-Z0-9_]+$/.test(e)||t.push(o("publishableKey","Invalid publishable key format. Expected: pk_test_... or pk_live_...",e)),e.length<20&&t.push(o("publishableKey","Publishable key appears to be too short",e)),t):(t.push(o("publishableKey","Publishable key is required")),t)}function g(e){const t=[];return e?typeof e!="string"?(t.push(o("apiUrl","API URL must be a string",e)),t):(b(e)||t.push(o("apiUrl","Invalid API URL format",e)),e.startsWith("http://")&&!e.includes("localhost")&&!e.includes("127.0.0.1")&&t.push(m("apiUrl","Consider using HTTPS for production API URL",e)),t):t}function v(e){const t=[],s=["internal","external","end_user"];return u(e,s)||t.push(o("userType",`Invalid user type. Must be one of: ${s.join(", ")}`,e)),t}function f(e){const t=[],s=["en","es","fr","de","pt","it","ja","ko","zh"];return u(e,s)||t.push(o("locale",`Invalid locale. Must be one of: ${s.join(", ")}`,e)),t}function $(e){const t=[],s=["light","dark","system"];return u(e,s)||t.push(o("theme.mode",`Invalid theme mode. Must be one of: ${s.join(", ")}`,e)),t}function j(e,t="theme.colors"){const s=[];if(!e||typeof e!="object")return s.push(o(t,"Colors must be an object",e)),s;const n=["primary","secondary","background","foreground"];for(const i of n){if(!(i in e)){s.push(o(`${t}.${i}`,`Missing required color: ${i}`));continue}const r=e[i];if(i==="primary"||i==="secondary"){if(typeof r!="object"){s.push(o(`${t}.${i}`,`${i} must be an object with color shades`,r));continue}const M=["DEFAULT","foreground"];for(const a of M)a in r?p(r[a])||s.push(o(`${t}.${i}.${a}`,"Invalid hex color format",r[a])):s.push(o(`${t}.${i}.${a}`,`Missing required shade: ${a}`))}else p(r)||s.push(o(`${t}.${i}`,"Invalid hex color format",r))}return s}function C(e,t="theme.typography"){const s=[];return!e||typeof e!="object"?(s.push(o(t,"Typography must be an object",e)),s):(e.fontFamily&&(typeof e.fontFamily!="object"?s.push(o(`${t}.fontFamily`,"Font family must be an object",e.fontFamily)):(e.fontFamily.sans&&!Array.isArray(e.fontFamily.sans)&&s.push(o(`${t}.fontFamily.sans`,"Sans font family must be an array",e.fontFamily.sans)),e.fontFamily.mono&&!Array.isArray(e.fontFamily.mono)&&s.push(o(`${t}.fontFamily.mono`,"Mono font family must be an array",e.fontFamily.mono)))),e.fontSize&&(typeof e.fontSize!="object"?s.push(o(`${t}.fontSize`,"Font size must be an object",e.fontSize)):Object.entries(e.fontSize).forEach(([n,i])=>{(!Array.isArray(i)||i.length!==2)&&s.push(o(`${t}.fontSize.${n}`,"Font size value must be an array with [size, lineHeight]",i))})),s)}function F(e){const t=[];return!e||typeof e!="object"?(t.push(o("theme","Theme must be an object",e)),t):(e.mode&&t.push(...$(e.mode)),e.colors&&t.push(...j(e.colors)),e.typography&&t.push(...C(e.typography)),e.spacing&&(typeof e.spacing!="object"?t.push(o("theme.spacing","Spacing must be an object",e.spacing)):Object.entries(e.spacing).forEach(([s,n])=>{z(n)||t.push(o(`theme.spacing.${s}`,"Invalid CSS value for spacing",n))})),t)}function L(e){const t=[],s=["system","light","dark"];return u(e,s)||t.push(o("appearance.mode",`Invalid appearance mode. Must be one of: ${s.join(", ")}`,e)),t}function c(e){const t=[],s=["sm","md","lg"];return u(e,s)||t.push(o("size",`Invalid component size. Must be one of: ${s.join(", ")}`,e)),t}function d(e){const t=[],s=["default","primary","secondary","success","warning","danger"];return u(e,s)||t.push(o("color",`Invalid color variant. Must be one of: ${s.join(", ")}`,e)),t}function h(e,t="appearance.branding"){const s=[];return!e||typeof e!="object"?(s.push(o(t,"Branding must be an object",e)),s):(e.logo&&(e.logo.url&&!b(e.logo.url)&&s.push(o(`${t}.logo.url`,"Invalid logo URL",e.logo.url)),e.logo.alt||s.push(o(`${t}.logo.alt`,"Logo alt text is required for accessibility"))),e.colors&&(e.colors.primary&&!p(e.colors.primary)&&s.push(o(`${t}.colors.primary`,"Invalid hex color format",e.colors.primary)),e.colors.secondary&&!p(e.colors.secondary)&&s.push(o(`${t}.colors.secondary`,"Invalid hex color format",e.colors.secondary))),s)}function A(e){const t=[];if(!e||typeof e!="object")return t.push(o("appearance","Appearance must be an object",e)),t;if(e.mode&&t.push(...L(e.mode)),e.branding&&t.push(...h(e.branding)),e.components){const{components:s}=e;s.input?.size&&t.push(...c(s.input.size)),s.input?.color&&t.push(...d(s.input.color)),s.button?.size&&t.push(...c(s.button.size)),s.button?.color&&t.push(...d(s.button.color))}return t}function S(e){const t=[];return!e||typeof e!="object"?(t.push(o("localization","Localization must be an object",e)),t):(e.defaultLocale&&t.push(...f(e.defaultLocale).map(s=>({...s,path:`localization.${s.path}`}))),e.fallbackLocale&&t.push(...f(e.fallbackLocale).map(s=>({...s,path:`localization.${s.path}`}))),e.supportedLocales&&(Array.isArray(e.supportedLocales)?e.supportedLocales.forEach((s,n)=>{t.push(...f(s).map(i=>({...i,path:`localization.supportedLocales[${n}]`})))}):t.push(o("localization.supportedLocales","Supported locales must be an array",e.supportedLocales))),e.dateFormat&&typeof e.dateFormat!="string"&&t.push(o("localization.dateFormat","Date format must be a string",e.dateFormat)),e.timeFormat&&typeof e.timeFormat!="string"&&t.push(o("localization.timeFormat","Time format must be a string",e.timeFormat)),t)}function I(e){const t=[];if(!e||typeof e!="object")return t.push(o("organization","Organization must be an object",e)),t;if(e.id&&typeof e.id!="string"&&t.push(o("organization.id","Organization ID must be a string",e.id)),e.name&&typeof e.name!="string"&&t.push(o("organization.name","Organization name must be a string",e.name)),e.settings){const{settings:s}=e;s.passwordPolicy&&(s.passwordPolicy.minLength&&typeof s.passwordPolicy.minLength!="number"&&t.push(o("organization.settings.passwordPolicy.minLength","Min length must be a number",s.passwordPolicy.minLength)),s.passwordPolicy.minLength&&s.passwordPolicy.minLength<4&&t.push(m("organization.settings.passwordPolicy.minLength","Minimum password length should be at least 4 characters"))),s.sessionSettings&&s.sessionSettings.maxDuration&&typeof s.sessionSettings.maxDuration!="number"&&t.push(o("organization.settings.sessionSettings.maxDuration","Max duration must be a number",s.sessionSettings.maxDuration)),s.branding&&t.push(...h(s.branding,"organization.settings.branding"))}return t}function P(e){const t=[];return!e||typeof e!="object"?(t.push(o("components","Components must be an object",e)),t):(Object.entries(e).forEach(([s,n])=>{n&&typeof n!="function"&&t.push(o(`components.${s}`,"Component override must be a React component (function)",n))}),t)}function l(e){const t=[],s=[];if(!e||typeof e!="object")return{isValid:!1,errors:[o("config","Configuration must be an object",e)],warnings:[]};if(e.publishableKey?t.push(...y(e.publishableKey)):t.push(o("publishableKey","Publishable key is required")),e.userType?t.push(...v(e.userType)):t.push(o("userType","User type is required")),e.apiUrl){const n=g(e.apiUrl);t.push(...n.filter(i=>i.path.includes("error"))),s.push(...n.filter(i=>i.path.includes("warning")))}return e.theme&&t.push(...F(e.theme)),e.appearance&&t.push(...A(e.appearance)),e.localization&&t.push(...S(e.localization)),e.organization&&t.push(...I(e.organization)),e.components&&t.push(...P(e.components)),e.features&&(typeof e.features!="object"?t.push(o("features","Features must be an object",e.features)):!e.features.signIn&&!e.features.sso&&s.push(m("features","At least one authentication method (signIn or sso) should be enabled"))),{isValid:t.length===0,errors:t,warnings:s}}function T(e){const t=l(e);if(!t.isValid){const s=t.errors.map(n=>`${n.path}: ${n.message}`);throw new Error(`Invalid Frank Auth configuration: ${s.join(` `)}`)}}function U(e){return l(e).isValid}function w(e){return l(e).errors.map(s=>`${s.path}: ${s.message}`)}function V(e){return l(e).warnings.map(s=>`${s.path}: ${s.message}`)}exports.assertValidConfig=T;exports.getConfigErrors=w;exports.getConfigWarnings=V;exports.isValidConfig=U;exports.validateApiUrl=g;exports.validateAppearanceConfig=A;exports.validateAppearanceMode=L;exports.validateBrandingConfig=h;exports.validateColorPalette=j;exports.validateColorVariant=d;exports.validateComponentOverrides=P;exports.validateComponentSize=c;exports.validateFrankAuthConfig=l;exports.validateLocale=f;exports.validateLocalizationConfig=S;exports.validateOrganizationConfig=I;exports.validatePublishableKey=y;exports.validateThemeConfig=F;exports.validateThemeMode=$;exports.validateTypography=C;exports.validateUserType=v; //# sourceMappingURL=validators.cjs.map