UNPKG

@frank-auth/react

Version:

Flexible and customizable React UI components for Frank Authentication

3 lines (2 loc) 7.74 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=t=>{try{const e=new URL(t),n=s(e.search);return{protocol:e.protocol,hostname:e.hostname,port:e.port||void 0,pathname:e.pathname,search:e.search,hash:e.hash,query:n,origin:e.origin,href:e.href}}catch{return null}},c=(t,e)=>{try{const n=new URL(t);if(e)for(const[r,o]of Object.entries(e))o!=null&&n.searchParams.set(r,String(o));return n.toString()}catch{return t}},p=(t,e)=>c(t,e),s=t=>{const e=new URLSearchParams(t),n={};for(const[r,o]of e.entries())r in n?Array.isArray(n[r])?n[r].push(o):n[r]=[n[r],o]:n[r]=o;return n},w=t=>{const e=new URLSearchParams;for(const[n,r]of Object.entries(t))if(r!=null)if(Array.isArray(r))for(const o of r)e.append(n,String(o));else e.set(n,String(r));return e.toString()},U=(t,e)=>{try{const n=new URL(t);for(const r of e)n.searchParams.delete(r);return n.toString()}catch{return t}},y=(t,e)=>{try{return new URL(t).searchParams.get(e)}catch{return null}},R=(t,e)=>{try{return new URL(t).searchParams.has(e)}catch{return!1}},L=(t,e,n)=>{const r={signin:"/sign-in",signup:"/sign-up",reset:"/reset-password",verify:"/verify"},o=new URL(r[e],t);if(n)for(const[i,a]of Object.entries(n))a!=null&&o.searchParams.set(i,String(a));return o.toString()},b=(t,e,n,r)=>{const i={google:"https://accounts.google.com/o/oauth2/v2/auth",github:"https://github.com/login/oauth/authorize",microsoft:"https://login.microsoftonline.com/common/oauth2/v2.0/authorize",facebook:"https://www.facebook.com/v18.0/dialog/oauth",apple:"https://appleid.apple.com/auth/authorize",twitter:"https://twitter.com/i/oauth2/authorize",linkedin:"https://www.linkedin.com/oauth/v2/authorization",discord:"https://discord.com/api/oauth2/authorize",slack:"https://slack.com/oauth/v2/authorize",spotify:"https://accounts.spotify.com/authorize"}[t.toLowerCase()];if(!i)throw new Error(`Unsupported OAuth provider: ${t}`);const a={client_id:e,redirect_uri:n,response_type:r?.responseType||"code"};if(r?.state&&(a.state=r.state),r?.scope&&(a.scope=Array.isArray(r.scope)?r.scope.join(" "):r.scope),r?.codeChallenge&&r?.codeChallengeMethod&&(a.code_challenge=r.codeChallenge,a.code_challenge_method=r.codeChallengeMethod),r?.organizationId&&(a.organization_id=r.organizationId),r)for(const[g,u]of Object.entries(r))u!=null&&!["state","scope","responseType","codeChallenge","codeChallengeMethod","organizationId"].includes(g)&&(a[g]=String(u));return c(i,a)},P=t=>{const e=d(t);return e?{code:typeof e.query.code=="string"?e.query.code:void 0,state:typeof e.query.state=="string"?e.query.state:void 0,error:typeof e.query.error=="string"?e.query.error:void 0,errorDescription:typeof e.query.error_description=="string"?e.query.error_description:void 0,organizationId:typeof e.query.organization_id=="string"?e.query.organization_id:void 0}:{}},v=(t,e,n)=>{const r=new URL("/auth/magic-link",t);return r.searchParams.set("token",e),n?.redirectUrl&&r.searchParams.set("redirect_url",n.redirectUrl),n?.organizationId&&r.searchParams.set("organization_id",n.organizationId),n?.mode&&r.searchParams.set("mode",n.mode),r.toString()},z=(t,e,n,r)=>{const o=new URL(`/auth/verify-${n}`,t);return o.searchParams.set("token",e),r?.redirectUrl&&o.searchParams.set("redirect_url",r.redirectUrl),r?.organizationId&&o.searchParams.set("organization_id",r.organizationId),o.toString()},C=(t,e,n)=>{const r=new URL("/auth/reset-password",t);return r.searchParams.set("token",e),n?.redirectUrl&&r.searchParams.set("redirect_url",n.redirectUrl),n?.organizationId&&r.searchParams.set("organization_id",n.organizationId),r.toString()},S=(t,e,n)=>{const r=new URL("/auth/invitation",t);return r.searchParams.set("token",e),n?.redirectUrl&&r.searchParams.set("redirect_url",n.redirectUrl),n?.organizationId&&r.searchParams.set("organization_id",n.organizationId),r.toString()},O=t=>{try{return new URL(t),!0}catch{return!1}},l=t=>{try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},j=t=>{try{return new URL(t).protocol==="https:"}catch{return!1}},h=(t,e)=>{try{const r=new URL(t).hostname.toLowerCase();return e.some(o=>{const i=o.toLowerCase();return r===i||r.endsWith(`.${i}`)})}catch{return!1}},k=(t,e)=>{try{const r=new URL(t).hostname.toLowerCase(),o=e.toLowerCase();return r===o||r.endsWith(`.${o}`)}catch{return!1}},f=t=>{try{return new URL(t).hostname}catch{return null}},I=t=>{const e=f(t);if(!e)return null;const n=e.split(".");return n.length>=2?n.slice(-2).join("."):e},_=t=>{try{const e=new URL(t);(e.protocol==="http:"&&e.port==="80"||e.protocol==="https:"&&e.port==="443")&&(e.port=""),e.pathname!=="/"&&e.pathname.endsWith("/")&&(e.pathname=e.pathname.slice(0,-1));const n=Array.from(e.searchParams.entries()).sort(([r],[o])=>r.localeCompare(o));e.search="";for(const[r,o]of n)e.searchParams.append(r,o);return e.toString()}catch{return t}},A=(...t)=>{if(t.length===0)return"";const[e,...n]=t;let r=e.replace(/\/+$/,"");for(const o of n){const i=o.replace(/^\/+|\/+$/g,"");i&&(r+="/"+i)}return r},Q=t=>{try{return new URL(t).pathname}catch{return""}},q=t=>{try{const e=new URL(t);return s(e.search)}catch{return{}}},m=(t,e,n=!0)=>t?n&&t.startsWith("/")?!0:l(t)?h(t,e):!1:!1,D=(t,e,n="/")=>m(t,e)?t:n,H=()=>typeof window<"u"?window.location.href:"",V=()=>typeof window<"u"?window.location.pathname:"",T=()=>typeof window<"u"?window.location.hostname:"",$=()=>typeof window<"u"?window.location.origin:"",M=()=>typeof window<"u"?s(window.location.search):{},x=(t,e=!1)=>{typeof window<"u"&&(e?window.location.replace(t):window.location.href=t)},W=t=>{typeof window<"u"&&window.open(t,"_blank","noopener,noreferrer")},N=()=>typeof window<"u"?window.location.hash:"",E=t=>{typeof window<"u"&&(window.location.hash=t)},B=()=>{typeof window<"u"&&window.history.replaceState("",document.title,window.location.pathname+window.location.search)},F=t=>encodeURIComponent(t).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),G=t=>{try{return decodeURIComponent(t)}catch{return t}},J={parseURL:d,parseQueryString:s,parseOAuthCallback:P,buildURL:c,buildQueryString:w,buildAuthURL:L,buildOAuthURL:b,buildMagicLinkURL:v,buildVerificationURL:z,buildPasswordResetURL:C,buildInvitationURL:S,addQueryParams:p,removeQueryParams:U,getQueryParam:y,hasQueryParam:R,joinURL:A,normalizeURL:_,isValidURL:O,isValidHttpURL:l,isValidHttpsURL:j,isDomainAllowed:h,isSubdomain:k,isSafeRedirectURL:m,extractDomain:f,extractRootDomain:I,getURLPath:Q,getURLParams:q,getCurrentURL:H,getCurrentPath:V,getCurrentDomain:T,getCurrentOrigin:$,getCurrentParams:M,redirectTo:x,openInNewTab:W,getHash:N,setHash:E,removeHash:B,encodeURIComponentSafe:F,decodeURIComponentSafe:G,sanitizeRedirectURL:D};exports.URLUtils=J;exports.addQueryParams=p;exports.buildAuthURL=L;exports.buildInvitationURL=S;exports.buildMagicLinkURL=v;exports.buildOAuthURL=b;exports.buildPasswordResetURL=C;exports.buildQueryString=w;exports.buildURL=c;exports.buildVerificationURL=z;exports.decodeURIComponentSafe=G;exports.encodeURIComponentSafe=F;exports.extractDomain=f;exports.extractRootDomain=I;exports.getCurrentDomain=T;exports.getCurrentOrigin=$;exports.getCurrentParams=M;exports.getCurrentPath=V;exports.getCurrentURL=H;exports.getHash=N;exports.getQueryParam=y;exports.getURLParams=q;exports.getURLPath=Q;exports.hasQueryParam=R;exports.isDomainAllowed=h;exports.isSafeRedirectURL=m;exports.isSubdomain=k;exports.isValidHttpURL=l;exports.isValidHttpsURL=j;exports.isValidURL=O;exports.joinURL=A;exports.normalizeURL=_;exports.openInNewTab=W;exports.parseOAuthCallback=P;exports.parseQueryString=s;exports.parseURL=d;exports.redirectTo=x;exports.removeHash=B;exports.removeQueryParams=U;exports.sanitizeRedirectURL=D;exports.setHash=E; //# sourceMappingURL=url.cjs.map