@leancodepl/kratos 10.1.2 → 10.1.3
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/CHANGELOG.md +18 -0
- package/README.md +79 -39
- package/dist/index.js +84 -83
- package/dist/index.umd.cjs +1 -1
- package/dist/lib/factories/mkKratos.d.ts +3 -3
- package/dist/lib/factories/mkKratos.d.ts.map +1 -1
- package/dist/lib/flows/formTypes.d.ts +6 -0
- package/dist/lib/flows/formTypes.d.ts.map +1 -0
- package/dist/lib/flows/index.d.ts +6 -0
- package/dist/lib/flows/index.d.ts.map +1 -1
- package/dist/lib/flows/login/formTypes.d.ts +10 -0
- package/dist/lib/flows/login/formTypes.d.ts.map +1 -0
- package/dist/lib/flows/login/loginFlow.d.ts.map +1 -1
- package/dist/lib/flows/recovery/formTypes.d.ts +9 -0
- package/dist/lib/flows/recovery/formTypes.d.ts.map +1 -0
- package/dist/lib/flows/registration/formTypes.d.ts +9 -0
- package/dist/lib/flows/registration/formTypes.d.ts.map +1 -0
- package/dist/lib/flows/settings/formTypes.d.ts +12 -0
- package/dist/lib/flows/settings/formTypes.d.ts.map +1 -0
- package/dist/lib/flows/verification/formTypes.d.ts +7 -0
- package/dist/lib/flows/verification/formTypes.d.ts.map +1 -0
- package/package.json +2 -2
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(b,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("react/jsx-runtime"),require("react"),require("@tanstack/react-query"),require("@leancodepl/utils"),require("@tanstack/react-form"),require("@radix-ui/react-slot")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@tanstack/react-query","@leancodepl/utils","@tanstack/react-form","@radix-ui/react-slot"],s):(b=typeof globalThis<"u"?globalThis:b||self,s(b["@leancodepl/kratos"]={},b.jsxRuntime,b.react,b.reactQuery,b.utils,b.reactForm,b.Slot))})(this,(function(b,s,l,m,Ne,D,cn){"use strict";function ln(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const y=ln(cn);var P=(e=>(e[e.NoFlowId=0]="NoFlowId",e[e.FlowRestartRequired=1]="FlowRestartRequired",e))(P||{});const tt=l.createContext(void 0);function Ee(){const e=l.useContext(tt);if(e===void 0)throw new Error("useKratosSessionContext must be used within a KratosSessionContextProvider");return e}function un({children:e,sessionManager:t}){const n=l.useMemo(()=>({sessionManager:t}),[t]);return s.jsx(tt.Provider,{value:n,children:e})}const ne=({initialFlowId:e,currentFlowId:t,error:n,onFlowRestart:o,createFlow:i,setFlowId:r,waitForSession:a})=>{const[c,u]=l.useState(!1),[w,f]=l.useState(e),{sessionManager:d}=Ee(),{isLoading:_}=d.useSession();w!==e&&(u(!1),f(e));const F=!!a&&_;l.useEffect(()=>{t||F||(e&&!c?(r(e),u(!0)):i())},[i,t,e,c,r,F]),l.useEffect(()=>{n&&n.cause===P.FlowRestartRequired&&(i(),o?.())},[i,n,o])},X="traits.";function nt(e){return"type"in e&&e.type==="public-key"&&"id"in e&&"rawId"in e&&"response"in e}function dn(e){return"attestationObject"in e&&"clientDataJSON"in e}function fn(e){return"authenticatorData"in e&&"clientDataJSON"in e&&"signature"in e}function le(e){return Uint8Array.from(atob(e.replaceAll("-","+").replaceAll("_","/")),function(t){return t.charCodeAt(0)})}function W(e){return btoa(String.fromCharCode(...new Uint8Array(e))).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")}function ot(e){if(!e||!nt(e))return;const{response:t,id:n,rawId:o}=e;if(dn(t))return JSON.stringify({id:n,rawId:W(o),type:e.type,response:{attestationObject:W(t.attestationObject),clientDataJSON:W(t.clientDataJSON)}})}async function it({credentialOptions:e,signal:t,userName:n,userDisplayName:o}){return await navigator.credentials.create({signal:t,publicKey:{challenge:le(e.publicKey.challenge),timeout:e.publicKey.timeout,rp:{id:e.publicKey.rp.id,name:e.publicKey.rp.name},user:{id:le(e.publicKey.user.id),name:n,displayName:o},pubKeyCredParams:e.publicKey.pubKeyCredParams}})}function rt(e){if(!e||!nt(e))return;const{response:t,id:n,rawId:o}=e;if(!fn(t))return;const{userHandle:i,authenticatorData:r,clientDataJSON:a,signature:c}=t;return JSON.stringify({id:n,rawId:W(o),type:e.type,response:{authenticatorData:W(r),clientDataJSON:W(a),signature:W(c),userHandle:i?W(i):void 0}})}async function wn({challengeOptions:e,signal:t}){return await navigator.credentials.get({signal:t,publicKey:{challenge:le(e.publicKey.challenge),timeout:e.publicKey.timeout,rpId:e.publicKey.rpId,userVerification:e.publicKey.userVerification}})}function pn(){return!!globalThis.PublicKeyCredential}async function hn(e,t){const n=JSON.parse(e);if(pn()&&globalThis.PublicKeyCredential.isConditionalMediationAvailable&&await globalThis.PublicKeyCredential.isConditionalMediationAvailable())try{const o=await navigator.credentials.get({mediation:"conditional",signal:t,publicKey:{challenge:le(n.publicKey.challenge),timeout:n.publicKey.timeout,rpId:n.publicKey.rpId,userVerification:n.publicKey.userVerification}});return rt(o)}catch{return}}async function _n(e,t){const n=JSON.parse(e);try{return rt(await wn({challengeOptions:n,signal:t}))}catch{return}}async function gn(e,t,n){const{credentialOptions:o,displayNameFieldName:i}=JSON.parse(e),r=i.startsWith(X)?i.slice(X.length):i,a=typeof n?.[r]=="string"?n[r]:"";try{return ot(await it({credentialOptions:o,signal:t,userName:a,userDisplayName:a}))}catch{return}}async function mn(e,t){const n=JSON.parse(e);try{return ot(await it({credentialOptions:n,signal:t,userName:n.publicKey.user.name,userDisplayName:n.publicKey.user.displayName}))}catch{return}}const p=(e,t,n)=>e!==void 0&&t in e&&typeof e[t]===n,yn="https://playground.projects.oryapis.com".replace(/\/+$/,"");class at{constructor(t={}){this.configuration=t}set config(t){this.configuration=t}get basePath(){return this.configuration.basePath!=null?this.configuration.basePath:yn}get fetchApi(){return this.configuration.fetchApi}get middleware(){return this.configuration.middleware||[]}get queryParamsStringify(){return this.configuration.queryParamsStringify||st}get username(){return this.configuration.username}get password(){return this.configuration.password}get apiKey(){const t=this.configuration.apiKey;if(t)return typeof t=="function"?t:()=>t}get accessToken(){const t=this.configuration.accessToken;if(t)return typeof t=="function"?t:async()=>t}get headers(){return this.configuration.headers}get credentials(){return this.configuration.credentials}}const Fn=new at;class Me{constructor(t=Fn){this.configuration=t,this.middleware=t.middleware}static jsonRegex=new RegExp("^(:?application/json|[^;/ ]+/[^;/ ]+[+]json)[ ]*(:?;.*)?$","i");middleware;withMiddleware(...t){const n=this.clone();return n.middleware=n.middleware.concat(...t),n}withPreMiddleware(...t){const n=t.map(o=>({pre:o}));return this.withMiddleware(...n)}withPostMiddleware(...t){const n=t.map(o=>({post:o}));return this.withMiddleware(...n)}isJsonMime(t){return t?Me.jsonRegex.test(t):!1}async request(t,n){const{url:o,init:i}=await this.createFetchParams(t,n),r=await this.fetchApi(o,i);if(r&&r.status>=200&&r.status<300)return r;throw new Y(r,"Response returned an error code")}async createFetchParams(t,n){let o=this.configuration.basePath+t.path;t.query!==void 0&&Object.keys(t.query).length!==0&&(o+="?"+this.configuration.queryParamsStringify(t.query));const i=Object.assign({},this.configuration.headers,t.headers);Object.keys(i).forEach(f=>i[f]===void 0?delete i[f]:{});const r=typeof n=="function"?n:async()=>n,a={method:t.method,headers:i,body:t.body,credentials:this.configuration.credentials},c={...a,...await r({init:a,context:t})};let u;Sn(c.body)||c.body instanceof URLSearchParams||vn(c.body)?u=c.body:this.isJsonMime(i["Content-Type"])?u=JSON.stringify(c.body):u=c.body;const w={...c,body:u};return{url:o,init:w}}fetchApi=async(t,n)=>{let o={url:t,init:n};for(const r of this.middleware)r.pre&&(o=await r.pre({fetch:this.fetchApi,...o})||o);let i;try{i=await(this.configuration.fetchApi||fetch)(o.url,o.init)}catch(r){for(const a of this.middleware)a.onError&&(i=await a.onError({fetch:this.fetchApi,url:o.url,init:o.init,error:r,response:i?i.clone():void 0})||i);if(i===void 0)throw r instanceof Error?new Re(r,"The request failed and the interceptors did not return an alternative response"):r}for(const r of this.middleware)r.post&&(i=await r.post({fetch:this.fetchApi,url:o.url,init:o.init,response:i.clone()})||i);return i};clone(){const t=this.constructor,n=new t(this.configuration);return n.middleware=this.middleware.slice(),n}}function vn(e){return typeof Blob<"u"&&e instanceof Blob}function Sn(e){return typeof FormData<"u"&&e instanceof FormData}class Y extends Error{constructor(t,n){super(n),this.response=t}name="ResponseError"}class Re extends Error{constructor(t,n){super(n),this.cause=t}name="FetchError"}class S extends Error{constructor(t,n){super(n),this.field=t}name="RequiredError"}function st(e,t=""){return Object.keys(e).map(n=>ct(n,e[n],t)).filter(n=>n.length>0).join("&")}function ct(e,t,n=""){const o=n+(n.length?`[${e}]`:e);if(t instanceof Array){const i=t.map(r=>encodeURIComponent(String(r))).join(`&${encodeURIComponent(o)}=`);return`${encodeURIComponent(o)}=${i}`}if(t instanceof Set){const i=Array.from(t);return ct(e,i,n)}return t instanceof Date?`${encodeURIComponent(o)}=${encodeURIComponent(t.toISOString())}`:t instanceof Object?st(t,o):`${encodeURIComponent(o)}=${encodeURIComponent(String(t))}`}function kn(e,t){return Object.keys(e).reduce((n,o)=>({...n,[o]:t(e[o])}),{})}class g{constructor(t,n=o=>o){this.raw=t,this.transformer=n}async value(){return this.transformer(await this.raw.json())}}class De{constructor(t){this.raw=t}async value(){}}class bn{constructor(t){this.raw=t}async value(){return await this.raw.text()}}function Ie(e){return Cn(e)}function Cn(e,t){return e}function xn(e){return Tn(e)}function Tn(e,t){return e==null?e:{id:e.id,url:e.url==null?void 0:e.url}}function On(e,t){return e==null?e:{action:e.action,flow:xn(e.flow)}}function Nn(e,t){return e==null?e:{action:e.action,redirect_browser_to:e.redirect_browser_to}}function En(e,t){return e==null?e:{action:e.action,ory_session_token:e.ory_session_token}}function Mn(e){return Rn(e)}function Rn(e,t){return e==null?e:{id:e.id,url:e.url==null?void 0:e.url}}function Dn(e,t){return e==null?e:{action:e.action,flow:Mn(e.flow)}}function In(e){return Jn(e)}function Jn(e,t){return e==null?e:{id:e.id,url:e.url==null?void 0:e.url,verifiable_address:e.verifiable_address}}function Un(e,t){return e==null?e:{action:e.action,flow:In(e.flow)}}function ue(e){return An(e)}function An(e,t){if(e==null)return e;switch(e.action){case"redirect_browser_to":return Object.assign({},Nn(e),{action:"redirect_browser_to"});case"set_ory_session_token":return Object.assign({},En(e),{action:"set_ory_session_token"});case"show_recovery_ui":return Object.assign({},On(e),{action:"show_recovery_ui"});case"show_settings_ui":return Object.assign({},Dn(e),{action:"show_settings_ui"});case"show_verification_ui":return Object.assign({},Un(e),{action:"show_verification_ui"});default:throw new Error(`No variant of ContinueWith exists with 'action=${e.action}'`)}}function Ln(e){return Vn(e)}function Vn(e,t){return e==null?e:{client_id:e.client_id==null?void 0:e.client_id,config_url:e.config_url==null?void 0:e.config_url,domain_hint:e.domain_hint==null?void 0:e.domain_hint,fields:e.fields==null?void 0:e.fields,login_hint:e.login_hint==null?void 0:e.login_hint,nonce:e.nonce==null?void 0:e.nonce,parameters:e.parameters==null?void 0:e.parameters}}function Pn(e){return Wn(e)}function Wn(e,t){return e==null?e:{csrf_token:e.csrf_token==null?void 0:e.csrf_token,providers:e.providers==null?void 0:e.providers.map(Ln)}}function Bn(e){return qn(e)}function qn(e,t){return e==null?e:{created_at:e.created_at==null?void 0:new Date(e.created_at),id:e.id==null?void 0:e.id,status:e.status,updated_at:e.updated_at==null?void 0:new Date(e.updated_at),value:e.value,verified:e.verified,verified_at:e.verified_at==null?void 0:new Date(e.verified_at),via:e.via}}function $n(e){return Kn(e)}function Kn(e,t){return e==null?e:{created_at:e.created_at==null?void 0:new Date(e.created_at),id:e.id,updated_at:e.updated_at==null?void 0:new Date(e.updated_at),value:e.value,via:e.via}}function zn(e){return Gn(e)}function Gn(e,t){return e==null?e:{count:e.count==null?void 0:e.count}}function Qn(e){return Hn(e)}function Hn(e,t){return e==null?e:{created_at:e.created_at==null?void 0:new Date(e.created_at),error:e.error==null?void 0:e.error,id:e.id,updated_at:e.updated_at==null?void 0:new Date(e.updated_at)}}function Xn(e){return Yn(e)}function Yn(e,t){return e==null?e:{config:e.config==null?void 0:e.config,created_at:e.created_at==null?void 0:new Date(e.created_at),identifiers:e.identifiers==null?void 0:e.identifiers,type:e.type==null?void 0:e.type,updated_at:e.updated_at==null?void 0:new Date(e.updated_at),version:e.version==null?void 0:e.version}}function Je(e){return Zn(e)}function Zn(e,t){return e==null?e:{created_at:e.created_at==null?void 0:new Date(e.created_at),credentials:e.credentials==null?void 0:kn(e.credentials,Xn),id:e.id,metadata_admin:e.metadata_admin==null?void 0:e.metadata_admin,metadata_public:e.metadata_public==null?void 0:e.metadata_public,organization_id:e.organization_id==null?void 0:e.organization_id,recovery_addresses:e.recovery_addresses==null?void 0:e.recovery_addresses.map($n),schema_id:e.schema_id,schema_url:e.schema_url,state:e.state==null?void 0:e.state,state_changed_at:e.state_changed_at==null?void 0:new Date(e.state_changed_at),traits:e.traits,updated_at:e.updated_at==null?void 0:new Date(e.updated_at),verifiable_addresses:e.verifiable_addresses==null?void 0:e.verifiable_addresses.map(Bn)}}function jn(e){return eo(e)}function eo(e,t){return e==null?e:{acr_values:e.acr_values==null?void 0:e.acr_values,display:e.display==null?void 0:e.display,id_token_hint_claims:e.id_token_hint_claims==null?void 0:e.id_token_hint_claims,login_hint:e.login_hint==null?void 0:e.login_hint,ui_locales:e.ui_locales==null?void 0:e.ui_locales}}function to(e){return no(e)}function no(e,t){return e==null?e:{access_token_strategy:e.access_token_strategy==null?void 0:e.access_token_strategy,allowed_cors_origins:e.allowed_cors_origins==null?void 0:e.allowed_cors_origins,audience:e.audience==null?void 0:e.audience,authorization_code_grant_access_token_lifespan:e.authorization_code_grant_access_token_lifespan==null?void 0:e.authorization_code_grant_access_token_lifespan,authorization_code_grant_id_token_lifespan:e.authorization_code_grant_id_token_lifespan==null?void 0:e.authorization_code_grant_id_token_lifespan,authorization_code_grant_refresh_token_lifespan:e.authorization_code_grant_refresh_token_lifespan==null?void 0:e.authorization_code_grant_refresh_token_lifespan,backchannel_logout_session_required:e.backchannel_logout_session_required==null?void 0:e.backchannel_logout_session_required,backchannel_logout_uri:e.backchannel_logout_uri==null?void 0:e.backchannel_logout_uri,client_credentials_grant_access_token_lifespan:e.client_credentials_grant_access_token_lifespan==null?void 0:e.client_credentials_grant_access_token_lifespan,client_id:e.client_id==null?void 0:e.client_id,client_name:e.client_name==null?void 0:e.client_name,client_secret:e.client_secret==null?void 0:e.client_secret,client_secret_expires_at:e.client_secret_expires_at==null?void 0:e.client_secret_expires_at,client_uri:e.client_uri==null?void 0:e.client_uri,contacts:e.contacts==null?void 0:e.contacts,created_at:e.created_at==null?void 0:new Date(e.created_at),frontchannel_logout_session_required:e.frontchannel_logout_session_required==null?void 0:e.frontchannel_logout_session_required,frontchannel_logout_uri:e.frontchannel_logout_uri==null?void 0:e.frontchannel_logout_uri,grant_types:e.grant_types==null?void 0:e.grant_types,implicit_grant_access_token_lifespan:e.implicit_grant_access_token_lifespan==null?void 0:e.implicit_grant_access_token_lifespan,implicit_grant_id_token_lifespan:e.implicit_grant_id_token_lifespan==null?void 0:e.implicit_grant_id_token_lifespan,jwks:e.jwks==null?void 0:e.jwks,jwks_uri:e.jwks_uri==null?void 0:e.jwks_uri,jwt_bearer_grant_access_token_lifespan:e.jwt_bearer_grant_access_token_lifespan==null?void 0:e.jwt_bearer_grant_access_token_lifespan,logo_uri:e.logo_uri==null?void 0:e.logo_uri,metadata:e.metadata==null?void 0:e.metadata,owner:e.owner==null?void 0:e.owner,policy_uri:e.policy_uri==null?void 0:e.policy_uri,post_logout_redirect_uris:e.post_logout_redirect_uris==null?void 0:e.post_logout_redirect_uris,redirect_uris:e.redirect_uris==null?void 0:e.redirect_uris,refresh_token_grant_access_token_lifespan:e.refresh_token_grant_access_token_lifespan==null?void 0:e.refresh_token_grant_access_token_lifespan,refresh_token_grant_id_token_lifespan:e.refresh_token_grant_id_token_lifespan==null?void 0:e.refresh_token_grant_id_token_lifespan,refresh_token_grant_refresh_token_lifespan:e.refresh_token_grant_refresh_token_lifespan==null?void 0:e.refresh_token_grant_refresh_token_lifespan,registration_access_token:e.registration_access_token==null?void 0:e.registration_access_token,registration_client_uri:e.registration_client_uri==null?void 0:e.registration_client_uri,request_object_signing_alg:e.request_object_signing_alg==null?void 0:e.request_object_signing_alg,request_uris:e.request_uris==null?void 0:e.request_uris,response_types:e.response_types==null?void 0:e.response_types,scope:e.scope==null?void 0:e.scope,sector_identifier_uri:e.sector_identifier_uri==null?void 0:e.sector_identifier_uri,skip_consent:e.skip_consent==null?void 0:e.skip_consent,skip_logout_consent:e.skip_logout_consent==null?void 0:e.skip_logout_consent,subject_type:e.subject_type==null?void 0:e.subject_type,token_endpoint_auth_method:e.token_endpoint_auth_method==null?void 0:e.token_endpoint_auth_method,token_endpoint_auth_signing_alg:e.token_endpoint_auth_signing_alg==null?void 0:e.token_endpoint_auth_signing_alg,tos_uri:e.tos_uri==null?void 0:e.tos_uri,updated_at:e.updated_at==null?void 0:new Date(e.updated_at),userinfo_signed_response_alg:e.userinfo_signed_response_alg==null?void 0:e.userinfo_signed_response_alg}}function lt(e){return oo(e)}function oo(e,t){return e==null?e:{challenge:e.challenge,client:to(e.client),oidc_context:e.oidc_context==null?void 0:jn(e.oidc_context),request_url:e.request_url,requested_access_token_audience:e.requested_access_token_audience==null?void 0:e.requested_access_token_audience,requested_scope:e.requested_scope==null?void 0:e.requested_scope,session_id:e.session_id==null?void 0:e.session_id,skip:e.skip,subject:e.subject}}const io={Error:"error"};function ro(e){return!(!("id"in e)||e.id===void 0||!("text"in e)||e.text===void 0||!("type"in e)||e.type===void 0)}function Z(e){return ao(e)}function ao(e,t){return e==null?e:{context:e.context==null?void 0:e.context,id:e.id,text:e.text,type:e.type}}function so(e){return co(e)}function co(e,t){return e==null?e:{label:e.label==null?void 0:Z(e.label)}}function lo(e,t){return e==null?e:{href:e.href,id:e.id,node_type:e.node_type,title:Z(e.title)}}function uo(e,t){return e==null?e:{_class:e.class==null?void 0:e.class,data:e.data==null?void 0:e.data,id:e.id,node_type:e.node_type}}const ut={Text:"text",Img:"img"};function fo(e,t){return e==null?e:{height:e.height,id:e.id,node_type:e.node_type,src:e.src,width:e.width}}function wo(e,t){return e==null?e:{autocomplete:e.autocomplete==null?void 0:e.autocomplete,disabled:e.disabled,label:e.label==null?void 0:Z(e.label),maxlength:e.maxlength==null?void 0:e.maxlength,name:e.name,node_type:e.node_type,onclick:e.onclick==null?void 0:e.onclick,onclickTrigger:e.onclickTrigger==null?void 0:e.onclickTrigger,onload:e.onload==null?void 0:e.onload,onloadTrigger:e.onloadTrigger==null?void 0:e.onloadTrigger,pattern:e.pattern==null?void 0:e.pattern,required:e.required==null?void 0:e.required,type:e.type,value:e.value==null?void 0:e.value}}const po={Input:"input"};function ho(e,t){return e==null?e:{async:e.async,crossorigin:e.crossorigin,id:e.id,integrity:e.integrity,node_type:e.node_type,nonce:e.nonce,referrerpolicy:e.referrerpolicy,src:e.src,type:e.type}}function _o(e,t){return e==null?e:{id:e.id,node_type:e.node_type,text:Z(e.text)}}function go(e){return mo(e)}function mo(e,t){if(e==null)return e;switch(e.node_type){case"a":return Object.assign({},lo(e),{node_type:"a"});case"div":return Object.assign({},uo(e),{node_type:"div"});case"img":return Object.assign({},fo(e),{node_type:"img"});case"input":return Object.assign({},wo(e),{node_type:"input"});case"script":return Object.assign({},ho(e),{node_type:"script"});case"text":return Object.assign({},_o(e),{node_type:"text"});default:throw new Error(`No variant of UiNodeAttributes exists with 'node_type=${e.node_type}'`)}}const yo={Passkey:"passkey"},Fo={Input:"input"};function vo(e){return So(e)}function So(e,t){return e==null?e:{attributes:go(e.attributes),group:e.group,messages:e.messages.map(Z),meta:so(e.meta),type:e.type}}function oe(e){return ko(e)}function ko(e,t){return e==null?e:{action:e.action,messages:e.messages==null?void 0:e.messages.map(Z),method:e.method,nodes:e.nodes.map(vo)}}function Ue(e){return bo(e)}function bo(e,t){return e==null?e:{active:e.active==null?void 0:e.active,created_at:e.created_at==null?void 0:new Date(e.created_at),expires_at:new Date(e.expires_at),id:e.id,issued_at:new Date(e.issued_at),oauth2_login_challenge:e.oauth2_login_challenge==null?void 0:e.oauth2_login_challenge,oauth2_login_request:e.oauth2_login_request==null?void 0:lt(e.oauth2_login_request),organization_id:e.organization_id==null?void 0:e.organization_id,refresh:e.refresh==null?void 0:e.refresh,request_url:e.request_url,requested_aal:e.requested_aal==null?void 0:Ie(e.requested_aal),return_to:e.return_to==null?void 0:e.return_to,session_token_exchange_code:e.session_token_exchange_code==null?void 0:e.session_token_exchange_code,state:e.state,transient_payload:e.transient_payload==null?void 0:e.transient_payload,type:e.type,ui:oe(e.ui),updated_at:e.updated_at==null?void 0:new Date(e.updated_at)}}function Co(e){return xo(e)}function xo(e,t){return e==null?e:{logout_token:e.logout_token,logout_url:e.logout_url}}function To(e){return Oo(e,!1)}function Oo(e,t=!1){return e==null?e:{session_token:e.session_token}}function de(e){return No(e)}function No(e,t){return e==null?e:{active:e.active==null?void 0:e.active,continue_with:e.continue_with==null?void 0:e.continue_with.map(ue),expires_at:new Date(e.expires_at),id:e.id,issued_at:new Date(e.issued_at),request_url:e.request_url,return_to:e.return_to==null?void 0:e.return_to,state:e.state,transient_payload:e.transient_payload==null?void 0:e.transient_payload,type:e.type,ui:oe(e.ui)}}function Ae(e){return Eo(e)}function Eo(e,t){return e==null?e:{active:e.active==null?void 0:e.active,expires_at:new Date(e.expires_at),id:e.id,issued_at:new Date(e.issued_at),oauth2_login_challenge:e.oauth2_login_challenge==null?void 0:e.oauth2_login_challenge,oauth2_login_request:e.oauth2_login_request==null?void 0:lt(e.oauth2_login_request),organization_id:e.organization_id==null?void 0:e.organization_id,request_url:e.request_url,return_to:e.return_to==null?void 0:e.return_to,session_token_exchange_code:e.session_token_exchange_code==null?void 0:e.session_token_exchange_code,state:e.state,transient_payload:e.transient_payload==null?void 0:e.transient_payload,type:e.type,ui:oe(e.ui)}}const dt={ChooseMethod:"choose_method"};function Mo(e){return Ro(e)}function Ro(e,t){return e==null?e:{id:e.id,ip_address:e.ip_address==null?void 0:e.ip_address,location:e.location==null?void 0:e.location,user_agent:e.user_agent==null?void 0:e.user_agent}}function Do(e){return Io(e)}function Io(e,t){return e==null?e:{aal:e.aal==null?void 0:Ie(e.aal),completed_at:e.completed_at==null?void 0:new Date(e.completed_at),method:e.method==null?void 0:e.method,organization:e.organization==null?void 0:e.organization,provider:e.provider==null?void 0:e.provider}}function fe(e){return Jo(e)}function Jo(e,t){return e==null?e:{active:e.active==null?void 0:e.active,authenticated_at:e.authenticated_at==null?void 0:new Date(e.authenticated_at),authentication_methods:e.authentication_methods==null?void 0:e.authentication_methods.map(Do),authenticator_assurance_level:e.authenticator_assurance_level==null?void 0:Ie(e.authenticator_assurance_level),devices:e.devices==null?void 0:e.devices.map(Mo),expires_at:e.expires_at==null?void 0:new Date(e.expires_at),id:e.id,identity:e.identity==null?void 0:Je(e.identity),issued_at:e.issued_at==null?void 0:new Date(e.issued_at),tokenized:e.tokenized==null?void 0:e.tokenized}}function we(e){return Uo(e)}function Uo(e,t){return e==null?e:{active:e.active==null?void 0:e.active,continue_with:e.continue_with==null?void 0:e.continue_with.map(ue),expires_at:new Date(e.expires_at),id:e.id,identity:Je(e.identity),issued_at:new Date(e.issued_at),request_url:e.request_url,return_to:e.return_to==null?void 0:e.return_to,state:e.state,transient_payload:e.transient_payload==null?void 0:e.transient_payload,type:e.type,ui:oe(e.ui)}}const Ao={Success:"success"};function pe(e){return!(!("session"in e)||e.session===void 0)}function Le(e){return Lo(e)}function Lo(e,t){return e==null?e:{continue_with:e.continue_with==null?void 0:e.continue_with.map(ue),session:fe(e.session),session_token:e.session_token==null?void 0:e.session_token}}function Ve(e){return!(!("identity"in e)||e.identity===void 0)}function Vo(e){return Po(e)}function Po(e,t){return e==null?e:{continue_with:e.continue_with==null?void 0:e.continue_with.map(ue),identity:Je(e.identity),session:e.session==null?void 0:fe(e.session),session_token:e.session_token==null?void 0:e.session_token}}function Wo(e){return Bo(e,!1)}function Bo(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,nonce:e.nonce,token:e.token,transient_payload:e.transient_payload}}function qo(e){return $o(e,!1)}function $o(e,t=!1){return e==null?e:{address:e.address,code:e.code,csrf_token:e.csrf_token,identifier:e.identifier,method:e.method,resend:e.resend,transient_payload:e.transient_payload}}function Ko(e){return zo(e,!1)}function zo(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,identifier:e.identifier,method:e.method,transient_payload:e.transient_payload}}function Go(e){return Qo(e,!1)}function Qo(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,lookup_secret:e.lookup_secret,method:e.method}}function Ho(e){return Xo(e,!1)}function Xo(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,id_token:e.id_token,id_token_nonce:e.id_token_nonce,method:e.method,provider:e.provider,traits:e.traits,transient_payload:e.transient_payload,upstream_parameters:e.upstream_parameters}}function Yo(e){return Zo(e,!1)}function Zo(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,passkey_login:e.passkey_login}}function jo(e){return ei(e,!1)}function ei(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,identifier:e.identifier,method:e.method,password:e.password,password_identifier:e.password_identifier,transient_payload:e.transient_payload}}function ti(e){return ni(e,!1)}function ni(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,provider:e.provider,transient_payload:e.transient_payload}}function oi(e){return ii(e,!1)}function ii(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,totp_code:e.totp_code,transient_payload:e.transient_payload}}function ri(e){return ai(e,!1)}function ai(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,identifier:e.identifier,method:e.method,transient_payload:e.transient_payload,webauthn_login:e.webauthn_login}}function si(e){return ci(e,!1)}function ci(e,t=!1){if(e==null)return e;switch(e.method){case"code":return Object.assign({},qo(e),{method:"code"});case"identifier_first":return Object.assign({},Ko(e),{method:"identifier_first"});case"lookup_secret":return Object.assign({},Go(e),{method:"lookup_secret"});case"oidc":return Object.assign({},Ho(e),{method:"oidc"});case"passkey":return Object.assign({},Yo(e),{method:"passkey"});case"password":return Object.assign({},jo(e),{method:"password"});case"saml":return Object.assign({},ti(e),{method:"saml"});case"totp":return Object.assign({},oi(e),{method:"totp"});case"webauthn":return Object.assign({},ri(e),{method:"webauthn"});default:throw new Error(`No variant of UpdateLoginFlowBody exists with 'method=${e.method}'`)}}function li(e){return ui(e,!1)}function ui(e,t=!1){return e==null?e:{code:e.code,csrf_token:e.csrf_token,email:e.email,method:e.method,transient_payload:e.transient_payload}}function di(e){return fi(e,!1)}function fi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,email:e.email,method:e.method,transient_payload:e.transient_payload}}function wi(e){return pi(e,!1)}function pi(e,t=!1){if(e==null)return e;switch(e.method){case"code":return Object.assign({},li(e),{method:"code"});case"link":return Object.assign({},di(e),{method:"link"});default:throw new Error(`No variant of UpdateRecoveryFlowBody exists with 'method=${e.method}'`)}}function hi(e){return _i(e,!1)}function _i(e,t=!1){return e==null?e:{code:e.code,csrf_token:e.csrf_token,method:e.method,resend:e.resend,traits:e.traits,transient_payload:e.transient_payload}}function gi(e){return mi(e,!1)}function mi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,id_token:e.id_token,id_token_nonce:e.id_token_nonce,method:e.method,provider:e.provider,traits:e.traits,transient_payload:e.transient_payload,upstream_parameters:e.upstream_parameters}}function yi(e){return Fi(e,!1)}function Fi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,passkey_register:e.passkey_register,traits:e.traits,transient_payload:e.transient_payload}}function vi(e){return Si(e,!1)}function Si(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,password:e.password,traits:e.traits,transient_payload:e.transient_payload}}function ki(e){return bi(e,!1)}function bi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,screen:e.screen,traits:e.traits,transient_payload:e.transient_payload}}function Ci(e){return xi(e,!1)}function xi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,provider:e.provider,traits:e.traits,transient_payload:e.transient_payload}}function Ti(e){return Oi(e,!1)}function Oi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,traits:e.traits,transient_payload:e.transient_payload,webauthn_register:e.webauthn_register,webauthn_register_displayname:e.webauthn_register_displayname}}function Ni(e){return Ei(e,!1)}function Ei(e,t=!1){if(e==null)return e;switch(e.method){case"code":return Object.assign({},hi(e),{method:"code"});case"oidc":return Object.assign({},gi(e),{method:"oidc"});case"passkey":return Object.assign({},yi(e),{method:"passkey"});case"password":return Object.assign({},vi(e),{method:"password"});case"profile":return Object.assign({},ki(e),{method:"profile"});case"saml":return Object.assign({},Ci(e),{method:"saml"});case"webauthn":return Object.assign({},Ti(e),{method:"webauthn"});default:throw new Error(`No variant of UpdateRegistrationFlowBody exists with 'method=${e.method}'`)}}function Mi(e){return Ri(e,!1)}function Ri(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,lookup_secret_confirm:e.lookup_secret_confirm,lookup_secret_disable:e.lookup_secret_disable,lookup_secret_regenerate:e.lookup_secret_regenerate,lookup_secret_reveal:e.lookup_secret_reveal,method:e.method,transient_payload:e.transient_payload}}function Di(e){return Ii(e,!1)}function Ii(e,t=!1){return e==null?e:{flow:e.flow,link:e.link,method:e.method,traits:e.traits,transient_payload:e.transient_payload,unlink:e.unlink,upstream_parameters:e.upstream_parameters}}function Ji(e){return Ui(e,!1)}function Ui(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,passkey_remove:e.passkey_remove,passkey_settings_register:e.passkey_settings_register}}function Ai(e){return Li(e,!1)}function Li(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,password:e.password,transient_payload:e.transient_payload}}function Vi(e){return Pi(e,!1)}function Pi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,traits:e.traits,transient_payload:e.transient_payload}}function Wi(e){return Bi(e,!1)}function Bi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,flow:e.flow,link:e.link,method:e.method,traits:e.traits,transient_payload:e.transient_payload,unlink:e.unlink}}function qi(e){return $i(e,!1)}function $i(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,totp_code:e.totp_code,totp_unlink:e.totp_unlink,transient_payload:e.transient_payload}}function Ki(e){return zi(e,!1)}function zi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,transient_payload:e.transient_payload,webauthn_register:e.webauthn_register,webauthn_register_displayname:e.webauthn_register_displayname,webauthn_remove:e.webauthn_remove}}function Gi(e){return Qi(e,!1)}function Qi(e,t=!1){if(e==null)return e;switch(e.method){case"lookup_secret":return Object.assign({},Mi(e),{method:"lookup_secret"});case"oidc":return Object.assign({},Di(e),{method:"oidc"});case"passkey":return Object.assign({},Ji(e),{method:"passkey"});case"password":return Object.assign({},Ai(e),{method:"password"});case"profile":return Object.assign({},Vi(e),{method:"profile"});case"saml":return Object.assign({},Wi(e),{method:"saml"});case"totp":return Object.assign({},qi(e),{method:"totp"});case"webauthn":return Object.assign({},Ki(e),{method:"webauthn"});default:throw new Error(`No variant of UpdateSettingsFlowBody exists with 'method=${e.method}'`)}}function Hi(e){return Xi(e,!1)}function Xi(e,t=!1){return e==null?e:{code:e.code,csrf_token:e.csrf_token,email:e.email,method:e.method,transient_payload:e.transient_payload}}function Yi(e){return Zi(e,!1)}function Zi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,email:e.email,method:e.method,transient_payload:e.transient_payload}}function ji(e){return er(e,!1)}function er(e,t=!1){if(e==null)return e;switch(e.method){case"code":return Object.assign({},Hi(e),{method:"code"});case"link":return Object.assign({},Yi(e),{method:"link"});default:throw new Error(`No variant of UpdateVerificationFlowBody exists with 'method=${e.method}'`)}}function he(e){return tr(e)}function tr(e,t){return e==null?e:{active:e.active==null?void 0:e.active,expires_at:e.expires_at==null?void 0:new Date(e.expires_at),id:e.id,issued_at:e.issued_at==null?void 0:new Date(e.issued_at),request_url:e.request_url==null?void 0:e.request_url,return_to:e.return_to==null?void 0:e.return_to,state:e.state,transient_payload:e.transient_payload==null?void 0:e.transient_payload,type:e.type,ui:oe(e.ui)}}const ft={ChooseMethod:"choose_method",SentEmail:"sent_email",PassedChallenge:"passed_challenge",UnknownDefaultOpenApi:"11184809"};class nr extends Me{async createBrowserLoginFlowRaw(t,n){const o={};t.refresh!=null&&(o.refresh=t.refresh),t.aal!=null&&(o.aal=t.aal),t.returnTo!=null&&(o.return_to=t.returnTo),t.loginChallenge!=null&&(o.login_challenge=t.loginChallenge),t.organization!=null&&(o.organization=t.organization),t.via!=null&&(o.via=t.via);const i={};t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/login/browser",method:"GET",headers:i,query:o},n);return new g(r,a=>Ue(a))}async createBrowserLoginFlow(t={},n){return await(await this.createBrowserLoginFlowRaw(t,n)).value()}async createBrowserLogoutFlowRaw(t,n){const o={};t.returnTo!=null&&(o.return_to=t.returnTo);const i={};t.cookie!=null&&(i.cookie=String(t.cookie));const r=await this.request({path:"/self-service/logout/browser",method:"GET",headers:i,query:o},n);return new g(r,a=>Co(a))}async createBrowserLogoutFlow(t={},n){return await(await this.createBrowserLogoutFlowRaw(t,n)).value()}async createBrowserRecoveryFlowRaw(t,n){const o={};t.returnTo!=null&&(o.return_to=t.returnTo);const i={},r=await this.request({path:"/self-service/recovery/browser",method:"GET",headers:i,query:o},n);return new g(r,a=>de(a))}async createBrowserRecoveryFlow(t={},n){return await(await this.createBrowserRecoveryFlowRaw(t,n)).value()}async createBrowserRegistrationFlowRaw(t,n){const o={};t.returnTo!=null&&(o.return_to=t.returnTo),t.loginChallenge!=null&&(o.login_challenge=t.loginChallenge),t.afterVerificationReturnTo!=null&&(o.after_verification_return_to=t.afterVerificationReturnTo),t.organization!=null&&(o.organization=t.organization);const i={},r=await this.request({path:"/self-service/registration/browser",method:"GET",headers:i,query:o},n);return new g(r,a=>Ae(a))}async createBrowserRegistrationFlow(t={},n){return await(await this.createBrowserRegistrationFlowRaw(t,n)).value()}async createBrowserSettingsFlowRaw(t,n){const o={};t.returnTo!=null&&(o.return_to=t.returnTo);const i={};t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/settings/browser",method:"GET",headers:i,query:o},n);return new g(r,a=>we(a))}async createBrowserSettingsFlow(t={},n){return await(await this.createBrowserSettingsFlowRaw(t,n)).value()}async createBrowserVerificationFlowRaw(t,n){const o={};t.returnTo!=null&&(o.return_to=t.returnTo);const i={},r=await this.request({path:"/self-service/verification/browser",method:"GET",headers:i,query:o},n);return new g(r,a=>he(a))}async createBrowserVerificationFlow(t={},n){return await(await this.createBrowserVerificationFlowRaw(t,n)).value()}async createFedcmFlowRaw(t){const n={},o={},i=await this.request({path:"/self-service/fed-cm/parameters",method:"GET",headers:o,query:n},t);return new g(i,r=>Pn(r))}async createFedcmFlow(t){return await(await this.createFedcmFlowRaw(t)).value()}async createNativeLoginFlowRaw(t,n){const o={};t.refresh!=null&&(o.refresh=t.refresh),t.aal!=null&&(o.aal=t.aal),t.returnSessionTokenExchangeCode!=null&&(o.return_session_token_exchange_code=t.returnSessionTokenExchangeCode),t.returnTo!=null&&(o.return_to=t.returnTo),t.organization!=null&&(o.organization=t.organization),t.via!=null&&(o.via=t.via);const i={};t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken));const r=await this.request({path:"/self-service/login/api",method:"GET",headers:i,query:o},n);return new g(r,a=>Ue(a))}async createNativeLoginFlow(t={},n){return await(await this.createNativeLoginFlowRaw(t,n)).value()}async createNativeRecoveryFlowRaw(t){const n={},o={},i=await this.request({path:"/self-service/recovery/api",method:"GET",headers:o,query:n},t);return new g(i,r=>de(r))}async createNativeRecoveryFlow(t){return await(await this.createNativeRecoveryFlowRaw(t)).value()}async createNativeRegistrationFlowRaw(t,n){const o={};t.returnSessionTokenExchangeCode!=null&&(o.return_session_token_exchange_code=t.returnSessionTokenExchangeCode),t.returnTo!=null&&(o.return_to=t.returnTo),t.organization!=null&&(o.organization=t.organization);const i={},r=await this.request({path:"/self-service/registration/api",method:"GET",headers:i,query:o},n);return new g(r,a=>Ae(a))}async createNativeRegistrationFlow(t={},n){return await(await this.createNativeRegistrationFlowRaw(t,n)).value()}async createNativeSettingsFlowRaw(t,n){const o={},i={};t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken));const r=await this.request({path:"/self-service/settings/api",method:"GET",headers:i,query:o},n);return new g(r,a=>we(a))}async createNativeSettingsFlow(t={},n){return await(await this.createNativeSettingsFlowRaw(t,n)).value()}async createNativeVerificationFlowRaw(t,n){const o={};t.returnTo!=null&&(o.return_to=t.returnTo);const i={},r=await this.request({path:"/self-service/verification/api",method:"GET",headers:i,query:o},n);return new g(r,a=>he(a))}async createNativeVerificationFlow(t={},n){return await(await this.createNativeVerificationFlowRaw(t,n)).value()}async disableMyOtherSessionsRaw(t,n){const o={},i={};t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken)),t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/sessions",method:"DELETE",headers:i,query:o},n);return new g(r,a=>zn(a))}async disableMyOtherSessions(t={},n){return await(await this.disableMyOtherSessionsRaw(t,n)).value()}async disableMySessionRaw(t,n){if(t.id==null)throw new S("id",'Required parameter "id" was null or undefined when calling disableMySession().');const o={},i={};t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken)),t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/sessions/{id}".replace("{id}",encodeURIComponent(String(t.id))),method:"DELETE",headers:i,query:o},n);return new De(r)}async disableMySession(t,n){await this.disableMySessionRaw(t,n)}async exchangeSessionTokenRaw(t,n){if(t.initCode==null)throw new S("initCode",'Required parameter "initCode" was null or undefined when calling exchangeSessionToken().');if(t.returnToCode==null)throw new S("returnToCode",'Required parameter "returnToCode" was null or undefined when calling exchangeSessionToken().');const o={};t.initCode!=null&&(o.init_code=t.initCode),t.returnToCode!=null&&(o.return_to_code=t.returnToCode);const i={},r=await this.request({path:"/sessions/token-exchange",method:"GET",headers:i,query:o},n);return new g(r,a=>Le(a))}async exchangeSessionToken(t,n){return await(await this.exchangeSessionTokenRaw(t,n)).value()}async getFlowErrorRaw(t,n){if(t.id==null)throw new S("id",'Required parameter "id" was null or undefined when calling getFlowError().');const o={};t.id!=null&&(o.id=t.id);const i={},r=await this.request({path:"/self-service/errors",method:"GET",headers:i,query:o},n);return new g(r,a=>Qn(a))}async getFlowError(t,n){return await(await this.getFlowErrorRaw(t,n)).value()}async getLoginFlowRaw(t,n){if(t.id==null)throw new S("id",'Required parameter "id" was null or undefined when calling getLoginFlow().');const o={};t.id!=null&&(o.id=t.id);const i={};t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/login/flows",method:"GET",headers:i,query:o},n);return new g(r,a=>Ue(a))}async getLoginFlow(t,n){return await(await this.getLoginFlowRaw(t,n)).value()}async getRecoveryFlowRaw(t,n){if(t.id==null)throw new S("id",'Required parameter "id" was null or undefined when calling getRecoveryFlow().');const o={};t.id!=null&&(o.id=t.id);const i={};t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/recovery/flows",method:"GET",headers:i,query:o},n);return new g(r,a=>de(a))}async getRecoveryFlow(t,n){return await(await this.getRecoveryFlowRaw(t,n)).value()}async getRegistrationFlowRaw(t,n){if(t.id==null)throw new S("id",'Required parameter "id" was null or undefined when calling getRegistrationFlow().');const o={};t.id!=null&&(o.id=t.id);const i={};t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/registration/flows",method:"GET",headers:i,query:o},n);return new g(r,a=>Ae(a))}async getRegistrationFlow(t,n){return await(await this.getRegistrationFlowRaw(t,n)).value()}async getSettingsFlowRaw(t,n){if(t.id==null)throw new S("id",'Required parameter "id" was null or undefined when calling getSettingsFlow().');const o={};t.id!=null&&(o.id=t.id);const i={};t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken)),t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/settings/flows",method:"GET",headers:i,query:o},n);return new g(r,a=>we(a))}async getSettingsFlow(t,n){return await(await this.getSettingsFlowRaw(t,n)).value()}async getVerificationFlowRaw(t,n){if(t.id==null)throw new S("id",'Required parameter "id" was null or undefined when calling getVerificationFlow().');const o={};t.id!=null&&(o.id=t.id);const i={};t.cookie!=null&&(i.cookie=String(t.cookie));const r=await this.request({path:"/self-service/verification/flows",method:"GET",headers:i,query:o},n);return new g(r,a=>he(a))}async getVerificationFlow(t,n){return await(await this.getVerificationFlowRaw(t,n)).value()}async getWebAuthnJavaScriptRaw(t){const n={},o={},i=await this.request({path:"/.well-known/ory/webauthn.js",method:"GET",headers:o,query:n},t);return this.isJsonMime(i.headers.get("content-type"))?new g(i):new bn(i)}async getWebAuthnJavaScript(t){return await(await this.getWebAuthnJavaScriptRaw(t)).value()}async listMySessionsRaw(t,n){const o={};t.perPage!=null&&(o.per_page=t.perPage),t.page!=null&&(o.page=t.page),t.pageSize!=null&&(o.page_size=t.pageSize),t.pageToken!=null&&(o.page_token=t.pageToken);const i={};t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken)),t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/sessions",method:"GET",headers:i,query:o},n);return new g(r,a=>a.map(fe))}async listMySessions(t={},n){return await(await this.listMySessionsRaw(t,n)).value()}async performNativeLogoutRaw(t,n){if(t.performNativeLogoutBody==null)throw new S("performNativeLogoutBody",'Required parameter "performNativeLogoutBody" was null or undefined when calling performNativeLogout().');const o={},i={};i["Content-Type"]="application/json";const r=await this.request({path:"/self-service/logout/api",method:"DELETE",headers:i,query:o,body:To(t.performNativeLogoutBody)},n);return new De(r)}async performNativeLogout(t,n){await this.performNativeLogoutRaw(t,n)}async toSessionRaw(t,n){const o={};t.tokenizeAs!=null&&(o.tokenize_as=t.tokenizeAs);const i={};t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken)),t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/sessions/whoami",method:"GET",headers:i,query:o},n);return new g(r,a=>fe(a))}async toSession(t={},n){return await(await this.toSessionRaw(t,n)).value()}async updateFedcmFlowRaw(t,n){if(t.updateFedcmFlowBody==null)throw new S("updateFedcmFlowBody",'Required parameter "updateFedcmFlowBody" was null or undefined when calling updateFedcmFlow().');const o={},i={};i["Content-Type"]="application/json";const r=await this.request({path:"/self-service/fed-cm/token",method:"POST",headers:i,query:o,body:Wo(t.updateFedcmFlowBody)},n);return new g(r,a=>Le(a))}async updateFedcmFlow(t,n){return await(await this.updateFedcmFlowRaw(t,n)).value()}async updateLoginFlowRaw(t,n){if(t.flow==null)throw new S("flow",'Required parameter "flow" was null or undefined when calling updateLoginFlow().');if(t.updateLoginFlowBody==null)throw new S("updateLoginFlowBody",'Required parameter "updateLoginFlowBody" was null or undefined when calling updateLoginFlow().');const o={};t.flow!=null&&(o.flow=t.flow);const i={};i["Content-Type"]="application/json",t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken)),t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/login",method:"POST",headers:i,query:o,body:si(t.updateLoginFlowBody)},n);return new g(r,a=>Le(a))}async updateLoginFlow(t,n){return await(await this.updateLoginFlowRaw(t,n)).value()}async updateLogoutFlowRaw(t,n){const o={};t.token!=null&&(o.token=t.token),t.returnTo!=null&&(o.return_to=t.returnTo);const i={};t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/logout",method:"GET",headers:i,query:o},n);return new De(r)}async updateLogoutFlow(t={},n){await this.updateLogoutFlowRaw(t,n)}async updateRecoveryFlowRaw(t,n){if(t.flow==null)throw new S("flow",'Required parameter "flow" was null or undefined when calling updateRecoveryFlow().');if(t.updateRecoveryFlowBody==null)throw new S("updateRecoveryFlowBody",'Required parameter "updateRecoveryFlowBody" was null or undefined when calling updateRecoveryFlow().');const o={};t.flow!=null&&(o.flow=t.flow),t.token!=null&&(o.token=t.token);const i={};i["Content-Type"]="application/json",t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/recovery",method:"POST",headers:i,query:o,body:wi(t.updateRecoveryFlowBody)},n);return new g(r,a=>de(a))}async updateRecoveryFlow(t,n){return await(await this.updateRecoveryFlowRaw(t,n)).value()}async updateRegistrationFlowRaw(t,n){if(t.flow==null)throw new S("flow",'Required parameter "flow" was null or undefined when calling updateRegistrationFlow().');if(t.updateRegistrationFlowBody==null)throw new S("updateRegistrationFlowBody",'Required parameter "updateRegistrationFlowBody" was null or undefined when calling updateRegistrationFlow().');const o={};t.flow!=null&&(o.flow=t.flow);const i={};i["Content-Type"]="application/json",t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/registration",method:"POST",headers:i,query:o,body:Ni(t.updateRegistrationFlowBody)},n);return new g(r,a=>Vo(a))}async updateRegistrationFlow(t,n){return await(await this.updateRegistrationFlowRaw(t,n)).value()}async updateSettingsFlowRaw(t,n){if(t.flow==null)throw new S("flow",'Required parameter "flow" was null or undefined when calling updateSettingsFlow().');if(t.updateSettingsFlowBody==null)throw new S("updateSettingsFlowBody",'Required parameter "updateSettingsFlowBody" was null or undefined when calling updateSettingsFlow().');const o={};t.flow!=null&&(o.flow=t.flow);const i={};i["Content-Type"]="application/json",t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken)),t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/settings",method:"POST",headers:i,query:o,body:Gi(t.updateSettingsFlowBody)},n);return new g(r,a=>we(a))}async updateSettingsFlow(t,n){return await(await this.updateSettingsFlowRaw(t,n)).value()}async updateVerificationFlowRaw(t,n){if(t.flow==null)throw new S("flow",'Required parameter "flow" was null or undefined when calling updateVerificationFlow().');if(t.updateVerificationFlowBody==null)throw new S("updateVerificationFlowBody",'Required parameter "updateVerificationFlowBody" was null or undefined when calling updateVerificationFlow().');const o={};t.flow!=null&&(o.flow=t.flow),t.token!=null&&(o.token=t.token);const i={};i["Content-Type"]="application/json",t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/verification",method:"POST",headers:i,query:o,body:ji(t.updateVerificationFlowBody)},n);return new g(r,a=>he(a))}async updateVerificationFlow(t,n){return await(await this.updateVerificationFlowRaw(t,n)).value()}}function V(e){return typeof e=="object"&&!!e&&"error"in e&&typeof e.error=="object"&&!!e.error&&"id"in e.error}function or(e){return V(e)&&e.error.id==="session_refresh_required"}function wt(e){return V(e)&&e.error.id==="self_service_flow_expired"}function ir(e){return V(e)&&V(e)&&e.error.id==="browser_location_change_required"}function _e(e){return V(e)&&e.error.id==="session_already_available"}function rr(e){return V(e)&&e.error.id==="session_aal2_required"}function ar(e){return V(e)&&e.error.id==="security_csrf_violation"}const sr=e=>e instanceof Y?!0:typeof e=="object"&&!!e&&"name"in e&&e.name==="ResponseError",B=e=>async t=>{if(sr(t))switch(t.response.status){case 404:e.onRestartFlow();return;case 410:{const n=await pt(t.response);if(wt(n)){e.onRestartFlow(n.use_flow_id);return}e.onRestartFlow();return}case 400:return e.onValidationError(await t.response.json());case 403:case 422:{const n=await pt(t.response);if(ir(n)&&n.redirect_browser_to){e.onRedirect(n.redirect_browser_to,!0);return}else if(wt(n)){e.onRestartFlow(n.use_flow_id);return}else if(or(n)){e.onRedirect(n.redirect_browser_to,!0);return}else if(ar(n)){e.onRestartFlow();return}throw new Y(t.response,"The Ory API endpoint returned a response code the SDK does not know how to handle. Please check the network tab for more information:"+JSON.stringify(n))}default:throw new Y(t.response,"The Ory API endpoint returned a response code the SDK does not know how to handle. Please check the network tab for more information.")}else if(t instanceof Re)throw new Re(t,"Unable to call the API endpoint. Ensure that CORS is set up correctly and that you have provided a valid SDK URL to Ory Elements.");throw t};async function pt(e){try{return await e.clone().json()}catch{throw new Y(e,"The Ory API endpoint returned a response the SDK does not know how to handle:"+await e.text())}}const ht=["show_settings_ui","show_recovery_ui","show_verification_ui","redirect_browser_to","set_ory_session_token"];function Pe(e,{onRedirect:t}){if(!e||e.length===0)return!1;const n=cr(e);if(!n)return!1;const o=(i,r,a)=>a?(t(a,!0),!0):(t("/"+r+"?flow="+i,!1),!0);if(lr(n))throw new Error("Ory Elements does not support API flows yet.");if(ur(n)&&n.redirect_browser_to)return t(n.redirect_browser_to,!0),!0;if(wr(n))return o(n.flow.id,"verification",n.flow.url);if(dr(n))return o(n.flow.id,"recovery",n.flow.url);if(fr(n))return o(n.flow.id,"settings",n.flow.url);throw new Error("Unknown action: "+JSON.stringify(n))}function cr(e){return!e||e.length===0?void 0:e.toSorted((n,o)=>ht.indexOf(n.action)-ht.indexOf(o.action))[0]}function lr(e){return e.action==="set_ory_session_token"}function ur(e){return e.action==="redirect_browser_to"}function dr(e){return e.action==="show_recovery_ui"}function fr(e){return e.action==="show_settings_ui"}function wr(e){return e.action==="show_verification_ui"}function We(e){return e.node_type==="input"}function _t({attributes:e}){return We(e)?e.name:e.id}const gt=e=>!(typeof e!="object"||e===null||!ro(e)||e.type!==io.Error),pr=e=>!(typeof e!="object"||e===null||!("id"in e)||typeof e.id!="string"||"context"in e&&(typeof e.context!="object"||e.context===null)||"originalError"in e&&!gt(e.originalError)),mt=e=>e?.filter(gt).map(_r)??[],C=({onSubmit:e,onChange:t,onBlur:n}={})=>{const o=[...Array.isArray(e)?e:[],...Array.isArray(t)?t:[],...Array.isArray(n)?n:[]].filter(pr);return[...new Map(o.map(i=>[i.id,i])).values()]};var ie=(e=>(e.FieldMismatch="FieldMismatch",e.FieldRequired="FieldRequired",e))(ie||{});const ge=e=>({id:`AdditionalValidationError_${e}`}),hr=e=>{const t=(h,v)=>({id:`${h}_${v}`,originalError:e}),n=(h,v,Q)=>({id:`${h}_${v}_WithContext`,context:Q,originalError:e});return{createGenericError:h=>t("Error",h),createGenericErrorWithContext:(h,v)=>n("Error",h,v),createLoginFlowError:h=>t("LoginFlowError",h),createLoginFlowErrorWithContext:(h,v)=>n("LoginFlowError",h,v),createRegisterFlowError:h=>t("RegisterFlowError",h),createRegisterFlowErrorWithContext:(h,v)=>n("RegisterFlowError",h,v),createSettingsFlowError:h=>t("SettingsFlowError",h),createSettingsFlowErrorWithContext:(h,v)=>n("SettingsFlowError",h,v),createRecoveryFlowError:h=>t("RecoveryFlowError",h),createRecoveryFlowErrorWithContext:(h,v)=>n("RecoveryFlowError",h,v),createVerificationFlowError:h=>t("VerificationFlowError",h),createVerificationFlowErrorWithContext:(h,v)=>n("VerificationFlowError",h,v)}},_r=e=>{const{createGenericError:t,createGenericErrorWithContext:n,createLoginFlowError:o,createLoginFlowErrorWithContext:i,createRegisterFlowError:r,createRegisterFlowErrorWithContext:a,createSettingsFlowError:c,createSettingsFlowErrorWithContext:u,createRecoveryFlowError:w,createRecoveryFlowErrorWithContext:f,createVerificationFlowError:d,createVerificationFlowErrorWithContext:_}=hr(e);switch(e.id){case 4000001:return p(e.context,"reason","string")?n("InvalidFormat",{reason:e.context.reason}):t("InvalidFormat");case 4000002:return p(e.context,"property","string")?n("MissingProperty",{property:e.context.property}):t("MissingProperty");case 4000003:return p(e.context,"min_length","number")&&p(e.context,"actual_length","number")?n("TooShort",{min_length:e.context.min_length,actual_length:e.context.actual_length}):t("TooShort");case 4000004:return p(e.context,"pattern","string")?n("InvalidPattern",{pattern:e.context.pattern}):t("InvalidPattern");case 4000005:return p(e.context,"reason","string")?n("PasswordPolicyViolation",{reason:e.context.reason}):t("PasswordPolicyViolation");case 4000006:return t("InvalidCredentials");case 4000007:return t("DuplicateCredentials");case 4000008:return t("TOTPVerifierWrong");case 4000009:return t("IdentifierMissing");case 4000010:return t("AddressNotVerified");case 4000011:return t("NoTOTPDeviceSetUp");case 4000012:return t("RecoveryCodeAlreadyUsed");case 4000013:return t("NoWebAuthnDeviceSetUp");case 4000014:return t("NoRecoveryCodesSetUp");case 4000015:return t("AccountNotExistsOrHasSecurityKey");case 4000016:return t("InvalidRecoveryCode");case 4000017:return p(e.context,"max_length","number")&&p(e.context,"actual_length","number")?n("TooLong",{max_length:e.context.max_length,actual_length:e.context.actual_length}):t("TooLong");case 4000018:return p(e.context,"actual","number")&&p(e.context,"minimum","number")?n("MustBeGreaterOrEqualThan",{actual:e.context.actual,minimum:e.context.minimum}):t("MustBeGreaterOrEqualThan");case 4000019:return p(e.context,"actual","number")&&p(e.context,"minimum","number")?n("MustBeGreaterThan",{actual:e.context.actual,minimum:e.context.minimum}):t("MustBeGreaterThan");case 4000020:return p(e.context,"actual","number")&&p(e.context,"maximum","number")?n("MustBeLessOrEqualThan",{actual:e.context.actual,maximum:e.context.maximum}):t("MustBeLessOrEqualThan");case 4000021:return p(e.context,"actual","number")&&p(e.context,"maximum","number")?n("MustBeLessThan",{actual:e.context.actual,maximum:e.context.maximum}):t("MustBeLessThan");case 4000022:return p(e.context,"actual","number")&&p(e.context,"base","number")?n("IsNotMultipleOf",{actual:e.context.actual,base:e.context.base}):t("IsNotMultipleOf");case 4000023:return p(e.context,"max_items","number")&&p(e.context,"actual_items","number")?n("TooManyItems",{max_items:e.context.max_items,actual_items:e.context.actual_items}):t("TooManyItems");case 4000024:return p(e.context,"min_items","number")&&p(e.context,"actual_items","number")?n("TooFewItems",{min_items:e.context.min_items,actual_items:e.context.actual_items}):t("TooFewItems");case 4000025:return p(e.context,"index_a","number")&&p(e.context,"index_b","number")?n("DuplicateItems",{index_a:e.context.index_a,index_b:e.context.index_b}):t("DuplicateItems");case 4000026:return p(e.context,"actual_type","string")&&p(e.context,"allowed_types","object")&&Array.isArray(e.context.allowed_types)&&e.context.allowed_types.every(F=>typeof F=="string")?n("InvalidType",{actual_type:e.context.actual_type,allowed_types:e.context.allowed_types}):t("InvalidType");case 4000027:return t("AccountAlreadyExists");case 4000028:return p(e.context,"credential_identifier_hint","string")&&p(e.context,"available_credential_types","object")&&Array.isArray(e.context.available_credential_types)&&e.context.available_credential_types.every(F=>typeof F=="string")&&p(e.context,"available_oidc_providers","object")&&Array.isArray(e.context.available_oidc_providers)&&e.context.available_oidc_providers.every(F=>typeof F=="string")?n("CredentialIdentifierHintAlreadyUsedByOtherAccount",{available_credential_types:e.context.available_credential_types,available_oidc_providers:e.context.available_oidc_providers,credential_identifier_hint:e.context.credential_identifier_hint}):t("CredentialIdentifierHintAlreadyUsedByOtherAccount");case 4000029:return p(e.context,"expected","string")?n("MustBeEqualTo",{expected:e.context.expected}):t("MustBeEqualTo");case 4000030:return t("ConstFailed");case 4000031:return t("PasswordAndIdentifierTooSimilar");case 4000032:return p(e.context,"min_length","number")&&p(e.context,"actual_length","number")?n("PasswordTooShort",{min_length:e.context.min_length,actual_length:e.context.actual_length}):t("PasswordTooShort");case 4000033:return p(e.context,"max_length","number")&&p(e.context,"actual_length","number")?n("PasswordTooLong",{max_length:e.context.max_length,actual_length:e.context.actual_length}):t("PasswordTooLong");case 4000034:return p(e.context,"breaches","number")?n("PasswordLeaked",{breaches:e.context.breaches}):t("PasswordLeaked");case 4000035:return t("AccountNotExistsOrWithoutCodeSignIn");case 4000036:return t("TraitsDoNotMatch");case 4000037:return t("AccountNotExistsOrWithoutLoginMethod");case 4000038:return t("CaptchaFailed");case 4010001:return p(e.context,"expired_at","string")&&p(e.context,"expired_at_unix","number")?i("LoginFlowExpired",{expired_at:e.context.expired_at,expired_at_unix:e.context.expired_at_unix}):o("LoginFlowExpired");case 4010002:return o("NoLogInStrategyFound");case 4010003:return o("NoSignUpStrategyFound");case 4010004:return o("NoSettingsStrategyFound");case 4010005:return o("NoRecoveryStrategyFound");case 4010006:return o("NoVerificationStrategyFound");case 4010007:return o("LoginRequestAlreadyCompletedSuccessfully");case 4010008:return o("InvalidLoginCodeOrAlreadyUsed");case 4010009:return o("MismatchedLinkedCretentials");case 4010010:return o("MismatchedAddress");case 4040001:return p(e.context,"expired_at","string")&&p(e.context,"expired_at_unix","number")?a("RegisterFlowExpired",{expired_at:e.context.expired_at,expired_at_unix:e.context.expired_at_unix}):r("RegisterFlowExpired");case 4040002:return r("RegisterRequestAlreadyCompletedSuccessfully");case 4040003:return r("InvalidRegisterCodeOrAlreadyUsed");case 4050001:return p(e.context,"expired_at","string")&&p(e.context,"expired_at_unix","number")?u("SettingsFlowExpired",{expired_at:e.context.expired_at,expired_at_unix:e.context.expired_at_unix}):c("SettingsFlowExpired");case 4060001:return w("RecoveryRequestAlreadyCompletedSuccessfully");case 4060002:return w("RecoveryFlowFailureState");case 4060004:return w("InvalidTokenOrAlreadyUsed");case 4060005:return p(e.context,"expired_at","string")&&p(e.context,"expired_at_unix","number")?f("RecoveryFlowExpired",{expired_at:e.context.expired_at,expired_at_unix:e.context.expired_at_unix}):w("RecoveryFlowExpired");case 4060006:return w("InvalidRecoveryCodeOrAlreadyUsed");case 4070001:return d("InvalidVerificationTokenOrAlreadyUsed");case 4070002:return d("VerificationRequestAlreadyCompletedSuccessfully");case 4070003:return d("VerificationFlowFailureState");case 4070005:return p(e.context,"expired_at","string")&&p(e.context,"expired_at_unix","number")?_("VerificationFlowExpired",{expired_at:e.context.expired_at,expired_at_unix:e.context.expired_at_unix}):d("VerificationFlowExpired");case 4070006:return d("InvalidVerificationCodeOrAlreadyUsed");default:return p(e.context,"reason","string")?n("Generic",{reason:e.context.reason}):t("Generic")}};function O(e,t){return e?.find(n=>_t(n)===t)}function gr(e,t){return e?.filter(n=>_t(n)===t)??[]}function $(e){if(e&&We(e.attributes))return e.attributes}function mr(e){if(e&&We(e.attributes))return e.messages}function k(e){const t=$(O(e.ui.nodes,"csrf_token"));if(!t||typeof t.value!="string")throw new Error("CSRF token not found");return t.value}const yr=e=>{if(e.group!==yo.Passkey||e.type!==Fo.Input||e.attributes.node_type!==po.Input||e.attributes.name!=="passkey_remove"||!e.meta?.label?.context)return!1;const{context:t}=e.meta.label;return"added_at"in t&&typeof t.added_at=="string"&&"display_name"in t&&typeof t.display_name=="string"&&"added_at_unix"in t&&typeof t.added_at_unix=="number"},yt=e=>e.group==="oidc"&&e.attributes.node_type==="input"&&typeof e.attributes.value=="string",Fr=(e,t)=>e?.find(n=>yt(n)&&n.attributes.value===t)??void 0,Be=e=>e?.filter(t=>yt(t))??[],qe=(e,t)=>e!==void 0&&e.some(n=>n.id===t),re=async({error:e})=>await B({onRedirect:(t,n)=>{globalThis.location.href=t},onRestartFlow:()=>{throw new Error("Needs to restart the flow",{cause:P.FlowRestartRequired})},onValidationError:t=>t})(e),N=(e,t,n)=>{const o=mt(e.ui.messages);o.length>0&&(t.setErrorMap({onSubmit:o}),n?.({target:"root",errors:o}));for(const i in t.fieldInfo){const r=i,a=mt(mr(O(e.ui.nodes,r)));a.length>0&&(t.setFieldMeta(r,c=>({...c,errorMap:{onSubmit:a}})),n?.({target:r,errors:a}))}},$e="leancode_kratos",K=e=>[$e,...e],z=e=>`${$e}_${e}`;function I(e){return l.useMemo(()=>C(e.state.errorMap),[e.state.errorMap])}const Ft=l.createContext(void 0);function x(){const e=l.useContext(Ft);if(e===void 0)throw new Error("useKratosClientContext must be used within a KratosClientContextProvider");return e}function vr({children:e,api:t}){const n=l.useMemo(()=>({kratosClient:t}),[t]);return s.jsx(Ft.Provider,{value:n,children:e})}function E({children:e}){const t=y.Root;return s.jsx(t,{type:"submit",children:e})}const vt=l.createContext(void 0);function Sr({children:e,emailVerificationForm:t}){const n=l.useMemo(()=>({emailVerificationForm:t}),[t]);return s.jsx(vt.Provider,{value:n,children:e})}function kr(){const e=l.useContext(vt);if(e===void 0)throw new Error("useEmailVerificationFormContext must be used within a EmailVerificationFormProvider");return e}const br=z("verification_flow"),me=(e="no_id")=>K([br,e]),St=l.createContext(void 0);function ye({children:e}){const[t,n]=l.useState(),[o,i]=l.useState(),r=l.useCallback(()=>{n(void 0),i(void 0)},[]);return s.jsx(St.Provider,{value:{verificationFlowId:t,setVerificationFlowId:n,verifiableAddress:o,setVerifiableAddress:i,resetFlow:r},children:e})}function J(){const e=l.useContext(St);if(e===void 0)throw new Error("useVerificationFlow must be used within a VerificationFlowProvider");return e}function Cr({returnTo:e}={}){const{kratosClient:t}=x(),{setVerificationFlowId:n}=J(),o=m.useQueryClient();return m.useMutation({mutationFn:()=>t.createBrowserVerificationFlow({returnTo:e},async({init:{headers:i}})=>({headers:{...i,Accept:"application/json"}})),onSuccess(i){o.setQueryDefaults(me(i.id),{staleTime:1/0}),o.setQueryData(me(i.id),i),n(i.id)}})}function Ke(){const{kratosClient:e}=x(),{verificationFlowId:t}=J();return m.useQuery({queryKey:me(t),queryFn:async({signal:n})=>{if(!t)throw new Error("No verification flow ID provided",{cause:P.NoFlowId});try{return await e.getVerificationFlow({id:t},async({init:{headers:o}})=>({signal:n,headers:{...o,Accept:"application/json"}}))}catch(o){throw await re({error:o})}},enabled:!!t,staleTime:1/0})}function kt(){const{kratosClient:e}=x(),{verificationFlowId:t,resetFlow:n}=J(),o=m.useQueryClient();return m.useMutation({mutationFn:async i=>{if(!t)throw new Error("Verification flow ID is not set");try{const r=await e.updateVerificationFlow({flow:t,updateVerificationFlowBody:i},{headers:{Accept:"application/json","Content-Type":"application/json"}});return r.state===ft.PassedChallenge&&r.return_to&&(globalThis.location.href=r.return_to),r}catch(r){return await B({onRedirect:(a,c)=>{globalThis.location.href=a},onRestartFlow:n,onValidationError:a=>a})(r)}},onSuccess(i){i&&"id"in i&&o.setQueryData(me(i.id),i)}})}function xr({children:e}){const{verifiableAddress:t}=J(),{mutate:n}=kt(),{data:o}=Ke(),i=l.useCallback(()=>{!o||!t||n({method:"code",csrf_token:k(o),email:t,code:""})},[o,t,n]),r=y.Root;return s.jsx(r,{type:"button",onClick:i,children:e})}function Tr({children:e}){const{emailVerificationForm:t}=kr(),n=y.Root;return s.jsx(t.Field,{name:"code",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"text",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}var bt=(e=>(e.Code="code",e))(bt||{});function Or({onError:e,onVerificationSuccess:t}){const{verifiableAddress:n}=J(),{mutateAsync:o}=kt(),{data:i}=Ke();return D.useForm({defaultValues:{[bt.Code]:""},onSubmit:async({value:r,formApi:a})=>{if(!i||!n)return;const c=await o({csrf_token:k(i),method:"code",code:r.code,email:n});if(c){if(c.state==ft.PassedChallenge){t?.();return}N(c,a,e)}}})}function Nr({emailVerificationForm:e,onError:t,onVerificationSuccess:n}){const o=Or({onError:t,onVerificationSuccess:n}),i=I(o);return s.jsx(Sr,{emailVerificationForm:o,children:s.jsx("form",{onSubmit:r=>{r.preventDefault(),o.handleSubmit()},children:s.jsx(e,{Code:Tr,errors:i,isSubmitting:o.state.isSubmitting,isValidating:o.state.isValidating,Resend:xr,Submit:E})})})}function Ct(e){return s.jsx(ye,{children:s.jsx(Fe,{...e})})}function Fe({emailVerificationForm:e,initialFlowId:t,initialVerifiableAddress:n,returnTo:o,onError:i,onVerificationSuccess:r,onFlowRestart:a}){const{verificationFlowId:c,setVerificationFlowId:u,verifiableAddress:w,setVerifiableAddress:f}=J(),{error:d}=Ke(),{mutate:_}=Cr({returnTo:o});return ne({initialFlowId:t,currentFlowId:c,error:d,onFlowRestart:a,createFlow:_,setFlowId:u}),!w&&n&&f(n),s.jsx(Nr,{emailVerificationForm:e,onError:i,onVerificationSuccess:r})}const Er=Object.freeze(Object.defineProperty({__proto__:null,VerificationFlow:Ct,VerificationFlowProvider:ye,VerificationFlowWrapper:Fe,useVerificationFlowContext:J},Symbol.toStringTag,{value:"Module"})),Mr=z("login_flow"),ve=(e="no_id")=>K([Mr,e]),xt=l.createContext(void 0);function Rr({children:e}){const[t,n]=l.useState(),o=l.useCallback(()=>{n(void 0)},[]);return s.jsx(xt.Provider,{value:{loginFlowId:t,setLoginFlowId:n,resetFlow:o},children:e})}function Se(){const e=l.useContext(xt);if(e===void 0)throw new Error("useLoginFlowContext must be used within a LoginFlow");return e}function Dr({aal:e,refresh:t,returnTo:n}={}){const{kratosClient:o}=x(),{setLoginFlowId:i}=Se(),r=m.useQueryClient();return m.useMutation({mutationFn:async()=>{try{return await o.createBrowserLoginFlow({aal:e,refresh:t,returnTo:n},async({init:{headers:a}})=>({headers:{...a,Accept:"application/json"}}))}catch(a){throw await B({onRestartFlow:()=>{},onRedirect:()=>{},onValidationError:c=>c})(a)}},onSuccess(a){r.setQueryDefaults(ve(a.id),{staleTime:1/0}),r.setQueryData(ve(a.id),a),i(a.id)}})}function U(){const{kratosClient:e}=x(),{loginFlowId:t}=Se();return m.useQuery({queryKey:ve(t),queryFn:async({signal:n})=>{if(!t)throw new Error("No login flow ID provided",{cause:P.NoFlowId});try{return await e.getLoginFlow({id:t},async({init:{headers:o}})=>({signal:n,headers:{...o,Accept:"application/json"}}))}catch(o){throw await re({error:o})}},enabled:!!t,staleTime:1/0})}const Tt=()=>{const{data:e}=U();return l.useMemo(()=>{if(!e)return;const t=O(e.ui.nodes,"identifier");if(!(!t||t.attributes.node_type!=="input"||typeof t.attributes.value!="string"))return t.attributes.value},[e])};function G(){const{kratosClient:e}=x(),{loginFlowId:t,resetFlow:n}=Se(),{setVerificationFlowId:o,setVerifiableAddress:i}=J(),r=m.useQueryClient();return m.useMutation({mutationFn:async a=>{if(!t)throw new Error("Login flow ID is not set");try{const u=await(await e.updateLoginFlowRaw({flow:t,updateLoginFlowBody:a},{headers:{Accept:"application/json","Content-Type":"application/json"}})).value();if(u&&"continue_with"in u){const w=u.continue_with?.find(f=>f.action==="show_verification_ui");w!==void 0?(o(w.flow.id),i(w.flow.verifiable_address)):Pe(u.continue_with,{onRedirect:(f,d)=>{globalThis.location.href=f}})}return u}catch(c){return await B({onRedirect:(u,w)=>{globalThis.location.href=u},onRestartFlow:n,onValidationError:u=>u})(c)}},onSuccess(a){a&&"id"in a&&r.setQueryData(ve(a.id),a)}})}const Ot=l.createContext(void 0);function Ir({children:e,passwordForm:t}){const n=l.useMemo(()=>({passwordForm:t}),[t]);return s.jsx(Ot.Provider,{value:n,children:e})}function ze(){const e=l.useContext(Ot);if(e===void 0)throw new Error("useChooseMethodFormContext must be used within a ChooseMethodFormProvider");return e}function Jr({children:e,provider:t}){const{mutate:n}=G(),{data:o}=U(),i=l.useCallback(()=>{o&&n({method:"oidc",csrf_token:k(o),provider:t})},[o,n,t]),r=y.Root;return s.jsx(r,{type:"button",onClick:i,children:e})}function Ur({children:e}){const{passwordForm:t}=ze(),n=y.Root;return s.jsx(t.Field,{name:"identifier",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"text",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}function Nt({children:e}){const{passwordForm:t}=ze(),n=y.Root;return s.jsx(t.Field,{name:"password",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"password",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}function Ar({children:e,onError:t,onLoginSuccess:n}){const{mutateAsync:o}=G(),{data:i}=U(),{passwordForm:r}=ze(),a=l.useCallback(async d=>{if(!i)return;const _=await o({method:"passkey",csrf_token:k(i),passkey_login:d});if(_){if(pe(_)){n?.();return}N(_,r,t)}},[i,t,n,r,o]),c=l.useMemo(()=>$(O(i?.ui.nodes,"passkey_challenge")),[i?.ui.nodes]),u=l.useMemo(()=>K([z("passkey"),c?.value]),[c?.value]);m.useQuery({queryKey:u,queryFn:async({signal:d})=>{if(!c)throw new Error("No challenge provided");const _=await hn(c.value,d);return _?await a(_):!1},enabled:!!c,retry:!1});const w=l.useCallback(async()=>{if(!c)return;const d=await _n(c.value);d&&a(d)},[c,a]),f=y.Root;return s.jsx(f,{type:"button",onClick:w,children:e})}var ae=(e=>(e.Identifier="identifier",e.Password="password",e))(ae||{});function Lr({onError:e,onLoginSuccess:t}){const{mutateAsync:n}=G(),{data:o}=U(),i=Tt();return D.useForm({defaultValues:{[ae.Identifier]:i??"",[ae.Password]:""},onSubmit:async({value:r,formApi:a})=>{if(!o)return;const c=await n({csrf_token:k(o),method:"password",identifier:r[ae.Identifier],password:r[ae.Password]});if(c){if(pe(c)){t?.();return}N(c,a,e)}}})}function Vr({chooseMethodForm:e,oidcProvidersConfig:t,isRefresh:n,onError:o,onLoginSuccess:i}){const{data:r}=U(),a=Lr({onError:o,onLoginSuccess:i}),c=I(a),u=Tt(),w=l.useCallback(d=>s.jsx(Ar,{...d,onError:o}),[o]),f=l.useMemo(()=>{if(!r)return{};const d=Be(r.ui.nodes),_={};return d.forEach(F=>{const T=F.attributes.value;if(!qe(t,T))return;const h=Ne.toUpperFirst(T);_[h]=({children:v})=>s.jsx(Jr,{provider:T,children:v})}),_},[r,t]);return r?s.jsx(Ir,{passwordForm:a,children:s.jsx("form",{onSubmit:d=>{d.preventDefault(),a.handleSubmit()},children:n?s.jsx(e,{isRefresh:!0,errors:c,identifier:u,isSubmitting:a.state.isSubmitting,isValidating:a.state.isValidating,oidcProviders:f,Passkey:O(r.ui.nodes,"passkey_login")&&w,passwordFields:O(r.ui.nodes,"password")?{Password:Nt,Submit:E}:void 0}):s.jsx(e,{errors:c,isSubmitting:a.state.isSubmitting,isValidating:a.state.isValidating,oidcProviders:f,Passkey:w,passwordFields:{Identifier:Ur,Password:Nt,Submit:E}})})}):null}function Pr({children:e}){const{mutate:t}=G(),{data:n}=U(),o=l.useCallback(()=>{if(!n)return;const r=$(O(n.ui.nodes,"identifier"))?.value;t({method:"code",csrf_token:k(n),resend:"code",identifier:r})},[n,t]),i=y.Root;return s.jsx(i,{type:"button",onClick:o,children:e})}const Et=l.createContext(void 0);function Wr({children:e,codeForm:t}){const n=l.useMemo(()=>({codeForm:t}),[t]);return s.jsx(Et.Provider,{value:n,children:e})}function Br(){const e=l.useContext(Et);if(e===void 0)throw new Error("useSecondFactorEmailFormContext must be used within a SecondFactorEmailFormProvider");return e}function qr({children:e}){const{codeForm:t}=Br(),n=y.Root;return s.jsx(t.Field,{name:"code",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"text",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}var Mt=(e=>(e.Code="code",e))(Mt||{});function $r({onError:e,onLoginSuccess:t}){const{mutateAsync:n}=G(),{data:o}=U();return D.useForm({defaultValues:{[Mt.Code]:""},onSubmit:async({value:i,formApi:r})=>{if(!o)return;const a=$(O(o.ui.nodes,"identifier"))?.value,c=await n({csrf_token:k(o),method:"code",code:i.code,identifier:a});if(c){if(pe(c)){t?.();return}N(c,r,e)}}})}function Kr({secondFactorForm:e,onError:t,onLoginSuccess:n}){const o=$r({onError:t,onLoginSuccess:n}),i=I(o);return s.jsx(Wr,{codeForm:o,children:s.jsx("form",{onSubmit:r=>{r.preventDefault(),o.handleSubmit()},children:s.jsx(e,{Code:qr,errors:i,isSubmitting:o.state.isSubmitting,isValidating:o.state.isValidating,Resend:Pr,Submit:E})})})}function zr({children:e}){const{mutate:t}=G(),{data:n}=U(),o=l.useCallback(()=>{if(!n)return;const r=$(O(n.ui.nodes,"address"))?.value;r&&t({method:"code",csrf_token:k(n),address:r})},[n,t]),i=y.Root;return s.jsx(i,{type:"button",onClick:o,children:e})}const Rt=l.createContext(void 0),Gr=({children:e,totpForm:t})=>{const n=l.useMemo(()=>({totpForm:t}),[t]);return s.jsx(Rt.Provider,{value:n,children:e})};function Qr(){const e=l.useContext(Rt);if(e===void 0)throw new Error("useSecondFactorFormContext must be used within a SecondFactorFormProvider");return e}function Hr({children:e}){const{totpForm:t}=Qr(),n=y.Root;return s.jsx(t.Field,{name:"totp_code",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"text",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}var Dt=(e=>(e.TotpCode="totp_code",e))(Dt||{});function Xr({onError:e,onLoginSuccess:t}){const{mutateAsync:n}=G(),{data:o}=U();return D.useForm({defaultValues:{[Dt.TotpCode]:""},onSubmit:async({value:i,formApi:r})=>{if(!o)return;const a=await n({csrf_token:k(o),method:"totp",totp_code:i.totp_code});if(a){if(pe(a)){t?.();return}N(a,r,e)}}})}function Yr({secondFactorForm:e,isRefresh:t,onError:n,onLoginSuccess:o}){const i=Xr({onError:n,onLoginSuccess:o}),r=I(i),{data:a}=U();return s.jsx(Gr,{totpForm:i,children:s.jsx("form",{onSubmit:c=>{c.preventDefault(),i.handleSubmit()},children:s.jsx(e,{Email:O(a?.ui.nodes,"address")&&zr,errors:r,isRefresh:t,isSubmitting:i.state.isSubmitting,isValidating:i.state.isValidating,Submit:E,Totp:Hr})})})}function Zr({loaderComponent:e,chooseMethodForm:t,secondFactorForm:n,secondFactorEmailForm:o,emailVerificationForm:i,oidcProvidersConfig:r,initialFlowId:a,returnTo:c,onError:u,onLoginSuccess:w,onVerificationSuccess:f,onFlowRestart:d,onSessionAlreadyAvailable:_}){const{loginFlowId:F,setLoginFlowId:T}=Se(),{verificationFlowId:h}=J(),{sessionManager:v}=Ee(),{isAal2Required:Q}=v.useIsAal2Required(),{mutate:te,error:H}=Dr({returnTo:c,aal:Q?"aal2":void 0}),{data:R,error:et}=U();ne({initialFlowId:a,currentFlowId:F,error:et??void 0,onFlowRestart:d,createFlow:te,setFlowId:T,waitForSession:!0});const Oe=l.useMemo(()=>_e(H)||_e(et),[H,et]);l.useEffect(()=>{Oe&&_?.()},[Oe,_]);const ce=l.useMemo(()=>{if(Oe)return"invalid";if(!R)return"loader";if(h)return"verifyEmail";if(R.state==="choose_method"){if(R.requested_aal==="aal1")return"chooseMethod";if(R.requested_aal==="aal2")return"secondFactor"}if(R.state==="sent_email")return"secondFactorEmail";throw new Error("Invalid login flow state")},[R,h,Oe]),sn=l.useMemo(()=>R?.refresh,[R]);return s.jsxs(s.Fragment,{children:[ce==="loader"&&e&&s.jsx(e,{}),ce==="chooseMethod"&&s.jsx(Vr,{chooseMethodForm:t,isRefresh:sn,oidcProvidersConfig:r,onError:u,onLoginSuccess:w}),ce==="secondFactor"&&s.jsx(Yr,{isRefresh:sn,secondFactorForm:n,onError:u,onLoginSuccess:w}),ce==="secondFactorEmail"&&s.jsx(Kr,{secondFactorForm:o,onError:u,onLoginSuccess:w}),ce==="verifyEmail"&&s.jsx(Fe,{emailVerificationForm:i,onError:u,onVerificationSuccess:f})]})}function It(e){return s.jsx(ye,{children:s.jsx(Rr,{children:s.jsx(Zr,{...e})})})}const jr=Object.freeze(Object.defineProperty({__proto__:null,LoginFlow:It},Symbol.toStringTag,{value:"Module"})),Jt=()=>{const{kratosClient:e}=x(),{sessionManager:t}=Ee(),n=m.useQueryClient();return{logout:async({returnTo:i}={})=>{try{const r=await e.createBrowserLogoutFlow({returnTo:i},async({init:{headers:a}})=>({credentials:"include",headers:{...a,Accept:"application/json","Content-Type":"application/json"}}));return await e.updateLogoutFlow({token:r.logout_token},{headers:{Accept:"application/json","Content-Type":"application/json"}}),t.checkIfLoggedIn(),i&&(globalThis.location.href=i),n.removeQueries({queryKey:[$e]}),{isSuccess:!0}}catch(r){return{isSuccess:!1,error:r}}}}},ea=Object.freeze(Object.defineProperty({__proto__:null,useLogout:Jt},Symbol.toStringTag,{value:"Module"})),Ut=l.createContext(void 0);function ta({children:e,chooseMethodForm:t}){const n=l.useMemo(()=>({chooseMethodForm:t}),[t]);return s.jsx(Ut.Provider,{value:n,children:e})}function Ge(){const e=l.useContext(Ut);if(e===void 0)throw new Error("useChooseMethodFormContext must be used within a ChooseMethodFormProvider");return e}const na=z("registration_flow"),ke=(e="no_id")=>K([na,e]),At=l.createContext(void 0);function oa({children:e}){const[t,n]=l.useState(),[o,i]=l.useState(!1),[r,a]=l.useState(),c=l.useCallback(()=>{n(void 0),i(!1),a(void 0)},[]);return s.jsx(At.Provider,{value:{registrationFlowId:t,setRegistrationFlowId:n,traitsFormCompleted:o,setTraitsFormCompleted:i,traits:r,setTraits:a,resetFlow:c},children:e})}function q(){const e=l.useContext(At);if(e===void 0)throw new Error("useRegistrationFlowContext must be used within a RegistrationFlow");return e}function ia({returnTo:e}={}){const{kratosClient:t}=x(),{setRegistrationFlowId:n}=q(),o=m.useQueryClient();return m.useMutation({mutationFn:async()=>{try{return await t.createBrowserRegistrationFlow({returnTo:e},async({init:{headers:i}})=>({headers:{...i,Accept:"application/json"}}))}catch(i){throw await B({onRestartFlow:()=>{},onRedirect:()=>{},onValidationError:r=>r})(i)}},onSuccess(i){o.setQueryDefaults(ke(i.id),{staleTime:1/0}),o.setQueryData(ke(i.id),i),n(i.id)}})}function j(){const{kratosClient:e}=x(),{registrationFlowId:t}=q();return m.useQuery({queryKey:ke(t),queryFn:async({signal:n})=>{if(!t)throw new Error("No registration flow ID provided",{cause:P.NoFlowId});try{return await e.getRegistrationFlow({id:t},async({init:{headers:o}})=>({signal:n,headers:{...o,Accept:"application/json"}}))}catch(o){throw await re({error:o})}},enabled:!!t,staleTime:1/0})}function be(){const{kratosClient:e}=x(),{resetFlow:t,registrationFlowId:n}=q(),{setVerificationFlowId:o,setVerifiableAddress:i}=J(),r=m.useQueryClient();return m.useMutation({mutationFn:async a=>{if(!n)throw new Error("Registration flow ID is not set");try{const u=await(await e.updateRegistrationFlowRaw({flow:n,updateRegistrationFlowBody:a},{headers:{Accept:"application/json","Content-Type":"application/json"}})).value();if(u&&"continue_with"in u){const w=u.continue_with?.find(f=>f.action==="show_verification_ui");w!==void 0?(o(w.flow.id),i(w.flow.verifiable_address)):Pe(u.continue_with,{onRedirect:(f,d)=>{globalThis.location.href=f}})}return u}catch(c){return await B({onRedirect:(u,w)=>{globalThis.location.href=u},onRestartFlow:t,onValidationError:u=>u})(c)}},onSuccess(a){a&&"id"in a&&r.setQueryData(ke(a.id),a)}})}function ra({children:e}){const{setTraitsFormCompleted:t}=q(),n=l.useCallback(()=>{t(!1)},[t]),o=y.Root;return s.jsx(o,{type:"button",onClick:n,children:e})}function aa({children:e,onError:t,onRegistrationSuccess:n}){const{traits:o}=q(),{mutateAsync:i}=be(),{data:r}=j(),{chooseMethodForm:a}=Ge(),c=l.useCallback(async d=>{if(!r)return;const _=await i({method:"passkey",csrf_token:k(r),traits:o??{},passkey_register:d});if(_){if(Ve(_)){n?.();return}N(_,a,t)}},[t,n,r,o,a,i]),u=l.useMemo(()=>$(O(r?.ui.nodes,"passkey_create_data")),[r?.ui.nodes]),w=l.useCallback(async()=>{if(!u)return;const d=await gn(u.value,void 0,o);d&&c(d)},[u,c,o]),f=y.Root;return s.jsx(f,{type:"button",onClick:w,children:e})}function sa({children:e}){const{chooseMethodForm:t}=Ge(),n=y.Root;return s.jsx(t.Field,{name:"password",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"password",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}var A=(e=>(e.Password="password",e.PasswordConfirmation="password_confirmation",e))(A||{});const Lt=({value:e,fieldApi:t})=>{const n=t.form.getFieldMeta(A.PasswordConfirmation);if(n?.isDirty&&n?.isTouched)return Vt(e,t.form.getFieldValue(A.Password))},Vt=(e,t)=>{if(!e)return[ge(ie.FieldRequired)];if(e!==t)return[ge(ie.FieldMismatch)]};function ca({children:e}){const{chooseMethodForm:t}=Ge(),n=y.Root;return s.jsx(t.Field,{listeners:{onChange:({fieldApi:o})=>{o.form.setFieldMeta(A.PasswordConfirmation,i=>({...i,errorMap:{...i.errorMap,onSubmit:void 0}}))}},name:"password_confirmation",validators:{onChangeListenTo:[A.Password],onChange:Lt,onBlurListenTo:[A.PasswordConfirmation],onBlur:Lt,onSubmit:({value:o,fieldApi:i})=>Vt(o,i.form.getFieldValue(A.Password))},children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"password",value:o.state.value,onBlur:o.handleBlur,onChange:i=>o.handleChange(i.target.value),children:e})})}function la({onError:e,onRegistrationSuccess:t}){const{setTraitsFormCompleted:n,traits:o}=q(),{mutateAsync:i}=be(),{data:r}=j();return D.useForm({defaultValues:{[A.Password]:"",[A.PasswordConfirmation]:""},onSubmit:async({value:a,formApi:c})=>{if(!r)return;const u=await i({csrf_token:k(r),method:"password",traits:o??{},password:a[A.Password]});if(u){if(Ve(u)){t?.();return}u.state===dt.ChooseMethod&&n(!0),N(u,c,e)}}})}function ua({chooseMethodForm:e,onError:t,onRegistrationSuccess:n}){const o=la({onError:t,onRegistrationSuccess:n}),i=I(o);return s.jsx(ta,{chooseMethodForm:o,children:s.jsx("form",{onSubmit:r=>{r.preventDefault(),o.handleSubmit()},children:s.jsx(e,{errors:i,isSubmitting:o.state.isSubmitting,isValidating:o.state.isValidating,Passkey:aa,passwordFields:{Password:sa,PasswordConfirmation:ca,Submit:E},ReturnToTraitsForm:ra})})})}function da({children:e,provider:t}){const{mutate:n}=be(),{data:o}=j(),i=l.useCallback(()=>{o&&n({method:"oidc",csrf_token:k(o),provider:t})},[o,n,t]),r=y.Root;return s.jsx(r,{type:"button",onClick:i,children:e})}const Pt=l.createContext(void 0);function fa({children:e,traitsForm:t}){const n=l.useMemo(()=>({traitsForm:t}),[t]);return s.jsx(Pt.Provider,{value:n,children:e})}function Wt(){const e=l.useContext(Pt);if(e===void 0)throw new Error("useTraitsFormContext must be used within a TraitsFormProvider");return e}function wa({trait:e,children:t}){const{traitsForm:n}=Wt(),o=y.Root;return s.jsx(n.Field,{name:`${X}${e}`,children:i=>{if(typeof i.state.value!="string")throw new TypeError("TraitInput: value is not string");return s.jsx(o,{errors:C(i.state.meta.errorMap),name:i.name,type:"text",value:i.state.value,onChange:r=>i.handleChange(r.target.value),children:t})}})}function pa({trait:e,children:t}){const{traitsForm:n}=Wt(),o=y.Root;return s.jsx(n.Field,{name:`${X}${e}`,children:i=>{if(typeof i.state.value!="boolean")throw new TypeError("TraitCheckbox: value is not boolean");return s.jsx(o,{checked:i.state.value,errors:C(i.state.meta.errorMap),name:i.name,type:"checkbox",onChange:r=>i.handleChange(r.target.checked),children:t})}})}function ha({traitsConfig:e,onError:t,onRegistrationSuccess:n}){const{setTraitsFormCompleted:o,setTraits:i,traits:r}=q(),{mutateAsync:a}=be(),{data:c}=j();return D.useForm({defaultValues:{traits:r??Object.fromEntries(Object.values(e).map(({trait:u,type:w})=>[u,w==="boolean"?!1:""]))},onSubmit:async({value:u,formApi:w})=>{if(!c)return;const f=await a({csrf_token:k(c),method:"profile",traits:u.traits??{}});if(f){if(Ve(f)){n?.();return}f.state===dt.ChooseMethod&&f.ui.messages?.some(({id:d})=>d===1040009)&&(i(u.traits),o(!0)),N(f,w,t)}}})}function _a({traitsConfig:e,oidcProvidersConfig:t,traitsForm:n,onError:o,onRegistrationSuccess:i}){const r=ha({traitsConfig:e,onError:o,onRegistrationSuccess:i}),a=I(r),{data:c}=j(),u=l.useMemo(()=>Object.fromEntries(Object.entries(e).map(([f,d])=>[f,d.type==="boolean"?({children:_})=>s.jsx(pa,{children:_,trait:d.trait}):({children:_})=>s.jsx(wa,{children:_,trait:d.trait})])),[e]),w=l.useMemo(()=>{if(!c)return{};const f=Be(c.ui.nodes),d={};return f.forEach(_=>{const F=_.attributes.value;if(!qe(t,F))return;const T=Ne.toUpperFirst(F);d[T]=({children:h})=>s.jsx(da,{provider:F,children:h})}),d},[c,t]);return s.jsx(fa,{traitsForm:r,children:s.jsx("form",{onSubmit:f=>{f.preventDefault(),r.handleSubmit()},children:s.jsx(n,{errors:a,isSubmitting:r.state.isSubmitting,isValidating:r.state.isValidating,oidcProviders:w,traitFields:{...u,Submit:E}})})})}function ga({traitsConfig:e,oidcProvidersConfig:t,traitsForm:n,chooseMethodForm:o,emailVerificationForm:i,initialFlowId:r,returnTo:a,onError:c,onRegistrationSuccess:u,onVerificationSuccess:w,onFlowRestart:f,onSessionAlreadyAvailable:d}){const{verificationFlowId:_}=J(),{registrationFlowId:F,setRegistrationFlowId:T,traitsFormCompleted:h}=q(),{error:v}=j(),{mutate:Q,error:te}=ia({returnTo:a});ne({initialFlowId:r,currentFlowId:F,error:v??void 0,onFlowRestart:f,createFlow:Q,setFlowId:T});const H=l.useMemo(()=>_e(v)||_e(te),[v,te]);l.useEffect(()=>{H&&d?.()},[H,d]);const R=l.useMemo(()=>H?"invalid":_?"emailVerification":h?"credentials":"traits",[h,_,H]);return s.jsxs(s.Fragment,{children:[R==="traits"&&s.jsx(_a,{oidcProvidersConfig:t,traitsConfig:e,traitsForm:n,onError:c,onRegistrationSuccess:u}),R==="credentials"&&s.jsx(ua,{chooseMethodForm:o,onError:c,onRegistrationSuccess:u}),R==="emailVerification"&&s.jsx(Fe,{emailVerificationForm:i,onError:c,onVerificationSuccess:w})]})}function Bt(e){return s.jsx(ye,{children:s.jsx(oa,{children:s.jsx(ga,{...e})})})}const ma=Object.freeze(Object.defineProperty({__proto__:null,RegistrationFlow:Bt},Symbol.toStringTag,{value:"Module"})),ya=z("settings_flow"),Ce=(e="no_id")=>K([ya,e]),qt=l.createContext(void 0);function Qe({children:e}){const[t,n]=l.useState(),[o,i]=l.useState(!1),r=l.useCallback(()=>{n(void 0)},[]);return s.jsx(qt.Provider,{value:{settingsFlowId:t,setSettingsFlowId:n,emailVerificationRequired:o,setEmailVerificationRequired:i,resetFlow:r},children:e})}function se(){const e=l.useContext(qt);if(e===void 0)throw new Error("useSettingsFlow must be used within a SettingsFlowProvider");return e}function Fa(){const{kratosClient:e}=x(),{setSettingsFlowId:t}=se(),n=m.useQueryClient();return m.useMutation({mutationFn:()=>e.createBrowserSettingsFlow({},async({init:{headers:o}})=>({headers:{...o,Accept:"application/json"}})),onSuccess(o){n.setQueryDefaults(Ce(o.id),{staleTime:1/0}),n.setQueryData(Ce(o.id),o),t(o.id)}})}function M(){const{kratosClient:e}=x(),{settingsFlowId:t}=se();return m.useQuery({queryKey:Ce(t),queryFn:async({signal:n})=>{if(!t)throw new Error("No settings flow ID provided",{cause:P.NoFlowId});try{return await e.getSettingsFlow({id:t},async({init:{headers:o}})=>({signal:n,headers:{...o,Accept:"application/json"}}))}catch(o){throw await re({error:o})}},enabled:!!t,staleTime:1/0})}function ee(){const{kratosClient:e}=x(),{settingsFlowId:t,resetFlow:n,setEmailVerificationRequired:o}=se(),i=m.useQueryClient();return m.useMutation({mutationFn:async r=>{if(!t)throw new Error("Settings flow ID is not set");try{const a=await e.updateSettingsFlow({flow:t,updateSettingsFlowBody:r},{headers:{Accept:"application/json","Content-Type":"application/json"}});return a&&"continue_with"in a&&(a.continue_with?.find(u=>u.action==="show_verification_ui")?o(!0):Pe(a.continue_with,{onRedirect:(u,w)=>{globalThis.location.href=u}})),a}catch(a){return await B({onRedirect:(c,u)=>{globalThis.location.href=c},onRestartFlow:n,onValidationError:c=>c})(a)}},onSuccess(r){r&&"id"in r&&i.setQueryData(Ce(r.id),r)}})}const $t=l.createContext(void 0);function va({children:e,newPasswordForm:t}){const n=l.useMemo(()=>({newPasswordForm:t}),[t]);return s.jsx($t.Provider,{value:n,children:e})}function Kt(){const e=l.useContext($t);if(e===void 0)throw new Error("useNewPasswordFormContext must be used within a NewPasswordFormProvider");return e}function Sa({children:e}){const{newPasswordForm:t}=Kt(),n=y.Root;return s.jsx(t.Field,{name:"password",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"password",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}var L=(e=>(e.Password="password",e.PasswordConfirmation="password_confirmation",e))(L||{});const zt=({value:e,fieldApi:t})=>{const n=t.form.getFieldMeta(L.PasswordConfirmation);if(n?.isDirty&&n?.isTouched)return Gt(e,t.form.getFieldValue(L.Password))},Gt=(e,t)=>{if(!e)return[ge(ie.FieldRequired)];if(e!==t)return[ge(ie.FieldMismatch)]};function ka({children:e}){const{newPasswordForm:t}=Kt(),n=y.Root;return s.jsx(t.Field,{listeners:{onChange:({fieldApi:o})=>{o.form.setFieldMeta(L.PasswordConfirmation,i=>({...i,errorMap:{...i.errorMap,onSubmit:void 0}}))}},name:"password_confirmation",validators:{onChangeListenTo:[L.Password],onChange:zt,onBlurListenTo:[L.PasswordConfirmation],onBlur:zt,onSubmit:({value:o,fieldApi:i})=>Gt(o,i.form.getFieldValue(L.Password))},children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"password",value:o.state.value,onBlur:o.handleBlur,onChange:i=>o.handleChange(i.target.value),children:e})})}function ba({onError:e,onChangePasswordSuccess:t}){const{mutateAsync:n}=ee(),{data:o}=M();return D.useForm({defaultValues:{[L.Password]:"",[L.PasswordConfirmation]:""},onSubmit:async({value:i,formApi:r})=>{if(!o)return;const a=await n({csrf_token:k(o),method:"password",password:i[L.Password]});if(a){if(a.state==="success"){t?.();return}N(a,r,e)}}})}function Ca({newPasswordForm:e,emailVerificationRequired:t,onError:n,onChangePasswordSuccess:o}){const{data:i}=M(),r=ba({onError:n,onChangePasswordSuccess:o}),a=I(r);return s.jsx(va,{newPasswordForm:r,children:s.jsx("form",{onSubmit:c=>{c.preventDefault(),r.handleSubmit()},children:s.jsx(e,{emailVerificationRequired:t,errors:a,isLoading:!i,isSubmitting:r.state.isSubmitting,isValidating:r.state.isValidating,Password:Sa,PasswordConfirmation:ka,Submit:E})})})}function xa({children:e,provider:t,type:n}){const{mutate:o}=ee(),{data:i}=M(),r=l.useCallback(()=>{i&&o({method:"oidc",[n]:t})},[i,o,n,t]),a=y.Root;return s.jsx(a,{oidcType:n,type:"button",onClick:r,children:e})}const Ta=(e,t)=>{const n=Fr(t,e);if(n){if(n.attributes.name==="link")return"link";if(n.attributes.name==="unlink")return"unlink";throw new Error(`Unknown OIDC provider type for ${e}: ${n.attributes.name}`)}};function Oa({oidcForm:e,oidcProvidersConfig:t}){const{data:n}=M(),o=l.useMemo(()=>{if(!n)return{};const i=Be(n.ui.nodes),r={};return i.forEach(a=>{const c=a.attributes.value,u=Ta(c,n.ui.nodes);if(!u||!qe(t,c))return;const w=Ne.toUpperFirst(c);r[w]=({children:f})=>s.jsx(xa,{provider:c,type:u,children:f})}),r},[n,t]);return s.jsx(e,{isLoading:!n,...o})}const Na=()=>{const{mutateAsync:e,isPending:t}=ee(),{data:n}=M(),o=l.useCallback(async c=>{if(!t){if(!n)throw new Error("Settings flow is not available");await e({method:"passkey",csrf_token:k(n),passkey_remove:c})}},[t,n,e]),i=l.useCallback(async c=>{n&&await e({method:"passkey",csrf_token:k(n),passkey_settings_register:c})},[n,e]),r=l.useMemo(()=>$(O(n?.ui.nodes,"passkey_create_data")),[n?.ui.nodes]),a=l.useCallback(async()=>{if(t||!r)return;const c=await mn(r.value);c&&await i(c)},[t,r,i]);return{isPending:t,removePasskey:o,addNewPasskey:a}};function Ea({passkeysForm:e}){const{data:t}=M(),{removePasskey:n,isPending:o,addNewPasskey:i}=Na(),r=t?gr(t.ui.nodes,"passkey_remove").filter(yr).map(({meta:a,attributes:c})=>({addedAt:a.label.context.added_at,addedAtUnix:a.label.context.added_at_unix,id:String(c.value),name:a.label.context.display_name,removePasskey:()=>n(c.value)})):[];return s.jsx(e,{addNewPasskey:i,existingPasskeys:r,isLoading:!t,isPending:o})}const Qt=l.createContext(void 0);function Ma({children:e,totpForm:t}){const n=l.useMemo(()=>({totpForm:t}),[t]);return s.jsx(Qt.Provider,{value:n,children:e})}function Ra(){const e=l.useContext(Qt);if(e===void 0)throw new Error("useTotpFormContext must be used within a TotpFormProvider");return e}function Da({children:e}){const{totpForm:t}=Ra(),n=y.Root;return s.jsx(t.Field,{name:"code",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"text",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}function Ia({children:e}){const{mutateAsync:t}=ee(),{data:n}=M(),o=l.useCallback(async()=>{n&&await t({method:"totp",csrf_token:k(n),totp_unlink:!0})},[n,t]),i=y.Root;return s.jsx(i,{type:"button",onClick:o,children:e})}var He=(e=>(e.Code="code",e))(He||{});function Ja({onError:e,onTotpSuccess:t}){const{mutateAsync:n}=ee(),{data:o}=M();return D.useForm({defaultValues:{[He.Code]:""},onSubmit:async({value:i,formApi:r})=>{if(!o)return;const a=await n({csrf_token:k(o),method:"totp",totp_code:i[He.Code]});if(a){if(a.state==="success"){t?.();return}N(a,r,e)}}})}function Ua({totpForm:e,emailVerificationRequired:t,onError:n,onTotpSuccess:o}){const i=Ja({onError:n,onTotpSuccess:o}),r=I(i),{data:a}=M(),c=l.useMemo(()=>{if(!a)return;const d=O(a.ui.nodes,"totp_qr");if(!(!d||d.attributes.node_type!==ut.Img))return d.attributes.src},[a]),u=l.useMemo(()=>{if(!a)return;const d=O(a.ui.nodes,"totp_secret_key");if(!d||d.attributes.node_type!==ut.Text)return;const{text:_}=d.attributes;return _.context&&"secret"in _.context&&typeof _.context.secret=="string"?_.context.secret:_.text},[a]),w=l.useMemo(()=>{if(a)return!!O(a.ui.nodes,"totp_unlink")},[a]),f=!a||w===void 0;return s.jsx(Ma,{totpForm:i,children:s.jsx("form",{onSubmit:d=>{d.preventDefault(),i.handleSubmit()},children:f?s.jsx(e,{isLoading:!0}):w?s.jsx(e,{isTotpLinked:!0,emailVerificationRequired:t,Unlink:Ia}):s.jsx(e,{Code:Da,emailVerificationRequired:t,errors:r,isSubmitting:i.state.isSubmitting,isValidating:i.state.isValidating,Submit:E,totpQrImageSrc:c,totpSecretKey:u})})})}const Ht=l.createContext(void 0);function Aa({children:e,traitsForm:t}){const n=l.useMemo(()=>({traitsForm:t}),[t]);return s.jsx(Ht.Provider,{value:n,children:e})}function Xt(){const e=l.useContext(Ht);if(e===void 0)throw new Error("useTraitsFormContext must be used within a TraitsFormProvider");return e}function La({trait:e,children:t}){const{traitsForm:n}=Xt(),o=y.Root;return s.jsx(n.Field,{name:`${X}${e}`,children:i=>{if(typeof i.state.value!="string")throw new TypeError("TraitInput: value is not string");return s.jsx(o,{errors:C(i.state.meta.errorMap),name:i.name,type:"text",value:i.state.value,onChange:r=>i.handleChange(r.target.value),children:t})}})}function Va({trait:e,children:t}){const{traitsForm:n}=Xt(),o=y.Root;return s.jsx(n.Field,{name:`${X}${e}`,children:i=>{if(typeof i.state.value!="boolean")throw new TypeError("TraitCheckbox: value is not boolean");return s.jsx(o,{checked:i.state.value,errors:C(i.state.meta.errorMap),name:i.name,type:"checkbox",onChange:r=>i.handleChange(r.target.checked),children:t})}})}function Pa({traitsConfig:e,onError:t,onChangeTraitsSuccess:n}){const{mutateAsync:o}=ee(),{data:i}=M();return D.useForm({defaultValues:{traits:i?.identity.traits??Object.fromEntries(Object.values(e).map(({trait:r,type:a})=>[r,a==="boolean"?!1:""]))},onSubmit:async({value:r,formApi:a})=>{if(!i)return;const c=await o({csrf_token:k(i),method:"profile",traits:r.traits??{}});if(c){if(c.state===Ao.Success){n?.();return}N(c,a,t)}}})}function Wa({traitsConfig:e,traitsForm:t,emailVerificationRequired:n,onError:o,onChangeTraitsSuccess:i}){const{data:r}=M(),a=Pa({traitsConfig:e,onError:o,onChangeTraitsSuccess:i}),c=I(a),u=l.useMemo(()=>Object.fromEntries(Object.entries(e).map(([w,f])=>[w,f.type==="boolean"?({children:d})=>s.jsx(Va,{children:d,trait:f.trait}):({children:d})=>s.jsx(La,{children:d,trait:f.trait})])),[e]);return s.jsx(Aa,{traitsForm:a,children:s.jsx("form",{onSubmit:w=>{w.preventDefault(),a.handleSubmit()},children:s.jsx(t,{emailVerificationRequired:n,errors:c,isLoading:!r,isSubmitting:a.state.isSubmitting,isValidating:a.state.isValidating,Submit:E,...u})})})}function Yt(e){return s.jsx(Qe,{children:s.jsx(Xe,{...e})})}function Xe({newPasswordForm:e,traitsForm:t,passkeysForm:n,totpForm:o,oidcForm:i,traitsConfig:r,oidcProvidersConfig:a,settingsForm:c,initialFlowId:u,onError:w,onChangePasswordSuccess:f,onChangeTraitsSuccess:d,onFlowRestart:_}){const{settingsFlowId:F,setSettingsFlowId:T,emailVerificationRequired:h}=se(),{mutate:v}=Fa(),{data:Q,error:te}=M();return ne({initialFlowId:u,currentFlowId:F,error:te,onFlowRestart:_,createFlow:v,setFlowId:T}),s.jsx(c,{emailVerificationRequired:h,isLoading:!Q,newPasswordForm:e&&s.jsx(Ca,{emailVerificationRequired:h,newPasswordForm:e,onChangePasswordSuccess:f,onError:w}),oidcForm:i&&s.jsx(Oa,{oidcForm:i,oidcProvidersConfig:a}),passkeysForm:n&&s.jsx(Ea,{passkeysForm:n}),totpForm:o&&s.jsx(Ua,{emailVerificationRequired:h,totpForm:o,onError:w,onTotpSuccess:d}),traitsForm:r&&t&&s.jsx(Wa,{emailVerificationRequired:h,traitsConfig:r,traitsForm:t,onChangeTraitsSuccess:d,onError:w})})}const Ba=Object.freeze(Object.defineProperty({__proto__:null,SettingsFlow:Yt,SettingsFlowProvider:Qe,SettingsFlowWrapper:Xe,useSettingsFlowContext:se},Symbol.toStringTag,{value:"Module"})),Zt=l.createContext(void 0);function qa({children:e,codeForm:t}){const n=l.useMemo(()=>({codeForm:t}),[t]);return s.jsx(Zt.Provider,{value:n,children:e})}function $a(){const e=l.useContext(Zt);if(e===void 0)throw new Error("useCodeFormContext must be used within a CodeFormProvider");return e}function Ka({children:e}){const{codeForm:t}=$a(),n=y.Root;return s.jsx(t.Field,{name:"code",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"text",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}const za=z("recovery_flow"),xe=(e="no_id")=>K([za,e]),jt=l.createContext(void 0);function Ga({children:e}){const[t,n]=l.useState(),o=l.useCallback(()=>{n(void 0)},[]);return s.jsx(jt.Provider,{value:{recoveryFlowId:t,setRecoveryFlowId:n,resetFlow:o},children:e})}function Te(){const e=l.useContext(jt);if(e===void 0)throw new Error("useRecoveryFlowContext must be used within a RecoveryFlow");return e}function Qa({returnTo:e}={}){const{kratosClient:t}=x(),{setRecoveryFlowId:n}=Te(),o=m.useQueryClient();return m.useMutation({mutationFn:()=>t.createBrowserRecoveryFlow({returnTo:e},async({init:{headers:i}})=>({headers:{...i,Accept:"application/json"}})),onSuccess(i){o.setQueryDefaults(xe(i.id),{staleTime:1/0}),o.setQueryData(xe(i.id),i),n(i.id)}})}function Ye(){const{kratosClient:e}=x(),{recoveryFlowId:t}=Te();return m.useQuery({queryKey:xe(t),queryFn:async({signal:n})=>{if(!t)throw new Error("No recovery flow ID provided",{cause:P.NoFlowId});try{return await e.getRecoveryFlow({id:t},async({init:{headers:o}})=>({signal:n,headers:{...o,Accept:"application/json"}}))}catch(o){throw await re({error:o})}},enabled:!!t,staleTime:1/0})}function en(){const{kratosClient:e}=x(),{resetFlow:t,recoveryFlowId:n}=Te(),o=m.useQueryClient();return m.useMutation({mutationFn:async i=>{if(!n)throw new Error("Recovery flow ID is not set");try{return await e.updateRecoveryFlow({flow:n,updateRecoveryFlowBody:i},{headers:{Accept:"application/json","Content-Type":"application/json"}})}catch(r){return await B({onRedirect:(a,c)=>{globalThis.location.href=a},onRestartFlow:t,onValidationError:a=>a})(r)}},onSuccess(i){i&&"id"in i&&o.setQueryData(xe(i.id),i)}})}var Ze=(e=>(e.Code="code",e))(Ze||{});function Ha({onError:e}){const{mutateAsync:t}=en(),{data:n}=Ye();return D.useForm({defaultValues:{[Ze.Code]:""},onSubmit:async({value:o,formApi:i})=>{if(!n)return;const r=await t({csrf_token:k(n),method:"code",code:o[Ze.Code]});r&&N(r,i,e)}})}function Xa({codeForm:e,onError:t}){const n=Ha({onError:t}),o=I(n);return s.jsx(qa,{codeForm:n,children:s.jsx("form",{onSubmit:i=>{i.preventDefault(),n.handleSubmit()},children:s.jsx(e,{Code:Ka,errors:o,isSubmitting:n.state.isSubmitting,isValidating:n.state.isValidating,Submit:E})})})}const tn=l.createContext(void 0);function Ya({children:e,emailForm:t}){const n=l.useMemo(()=>({emailForm:t}),[t]);return s.jsx(tn.Provider,{value:n,children:e})}function Za(){const e=l.useContext(tn);if(e===void 0)throw new Error("useEmailFormContext must be used within a EmailFormProvider");return e}function ja({children:e}){const{emailForm:t}=Za(),n=y.Root;return s.jsx(t.Field,{name:"email",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"text",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}var je=(e=>(e.Email="email",e))(je||{});function es({onError:e}){const{mutateAsync:t}=en(),{data:n}=Ye();return D.useForm({defaultValues:{[je.Email]:""},onSubmit:async({value:o,formApi:i})=>{if(!n)return;const r=await t({csrf_token:k(n),method:"code",email:o[je.Email]});r&&N(r,i,e)}})}function ts({emailForm:e,onError:t}){const n=es({onError:t}),o=I(n);return s.jsx(Ya,{emailForm:n,children:s.jsx("form",{onSubmit:i=>{i.preventDefault(),n.handleSubmit()},children:s.jsx(e,{Email:ja,errors:o,isSubmitting:n.state.isSubmitting,isValidating:n.state.isValidating,Submit:E})})})}function ns({emailForm:e,codeForm:t,newPasswordForm:n,initialFlowId:o,returnTo:i,onError:r,onRecoverySuccess:a,onFlowRestart:c}){const{recoveryFlowId:u,setRecoveryFlowId:w}=Te(),{mutate:f}=Qa({returnTo:i}),{data:d,error:_}=Ye(),F=l.useMemo(()=>d?.continue_with?.find(h=>h.action==="show_settings_ui")?.flow.id,[d]);ne({initialFlowId:o,currentFlowId:u,error:_,onFlowRestart:c,createFlow:f,setFlowId:w});const T=l.useMemo(()=>F?"newPassword":d?.state==="sent_email"?"code":"email",[d?.state,F]);return s.jsxs(s.Fragment,{children:[T==="email"&&s.jsx(ts,{emailForm:e,onError:r}),T==="code"&&s.jsx(Xa,{codeForm:t,onError:r}),T==="newPassword"&&F&&s.jsx(Xe,{initialFlowId:F,newPasswordForm:n,settingsForm:({newPasswordForm:h})=>h,onChangePasswordSuccess:a,onError:r})]})}function nn(e){return s.jsx(Qe,{children:s.jsx(Ga,{children:s.jsx(ns,{...e})})})}const os=Object.freeze(Object.defineProperty({__proto__:null,RecoveryFlow:nn},Symbol.toStringTag,{value:"Module"})),on=K([z("session_manager"),"session"]),rn=e=>({queryKey:on,queryFn:async()=>{try{return await e.toSession()}catch(t){if(t instanceof Y){if(t.response.status===401)return null;const n=await t.response.json();if(V(n))throw new Error("Kratos error occurred while fetching session",{cause:n})}throw new Error("Unexpected error while fetching session")}},staleTime:1/0,retry:!1});class an{queryClient;api;getSession=async()=>{try{return await this.queryClient.fetchQuery(rn(this.api))??void 0}catch{return}};getIdentity=async()=>(await this.getSession())?.identity;getUserId=async()=>(await this.getIdentity())?.id;isLoggedIn=async()=>(await this.getSession())?.active??!1;useSession=()=>{const{data:t,isLoading:n,error:o}=m.useQuery({...rn(this.api),retryOnMount:!1});return{session:t??void 0,isLoading:n,error:o}};useIdentity=()=>{const{session:t,...n}=this.useSession();return{identity:t?.identity,...n}};useUserId=()=>{const{identity:t,...n}=this.useIdentity();return{userId:t?.id,...n}};useIsLoggedIn=()=>{const{session:t,isLoading:n,error:o}=this.useSession();return{isLoggedIn:t?.active??(n?void 0:!1),isLoading:n,error:o}};useIsAal2Required=()=>{const t=this.useSession();return{isAal2Required:t.error?.cause?V(t.error.cause)&&rr(t.error.cause):void 0,isLoading:t.isLoading}};checkIfLoggedIn=async()=>await this.queryClient.refetchQueries({queryKey:on,exact:!0});constructor({queryClient:t,api:n}){this.api=n,this.queryClient=t}}function is({queryClient:e,basePath:t,traits:n={},SessionManager:o=an,oidcProviders:i=[]}){const r=new nr(new at({basePath:t,credentials:"include"})),a=new o({queryClient:e,api:r});return{flows:{useLogout:Jt,LoginFlow:f=>s.jsx(It,{...f,oidcProvidersConfig:i}),RecoveryFlow:nn,RegistrationFlow:f=>s.jsx(Bt,{...f,oidcProvidersConfig:i,traitsConfig:n}),SettingsFlow:f=>s.jsx(Yt,{...f,oidcProvidersConfig:i,traitsConfig:n}),VerificationFlow:Ct},providers:{KratosProviders:({children:f})=>s.jsx(vr,{api:r,children:s.jsx(un,{sessionManager:a,children:f})})},session:{sessionManager:a}}}b.BaseSessionManager=an,b.loginFlow=jr,b.logoutFlow=ea,b.mkKratos=is,b.recoveryFlow=os,b.registrationFlow=ma,b.settingsFlow=Ba,b.verificationFlow=Er,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(b,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("react/jsx-runtime"),require("react"),require("@tanstack/react-query"),require("@leancodepl/utils"),require("@tanstack/react-form"),require("@radix-ui/react-slot")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@tanstack/react-query","@leancodepl/utils","@tanstack/react-form","@radix-ui/react-slot"],s):(b=typeof globalThis<"u"?globalThis:b||self,s(b["@leancodepl/kratos"]={},b.jsxRuntime,b.react,b.reactQuery,b.utils,b.reactForm,b.Slot))})(this,(function(b,s,l,m,Ne,D,cn){"use strict";function ln(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const y=ln(cn);var P=(e=>(e[e.NoFlowId=0]="NoFlowId",e[e.FlowRestartRequired=1]="FlowRestartRequired",e))(P||{});const tt=l.createContext(void 0);function Ee(){const e=l.useContext(tt);if(e===void 0)throw new Error("useKratosSessionContext must be used within a KratosSessionContextProvider");return e}function un({children:e,sessionManager:t}){const n=l.useMemo(()=>({sessionManager:t}),[t]);return s.jsx(tt.Provider,{value:n,children:e})}const ne=({initialFlowId:e,currentFlowId:t,error:n,onFlowRestart:o,createFlow:i,setFlowId:r,waitForSession:a})=>{const[c,u]=l.useState(!1),[w,f]=l.useState(e),{sessionManager:d}=Ee(),{isLoading:_}=d.useSession();w!==e&&(u(!1),f(e));const F=!!a&&_;l.useEffect(()=>{t||F||(e&&!c?(r(e),u(!0)):i())},[i,t,e,c,r,F]),l.useEffect(()=>{n&&n.cause===P.FlowRestartRequired&&(i(),o?.())},[i,n,o])},X="traits.";function nt(e){return"type"in e&&e.type==="public-key"&&"id"in e&&"rawId"in e&&"response"in e}function dn(e){return"attestationObject"in e&&"clientDataJSON"in e}function fn(e){return"authenticatorData"in e&&"clientDataJSON"in e&&"signature"in e}function le(e){return Uint8Array.from(atob(e.replaceAll("-","+").replaceAll("_","/")),function(t){return t.charCodeAt(0)})}function W(e){return btoa(String.fromCharCode(...new Uint8Array(e))).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")}function ot(e){if(!e||!nt(e))return;const{response:t,id:n,rawId:o}=e;if(dn(t))return JSON.stringify({id:n,rawId:W(o),type:e.type,response:{attestationObject:W(t.attestationObject),clientDataJSON:W(t.clientDataJSON)}})}async function it({credentialOptions:e,signal:t,userName:n,userDisplayName:o}){return await navigator.credentials.create({signal:t,publicKey:{challenge:le(e.publicKey.challenge),timeout:e.publicKey.timeout,rp:{id:e.publicKey.rp.id,name:e.publicKey.rp.name},user:{id:le(e.publicKey.user.id),name:n,displayName:o},pubKeyCredParams:e.publicKey.pubKeyCredParams}})}function rt(e){if(!e||!nt(e))return;const{response:t,id:n,rawId:o}=e;if(!fn(t))return;const{userHandle:i,authenticatorData:r,clientDataJSON:a,signature:c}=t;return JSON.stringify({id:n,rawId:W(o),type:e.type,response:{authenticatorData:W(r),clientDataJSON:W(a),signature:W(c),userHandle:i?W(i):void 0}})}async function wn({challengeOptions:e,signal:t}){return await navigator.credentials.get({signal:t,publicKey:{challenge:le(e.publicKey.challenge),timeout:e.publicKey.timeout,rpId:e.publicKey.rpId,userVerification:e.publicKey.userVerification}})}function pn(){return!!globalThis.PublicKeyCredential}async function hn(e,t){const n=JSON.parse(e);if(pn()&&globalThis.PublicKeyCredential.isConditionalMediationAvailable&&await globalThis.PublicKeyCredential.isConditionalMediationAvailable())try{const o=await navigator.credentials.get({mediation:"conditional",signal:t,publicKey:{challenge:le(n.publicKey.challenge),timeout:n.publicKey.timeout,rpId:n.publicKey.rpId,userVerification:n.publicKey.userVerification}});return rt(o)}catch{return}}async function _n(e,t){const n=JSON.parse(e);try{return rt(await wn({challengeOptions:n,signal:t}))}catch{return}}async function gn(e,t,n){const{credentialOptions:o,displayNameFieldName:i}=JSON.parse(e),r=i.startsWith(X)?i.slice(X.length):i,a=typeof n?.[r]=="string"?n[r]:"";try{return ot(await it({credentialOptions:o,signal:t,userName:a,userDisplayName:a}))}catch{return}}async function mn(e,t){const n=JSON.parse(e);try{return ot(await it({credentialOptions:n,signal:t,userName:n.publicKey.user.name,userDisplayName:n.publicKey.user.displayName}))}catch{return}}const p=(e,t,n)=>e!==void 0&&t in e&&typeof e[t]===n,yn="https://playground.projects.oryapis.com".replace(/\/+$/,"");class at{constructor(t={}){this.configuration=t}set config(t){this.configuration=t}get basePath(){return this.configuration.basePath!=null?this.configuration.basePath:yn}get fetchApi(){return this.configuration.fetchApi}get middleware(){return this.configuration.middleware||[]}get queryParamsStringify(){return this.configuration.queryParamsStringify||st}get username(){return this.configuration.username}get password(){return this.configuration.password}get apiKey(){const t=this.configuration.apiKey;if(t)return typeof t=="function"?t:()=>t}get accessToken(){const t=this.configuration.accessToken;if(t)return typeof t=="function"?t:async()=>t}get headers(){return this.configuration.headers}get credentials(){return this.configuration.credentials}}const Fn=new at;class Me{constructor(t=Fn){this.configuration=t,this.middleware=t.middleware}static jsonRegex=new RegExp("^(:?application/json|[^;/ ]+/[^;/ ]+[+]json)[ ]*(:?;.*)?$","i");middleware;withMiddleware(...t){const n=this.clone();return n.middleware=n.middleware.concat(...t),n}withPreMiddleware(...t){const n=t.map(o=>({pre:o}));return this.withMiddleware(...n)}withPostMiddleware(...t){const n=t.map(o=>({post:o}));return this.withMiddleware(...n)}isJsonMime(t){return t?Me.jsonRegex.test(t):!1}async request(t,n){const{url:o,init:i}=await this.createFetchParams(t,n),r=await this.fetchApi(o,i);if(r&&r.status>=200&&r.status<300)return r;throw new Y(r,"Response returned an error code")}async createFetchParams(t,n){let o=this.configuration.basePath+t.path;t.query!==void 0&&Object.keys(t.query).length!==0&&(o+="?"+this.configuration.queryParamsStringify(t.query));const i=Object.assign({},this.configuration.headers,t.headers);Object.keys(i).forEach(f=>i[f]===void 0?delete i[f]:{});const r=typeof n=="function"?n:async()=>n,a={method:t.method,headers:i,body:t.body,credentials:this.configuration.credentials},c={...a,...await r({init:a,context:t})};let u;Sn(c.body)||c.body instanceof URLSearchParams||vn(c.body)?u=c.body:this.isJsonMime(i["Content-Type"])?u=JSON.stringify(c.body):u=c.body;const w={...c,body:u};return{url:o,init:w}}fetchApi=async(t,n)=>{let o={url:t,init:n};for(const r of this.middleware)r.pre&&(o=await r.pre({fetch:this.fetchApi,...o})||o);let i;try{i=await(this.configuration.fetchApi||fetch)(o.url,o.init)}catch(r){for(const a of this.middleware)a.onError&&(i=await a.onError({fetch:this.fetchApi,url:o.url,init:o.init,error:r,response:i?i.clone():void 0})||i);if(i===void 0)throw r instanceof Error?new Re(r,"The request failed and the interceptors did not return an alternative response"):r}for(const r of this.middleware)r.post&&(i=await r.post({fetch:this.fetchApi,url:o.url,init:o.init,response:i.clone()})||i);return i};clone(){const t=this.constructor,n=new t(this.configuration);return n.middleware=this.middleware.slice(),n}}function vn(e){return typeof Blob<"u"&&e instanceof Blob}function Sn(e){return typeof FormData<"u"&&e instanceof FormData}class Y extends Error{constructor(t,n){super(n),this.response=t}name="ResponseError"}class Re extends Error{constructor(t,n){super(n),this.cause=t}name="FetchError"}class S extends Error{constructor(t,n){super(n),this.field=t}name="RequiredError"}function st(e,t=""){return Object.keys(e).map(n=>ct(n,e[n],t)).filter(n=>n.length>0).join("&")}function ct(e,t,n=""){const o=n+(n.length?`[${e}]`:e);if(t instanceof Array){const i=t.map(r=>encodeURIComponent(String(r))).join(`&${encodeURIComponent(o)}=`);return`${encodeURIComponent(o)}=${i}`}if(t instanceof Set){const i=Array.from(t);return ct(e,i,n)}return t instanceof Date?`${encodeURIComponent(o)}=${encodeURIComponent(t.toISOString())}`:t instanceof Object?st(t,o):`${encodeURIComponent(o)}=${encodeURIComponent(String(t))}`}function kn(e,t){return Object.keys(e).reduce((n,o)=>({...n,[o]:t(e[o])}),{})}class g{constructor(t,n=o=>o){this.raw=t,this.transformer=n}async value(){return this.transformer(await this.raw.json())}}class De{constructor(t){this.raw=t}async value(){}}class bn{constructor(t){this.raw=t}async value(){return await this.raw.text()}}function Ie(e){return Cn(e)}function Cn(e,t){return e}function xn(e){return Tn(e)}function Tn(e,t){return e==null?e:{id:e.id,url:e.url==null?void 0:e.url}}function On(e,t){return e==null?e:{action:e.action,flow:xn(e.flow)}}function Nn(e,t){return e==null?e:{action:e.action,redirect_browser_to:e.redirect_browser_to}}function En(e,t){return e==null?e:{action:e.action,ory_session_token:e.ory_session_token}}function Mn(e){return Rn(e)}function Rn(e,t){return e==null?e:{id:e.id,url:e.url==null?void 0:e.url}}function Dn(e,t){return e==null?e:{action:e.action,flow:Mn(e.flow)}}function In(e){return Jn(e)}function Jn(e,t){return e==null?e:{id:e.id,url:e.url==null?void 0:e.url,verifiable_address:e.verifiable_address}}function Un(e,t){return e==null?e:{action:e.action,flow:In(e.flow)}}function ue(e){return An(e)}function An(e,t){if(e==null)return e;switch(e.action){case"redirect_browser_to":return Object.assign({},Nn(e),{action:"redirect_browser_to"});case"set_ory_session_token":return Object.assign({},En(e),{action:"set_ory_session_token"});case"show_recovery_ui":return Object.assign({},On(e),{action:"show_recovery_ui"});case"show_settings_ui":return Object.assign({},Dn(e),{action:"show_settings_ui"});case"show_verification_ui":return Object.assign({},Un(e),{action:"show_verification_ui"});default:throw new Error(`No variant of ContinueWith exists with 'action=${e.action}'`)}}function Ln(e){return Vn(e)}function Vn(e,t){return e==null?e:{client_id:e.client_id==null?void 0:e.client_id,config_url:e.config_url==null?void 0:e.config_url,domain_hint:e.domain_hint==null?void 0:e.domain_hint,fields:e.fields==null?void 0:e.fields,login_hint:e.login_hint==null?void 0:e.login_hint,nonce:e.nonce==null?void 0:e.nonce,parameters:e.parameters==null?void 0:e.parameters}}function Pn(e){return Wn(e)}function Wn(e,t){return e==null?e:{csrf_token:e.csrf_token==null?void 0:e.csrf_token,providers:e.providers==null?void 0:e.providers.map(Ln)}}function Bn(e){return qn(e)}function qn(e,t){return e==null?e:{created_at:e.created_at==null?void 0:new Date(e.created_at),id:e.id==null?void 0:e.id,status:e.status,updated_at:e.updated_at==null?void 0:new Date(e.updated_at),value:e.value,verified:e.verified,verified_at:e.verified_at==null?void 0:new Date(e.verified_at),via:e.via}}function $n(e){return Kn(e)}function Kn(e,t){return e==null?e:{created_at:e.created_at==null?void 0:new Date(e.created_at),id:e.id,updated_at:e.updated_at==null?void 0:new Date(e.updated_at),value:e.value,via:e.via}}function zn(e){return Gn(e)}function Gn(e,t){return e==null?e:{count:e.count==null?void 0:e.count}}function Qn(e){return Hn(e)}function Hn(e,t){return e==null?e:{created_at:e.created_at==null?void 0:new Date(e.created_at),error:e.error==null?void 0:e.error,id:e.id,updated_at:e.updated_at==null?void 0:new Date(e.updated_at)}}function Xn(e){return Yn(e)}function Yn(e,t){return e==null?e:{config:e.config==null?void 0:e.config,created_at:e.created_at==null?void 0:new Date(e.created_at),identifiers:e.identifiers==null?void 0:e.identifiers,type:e.type==null?void 0:e.type,updated_at:e.updated_at==null?void 0:new Date(e.updated_at),version:e.version==null?void 0:e.version}}function Je(e){return Zn(e)}function Zn(e,t){return e==null?e:{created_at:e.created_at==null?void 0:new Date(e.created_at),credentials:e.credentials==null?void 0:kn(e.credentials,Xn),id:e.id,metadata_admin:e.metadata_admin==null?void 0:e.metadata_admin,metadata_public:e.metadata_public==null?void 0:e.metadata_public,organization_id:e.organization_id==null?void 0:e.organization_id,recovery_addresses:e.recovery_addresses==null?void 0:e.recovery_addresses.map($n),schema_id:e.schema_id,schema_url:e.schema_url,state:e.state==null?void 0:e.state,state_changed_at:e.state_changed_at==null?void 0:new Date(e.state_changed_at),traits:e.traits,updated_at:e.updated_at==null?void 0:new Date(e.updated_at),verifiable_addresses:e.verifiable_addresses==null?void 0:e.verifiable_addresses.map(Bn)}}function jn(e){return eo(e)}function eo(e,t){return e==null?e:{acr_values:e.acr_values==null?void 0:e.acr_values,display:e.display==null?void 0:e.display,id_token_hint_claims:e.id_token_hint_claims==null?void 0:e.id_token_hint_claims,login_hint:e.login_hint==null?void 0:e.login_hint,ui_locales:e.ui_locales==null?void 0:e.ui_locales}}function to(e){return no(e)}function no(e,t){return e==null?e:{access_token_strategy:e.access_token_strategy==null?void 0:e.access_token_strategy,allowed_cors_origins:e.allowed_cors_origins==null?void 0:e.allowed_cors_origins,audience:e.audience==null?void 0:e.audience,authorization_code_grant_access_token_lifespan:e.authorization_code_grant_access_token_lifespan==null?void 0:e.authorization_code_grant_access_token_lifespan,authorization_code_grant_id_token_lifespan:e.authorization_code_grant_id_token_lifespan==null?void 0:e.authorization_code_grant_id_token_lifespan,authorization_code_grant_refresh_token_lifespan:e.authorization_code_grant_refresh_token_lifespan==null?void 0:e.authorization_code_grant_refresh_token_lifespan,backchannel_logout_session_required:e.backchannel_logout_session_required==null?void 0:e.backchannel_logout_session_required,backchannel_logout_uri:e.backchannel_logout_uri==null?void 0:e.backchannel_logout_uri,client_credentials_grant_access_token_lifespan:e.client_credentials_grant_access_token_lifespan==null?void 0:e.client_credentials_grant_access_token_lifespan,client_id:e.client_id==null?void 0:e.client_id,client_name:e.client_name==null?void 0:e.client_name,client_secret:e.client_secret==null?void 0:e.client_secret,client_secret_expires_at:e.client_secret_expires_at==null?void 0:e.client_secret_expires_at,client_uri:e.client_uri==null?void 0:e.client_uri,contacts:e.contacts==null?void 0:e.contacts,created_at:e.created_at==null?void 0:new Date(e.created_at),frontchannel_logout_session_required:e.frontchannel_logout_session_required==null?void 0:e.frontchannel_logout_session_required,frontchannel_logout_uri:e.frontchannel_logout_uri==null?void 0:e.frontchannel_logout_uri,grant_types:e.grant_types==null?void 0:e.grant_types,implicit_grant_access_token_lifespan:e.implicit_grant_access_token_lifespan==null?void 0:e.implicit_grant_access_token_lifespan,implicit_grant_id_token_lifespan:e.implicit_grant_id_token_lifespan==null?void 0:e.implicit_grant_id_token_lifespan,jwks:e.jwks==null?void 0:e.jwks,jwks_uri:e.jwks_uri==null?void 0:e.jwks_uri,jwt_bearer_grant_access_token_lifespan:e.jwt_bearer_grant_access_token_lifespan==null?void 0:e.jwt_bearer_grant_access_token_lifespan,logo_uri:e.logo_uri==null?void 0:e.logo_uri,metadata:e.metadata==null?void 0:e.metadata,owner:e.owner==null?void 0:e.owner,policy_uri:e.policy_uri==null?void 0:e.policy_uri,post_logout_redirect_uris:e.post_logout_redirect_uris==null?void 0:e.post_logout_redirect_uris,redirect_uris:e.redirect_uris==null?void 0:e.redirect_uris,refresh_token_grant_access_token_lifespan:e.refresh_token_grant_access_token_lifespan==null?void 0:e.refresh_token_grant_access_token_lifespan,refresh_token_grant_id_token_lifespan:e.refresh_token_grant_id_token_lifespan==null?void 0:e.refresh_token_grant_id_token_lifespan,refresh_token_grant_refresh_token_lifespan:e.refresh_token_grant_refresh_token_lifespan==null?void 0:e.refresh_token_grant_refresh_token_lifespan,registration_access_token:e.registration_access_token==null?void 0:e.registration_access_token,registration_client_uri:e.registration_client_uri==null?void 0:e.registration_client_uri,request_object_signing_alg:e.request_object_signing_alg==null?void 0:e.request_object_signing_alg,request_uris:e.request_uris==null?void 0:e.request_uris,response_types:e.response_types==null?void 0:e.response_types,scope:e.scope==null?void 0:e.scope,sector_identifier_uri:e.sector_identifier_uri==null?void 0:e.sector_identifier_uri,skip_consent:e.skip_consent==null?void 0:e.skip_consent,skip_logout_consent:e.skip_logout_consent==null?void 0:e.skip_logout_consent,subject_type:e.subject_type==null?void 0:e.subject_type,token_endpoint_auth_method:e.token_endpoint_auth_method==null?void 0:e.token_endpoint_auth_method,token_endpoint_auth_signing_alg:e.token_endpoint_auth_signing_alg==null?void 0:e.token_endpoint_auth_signing_alg,tos_uri:e.tos_uri==null?void 0:e.tos_uri,updated_at:e.updated_at==null?void 0:new Date(e.updated_at),userinfo_signed_response_alg:e.userinfo_signed_response_alg==null?void 0:e.userinfo_signed_response_alg}}function lt(e){return oo(e)}function oo(e,t){return e==null?e:{challenge:e.challenge,client:to(e.client),oidc_context:e.oidc_context==null?void 0:jn(e.oidc_context),request_url:e.request_url,requested_access_token_audience:e.requested_access_token_audience==null?void 0:e.requested_access_token_audience,requested_scope:e.requested_scope==null?void 0:e.requested_scope,session_id:e.session_id==null?void 0:e.session_id,skip:e.skip,subject:e.subject}}const io={Error:"error"};function ro(e){return!(!("id"in e)||e.id===void 0||!("text"in e)||e.text===void 0||!("type"in e)||e.type===void 0)}function Z(e){return ao(e)}function ao(e,t){return e==null?e:{context:e.context==null?void 0:e.context,id:e.id,text:e.text,type:e.type}}function so(e){return co(e)}function co(e,t){return e==null?e:{label:e.label==null?void 0:Z(e.label)}}function lo(e,t){return e==null?e:{href:e.href,id:e.id,node_type:e.node_type,title:Z(e.title)}}function uo(e,t){return e==null?e:{_class:e.class==null?void 0:e.class,data:e.data==null?void 0:e.data,id:e.id,node_type:e.node_type}}const ut={Text:"text",Img:"img"};function fo(e,t){return e==null?e:{height:e.height,id:e.id,node_type:e.node_type,src:e.src,width:e.width}}function wo(e,t){return e==null?e:{autocomplete:e.autocomplete==null?void 0:e.autocomplete,disabled:e.disabled,label:e.label==null?void 0:Z(e.label),maxlength:e.maxlength==null?void 0:e.maxlength,name:e.name,node_type:e.node_type,onclick:e.onclick==null?void 0:e.onclick,onclickTrigger:e.onclickTrigger==null?void 0:e.onclickTrigger,onload:e.onload==null?void 0:e.onload,onloadTrigger:e.onloadTrigger==null?void 0:e.onloadTrigger,pattern:e.pattern==null?void 0:e.pattern,required:e.required==null?void 0:e.required,type:e.type,value:e.value==null?void 0:e.value}}const po={Input:"input"};function ho(e,t){return e==null?e:{async:e.async,crossorigin:e.crossorigin,id:e.id,integrity:e.integrity,node_type:e.node_type,nonce:e.nonce,referrerpolicy:e.referrerpolicy,src:e.src,type:e.type}}function _o(e,t){return e==null?e:{id:e.id,node_type:e.node_type,text:Z(e.text)}}function go(e){return mo(e)}function mo(e,t){if(e==null)return e;switch(e.node_type){case"a":return Object.assign({},lo(e),{node_type:"a"});case"div":return Object.assign({},uo(e),{node_type:"div"});case"img":return Object.assign({},fo(e),{node_type:"img"});case"input":return Object.assign({},wo(e),{node_type:"input"});case"script":return Object.assign({},ho(e),{node_type:"script"});case"text":return Object.assign({},_o(e),{node_type:"text"});default:throw new Error(`No variant of UiNodeAttributes exists with 'node_type=${e.node_type}'`)}}const yo={Passkey:"passkey"},Fo={Input:"input"};function vo(e){return So(e)}function So(e,t){return e==null?e:{attributes:go(e.attributes),group:e.group,messages:e.messages.map(Z),meta:so(e.meta),type:e.type}}function oe(e){return ko(e)}function ko(e,t){return e==null?e:{action:e.action,messages:e.messages==null?void 0:e.messages.map(Z),method:e.method,nodes:e.nodes.map(vo)}}function Ue(e){return bo(e)}function bo(e,t){return e==null?e:{active:e.active==null?void 0:e.active,created_at:e.created_at==null?void 0:new Date(e.created_at),expires_at:new Date(e.expires_at),id:e.id,issued_at:new Date(e.issued_at),oauth2_login_challenge:e.oauth2_login_challenge==null?void 0:e.oauth2_login_challenge,oauth2_login_request:e.oauth2_login_request==null?void 0:lt(e.oauth2_login_request),organization_id:e.organization_id==null?void 0:e.organization_id,refresh:e.refresh==null?void 0:e.refresh,request_url:e.request_url,requested_aal:e.requested_aal==null?void 0:Ie(e.requested_aal),return_to:e.return_to==null?void 0:e.return_to,session_token_exchange_code:e.session_token_exchange_code==null?void 0:e.session_token_exchange_code,state:e.state,transient_payload:e.transient_payload==null?void 0:e.transient_payload,type:e.type,ui:oe(e.ui),updated_at:e.updated_at==null?void 0:new Date(e.updated_at)}}function Co(e){return xo(e)}function xo(e,t){return e==null?e:{logout_token:e.logout_token,logout_url:e.logout_url}}function To(e){return Oo(e,!1)}function Oo(e,t=!1){return e==null?e:{session_token:e.session_token}}function de(e){return No(e)}function No(e,t){return e==null?e:{active:e.active==null?void 0:e.active,continue_with:e.continue_with==null?void 0:e.continue_with.map(ue),expires_at:new Date(e.expires_at),id:e.id,issued_at:new Date(e.issued_at),request_url:e.request_url,return_to:e.return_to==null?void 0:e.return_to,state:e.state,transient_payload:e.transient_payload==null?void 0:e.transient_payload,type:e.type,ui:oe(e.ui)}}function Ae(e){return Eo(e)}function Eo(e,t){return e==null?e:{active:e.active==null?void 0:e.active,expires_at:new Date(e.expires_at),id:e.id,issued_at:new Date(e.issued_at),oauth2_login_challenge:e.oauth2_login_challenge==null?void 0:e.oauth2_login_challenge,oauth2_login_request:e.oauth2_login_request==null?void 0:lt(e.oauth2_login_request),organization_id:e.organization_id==null?void 0:e.organization_id,request_url:e.request_url,return_to:e.return_to==null?void 0:e.return_to,session_token_exchange_code:e.session_token_exchange_code==null?void 0:e.session_token_exchange_code,state:e.state,transient_payload:e.transient_payload==null?void 0:e.transient_payload,type:e.type,ui:oe(e.ui)}}const dt={ChooseMethod:"choose_method"};function Mo(e){return Ro(e)}function Ro(e,t){return e==null?e:{id:e.id,ip_address:e.ip_address==null?void 0:e.ip_address,location:e.location==null?void 0:e.location,user_agent:e.user_agent==null?void 0:e.user_agent}}function Do(e){return Io(e)}function Io(e,t){return e==null?e:{aal:e.aal==null?void 0:Ie(e.aal),completed_at:e.completed_at==null?void 0:new Date(e.completed_at),method:e.method==null?void 0:e.method,organization:e.organization==null?void 0:e.organization,provider:e.provider==null?void 0:e.provider}}function fe(e){return Jo(e)}function Jo(e,t){return e==null?e:{active:e.active==null?void 0:e.active,authenticated_at:e.authenticated_at==null?void 0:new Date(e.authenticated_at),authentication_methods:e.authentication_methods==null?void 0:e.authentication_methods.map(Do),authenticator_assurance_level:e.authenticator_assurance_level==null?void 0:Ie(e.authenticator_assurance_level),devices:e.devices==null?void 0:e.devices.map(Mo),expires_at:e.expires_at==null?void 0:new Date(e.expires_at),id:e.id,identity:e.identity==null?void 0:Je(e.identity),issued_at:e.issued_at==null?void 0:new Date(e.issued_at),tokenized:e.tokenized==null?void 0:e.tokenized}}function we(e){return Uo(e)}function Uo(e,t){return e==null?e:{active:e.active==null?void 0:e.active,continue_with:e.continue_with==null?void 0:e.continue_with.map(ue),expires_at:new Date(e.expires_at),id:e.id,identity:Je(e.identity),issued_at:new Date(e.issued_at),request_url:e.request_url,return_to:e.return_to==null?void 0:e.return_to,state:e.state,transient_payload:e.transient_payload==null?void 0:e.transient_payload,type:e.type,ui:oe(e.ui)}}const Ao={Success:"success"};function pe(e){return!(!("session"in e)||e.session===void 0)}function Le(e){return Lo(e)}function Lo(e,t){return e==null?e:{continue_with:e.continue_with==null?void 0:e.continue_with.map(ue),session:fe(e.session),session_token:e.session_token==null?void 0:e.session_token}}function Ve(e){return!(!("identity"in e)||e.identity===void 0)}function Vo(e){return Po(e)}function Po(e,t){return e==null?e:{continue_with:e.continue_with==null?void 0:e.continue_with.map(ue),identity:Je(e.identity),session:e.session==null?void 0:fe(e.session),session_token:e.session_token==null?void 0:e.session_token}}function Wo(e){return Bo(e,!1)}function Bo(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,nonce:e.nonce,token:e.token,transient_payload:e.transient_payload}}function qo(e){return $o(e,!1)}function $o(e,t=!1){return e==null?e:{address:e.address,code:e.code,csrf_token:e.csrf_token,identifier:e.identifier,method:e.method,resend:e.resend,transient_payload:e.transient_payload}}function Ko(e){return zo(e,!1)}function zo(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,identifier:e.identifier,method:e.method,transient_payload:e.transient_payload}}function Go(e){return Qo(e,!1)}function Qo(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,lookup_secret:e.lookup_secret,method:e.method}}function Ho(e){return Xo(e,!1)}function Xo(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,id_token:e.id_token,id_token_nonce:e.id_token_nonce,method:e.method,provider:e.provider,traits:e.traits,transient_payload:e.transient_payload,upstream_parameters:e.upstream_parameters}}function Yo(e){return Zo(e,!1)}function Zo(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,passkey_login:e.passkey_login}}function jo(e){return ei(e,!1)}function ei(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,identifier:e.identifier,method:e.method,password:e.password,password_identifier:e.password_identifier,transient_payload:e.transient_payload}}function ti(e){return ni(e,!1)}function ni(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,provider:e.provider,transient_payload:e.transient_payload}}function oi(e){return ii(e,!1)}function ii(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,totp_code:e.totp_code,transient_payload:e.transient_payload}}function ri(e){return ai(e,!1)}function ai(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,identifier:e.identifier,method:e.method,transient_payload:e.transient_payload,webauthn_login:e.webauthn_login}}function si(e){return ci(e,!1)}function ci(e,t=!1){if(e==null)return e;switch(e.method){case"code":return Object.assign({},qo(e),{method:"code"});case"identifier_first":return Object.assign({},Ko(e),{method:"identifier_first"});case"lookup_secret":return Object.assign({},Go(e),{method:"lookup_secret"});case"oidc":return Object.assign({},Ho(e),{method:"oidc"});case"passkey":return Object.assign({},Yo(e),{method:"passkey"});case"password":return Object.assign({},jo(e),{method:"password"});case"saml":return Object.assign({},ti(e),{method:"saml"});case"totp":return Object.assign({},oi(e),{method:"totp"});case"webauthn":return Object.assign({},ri(e),{method:"webauthn"});default:throw new Error(`No variant of UpdateLoginFlowBody exists with 'method=${e.method}'`)}}function li(e){return ui(e,!1)}function ui(e,t=!1){return e==null?e:{code:e.code,csrf_token:e.csrf_token,email:e.email,method:e.method,transient_payload:e.transient_payload}}function di(e){return fi(e,!1)}function fi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,email:e.email,method:e.method,transient_payload:e.transient_payload}}function wi(e){return pi(e,!1)}function pi(e,t=!1){if(e==null)return e;switch(e.method){case"code":return Object.assign({},li(e),{method:"code"});case"link":return Object.assign({},di(e),{method:"link"});default:throw new Error(`No variant of UpdateRecoveryFlowBody exists with 'method=${e.method}'`)}}function hi(e){return _i(e,!1)}function _i(e,t=!1){return e==null?e:{code:e.code,csrf_token:e.csrf_token,method:e.method,resend:e.resend,traits:e.traits,transient_payload:e.transient_payload}}function gi(e){return mi(e,!1)}function mi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,id_token:e.id_token,id_token_nonce:e.id_token_nonce,method:e.method,provider:e.provider,traits:e.traits,transient_payload:e.transient_payload,upstream_parameters:e.upstream_parameters}}function yi(e){return Fi(e,!1)}function Fi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,passkey_register:e.passkey_register,traits:e.traits,transient_payload:e.transient_payload}}function vi(e){return Si(e,!1)}function Si(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,password:e.password,traits:e.traits,transient_payload:e.transient_payload}}function ki(e){return bi(e,!1)}function bi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,screen:e.screen,traits:e.traits,transient_payload:e.transient_payload}}function Ci(e){return xi(e,!1)}function xi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,provider:e.provider,traits:e.traits,transient_payload:e.transient_payload}}function Ti(e){return Oi(e,!1)}function Oi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,traits:e.traits,transient_payload:e.transient_payload,webauthn_register:e.webauthn_register,webauthn_register_displayname:e.webauthn_register_displayname}}function Ni(e){return Ei(e,!1)}function Ei(e,t=!1){if(e==null)return e;switch(e.method){case"code":return Object.assign({},hi(e),{method:"code"});case"oidc":return Object.assign({},gi(e),{method:"oidc"});case"passkey":return Object.assign({},yi(e),{method:"passkey"});case"password":return Object.assign({},vi(e),{method:"password"});case"profile":return Object.assign({},ki(e),{method:"profile"});case"saml":return Object.assign({},Ci(e),{method:"saml"});case"webauthn":return Object.assign({},Ti(e),{method:"webauthn"});default:throw new Error(`No variant of UpdateRegistrationFlowBody exists with 'method=${e.method}'`)}}function Mi(e){return Ri(e,!1)}function Ri(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,lookup_secret_confirm:e.lookup_secret_confirm,lookup_secret_disable:e.lookup_secret_disable,lookup_secret_regenerate:e.lookup_secret_regenerate,lookup_secret_reveal:e.lookup_secret_reveal,method:e.method,transient_payload:e.transient_payload}}function Di(e){return Ii(e,!1)}function Ii(e,t=!1){return e==null?e:{flow:e.flow,link:e.link,method:e.method,traits:e.traits,transient_payload:e.transient_payload,unlink:e.unlink,upstream_parameters:e.upstream_parameters}}function Ji(e){return Ui(e,!1)}function Ui(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,passkey_remove:e.passkey_remove,passkey_settings_register:e.passkey_settings_register}}function Ai(e){return Li(e,!1)}function Li(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,password:e.password,transient_payload:e.transient_payload}}function Vi(e){return Pi(e,!1)}function Pi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,traits:e.traits,transient_payload:e.transient_payload}}function Wi(e){return Bi(e,!1)}function Bi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,flow:e.flow,link:e.link,method:e.method,traits:e.traits,transient_payload:e.transient_payload,unlink:e.unlink}}function qi(e){return $i(e,!1)}function $i(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,totp_code:e.totp_code,totp_unlink:e.totp_unlink,transient_payload:e.transient_payload}}function Ki(e){return zi(e,!1)}function zi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,transient_payload:e.transient_payload,webauthn_register:e.webauthn_register,webauthn_register_displayname:e.webauthn_register_displayname,webauthn_remove:e.webauthn_remove}}function Gi(e){return Qi(e,!1)}function Qi(e,t=!1){if(e==null)return e;switch(e.method){case"lookup_secret":return Object.assign({},Mi(e),{method:"lookup_secret"});case"oidc":return Object.assign({},Di(e),{method:"oidc"});case"passkey":return Object.assign({},Ji(e),{method:"passkey"});case"password":return Object.assign({},Ai(e),{method:"password"});case"profile":return Object.assign({},Vi(e),{method:"profile"});case"saml":return Object.assign({},Wi(e),{method:"saml"});case"totp":return Object.assign({},qi(e),{method:"totp"});case"webauthn":return Object.assign({},Ki(e),{method:"webauthn"});default:throw new Error(`No variant of UpdateSettingsFlowBody exists with 'method=${e.method}'`)}}function Hi(e){return Xi(e,!1)}function Xi(e,t=!1){return e==null?e:{code:e.code,csrf_token:e.csrf_token,email:e.email,method:e.method,transient_payload:e.transient_payload}}function Yi(e){return Zi(e,!1)}function Zi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,email:e.email,method:e.method,transient_payload:e.transient_payload}}function ji(e){return er(e,!1)}function er(e,t=!1){if(e==null)return e;switch(e.method){case"code":return Object.assign({},Hi(e),{method:"code"});case"link":return Object.assign({},Yi(e),{method:"link"});default:throw new Error(`No variant of UpdateVerificationFlowBody exists with 'method=${e.method}'`)}}function he(e){return tr(e)}function tr(e,t){return e==null?e:{active:e.active==null?void 0:e.active,expires_at:e.expires_at==null?void 0:new Date(e.expires_at),id:e.id,issued_at:e.issued_at==null?void 0:new Date(e.issued_at),request_url:e.request_url==null?void 0:e.request_url,return_to:e.return_to==null?void 0:e.return_to,state:e.state,transient_payload:e.transient_payload==null?void 0:e.transient_payload,type:e.type,ui:oe(e.ui)}}const ft={ChooseMethod:"choose_method",SentEmail:"sent_email",PassedChallenge:"passed_challenge",UnknownDefaultOpenApi:"11184809"};class nr extends Me{async createBrowserLoginFlowRaw(t,n){const o={};t.refresh!=null&&(o.refresh=t.refresh),t.aal!=null&&(o.aal=t.aal),t.returnTo!=null&&(o.return_to=t.returnTo),t.loginChallenge!=null&&(o.login_challenge=t.loginChallenge),t.organization!=null&&(o.organization=t.organization),t.via!=null&&(o.via=t.via);const i={};t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/login/browser",method:"GET",headers:i,query:o},n);return new g(r,a=>Ue(a))}async createBrowserLoginFlow(t={},n){return await(await this.createBrowserLoginFlowRaw(t,n)).value()}async createBrowserLogoutFlowRaw(t,n){const o={};t.returnTo!=null&&(o.return_to=t.returnTo);const i={};t.cookie!=null&&(i.cookie=String(t.cookie));const r=await this.request({path:"/self-service/logout/browser",method:"GET",headers:i,query:o},n);return new g(r,a=>Co(a))}async createBrowserLogoutFlow(t={},n){return await(await this.createBrowserLogoutFlowRaw(t,n)).value()}async createBrowserRecoveryFlowRaw(t,n){const o={};t.returnTo!=null&&(o.return_to=t.returnTo);const i={},r=await this.request({path:"/self-service/recovery/browser",method:"GET",headers:i,query:o},n);return new g(r,a=>de(a))}async createBrowserRecoveryFlow(t={},n){return await(await this.createBrowserRecoveryFlowRaw(t,n)).value()}async createBrowserRegistrationFlowRaw(t,n){const o={};t.returnTo!=null&&(o.return_to=t.returnTo),t.loginChallenge!=null&&(o.login_challenge=t.loginChallenge),t.afterVerificationReturnTo!=null&&(o.after_verification_return_to=t.afterVerificationReturnTo),t.organization!=null&&(o.organization=t.organization);const i={},r=await this.request({path:"/self-service/registration/browser",method:"GET",headers:i,query:o},n);return new g(r,a=>Ae(a))}async createBrowserRegistrationFlow(t={},n){return await(await this.createBrowserRegistrationFlowRaw(t,n)).value()}async createBrowserSettingsFlowRaw(t,n){const o={};t.returnTo!=null&&(o.return_to=t.returnTo);const i={};t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/settings/browser",method:"GET",headers:i,query:o},n);return new g(r,a=>we(a))}async createBrowserSettingsFlow(t={},n){return await(await this.createBrowserSettingsFlowRaw(t,n)).value()}async createBrowserVerificationFlowRaw(t,n){const o={};t.returnTo!=null&&(o.return_to=t.returnTo);const i={},r=await this.request({path:"/self-service/verification/browser",method:"GET",headers:i,query:o},n);return new g(r,a=>he(a))}async createBrowserVerificationFlow(t={},n){return await(await this.createBrowserVerificationFlowRaw(t,n)).value()}async createFedcmFlowRaw(t){const n={},o={},i=await this.request({path:"/self-service/fed-cm/parameters",method:"GET",headers:o,query:n},t);return new g(i,r=>Pn(r))}async createFedcmFlow(t){return await(await this.createFedcmFlowRaw(t)).value()}async createNativeLoginFlowRaw(t,n){const o={};t.refresh!=null&&(o.refresh=t.refresh),t.aal!=null&&(o.aal=t.aal),t.returnSessionTokenExchangeCode!=null&&(o.return_session_token_exchange_code=t.returnSessionTokenExchangeCode),t.returnTo!=null&&(o.return_to=t.returnTo),t.organization!=null&&(o.organization=t.organization),t.via!=null&&(o.via=t.via);const i={};t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken));const r=await this.request({path:"/self-service/login/api",method:"GET",headers:i,query:o},n);return new g(r,a=>Ue(a))}async createNativeLoginFlow(t={},n){return await(await this.createNativeLoginFlowRaw(t,n)).value()}async createNativeRecoveryFlowRaw(t){const n={},o={},i=await this.request({path:"/self-service/recovery/api",method:"GET",headers:o,query:n},t);return new g(i,r=>de(r))}async createNativeRecoveryFlow(t){return await(await this.createNativeRecoveryFlowRaw(t)).value()}async createNativeRegistrationFlowRaw(t,n){const o={};t.returnSessionTokenExchangeCode!=null&&(o.return_session_token_exchange_code=t.returnSessionTokenExchangeCode),t.returnTo!=null&&(o.return_to=t.returnTo),t.organization!=null&&(o.organization=t.organization);const i={},r=await this.request({path:"/self-service/registration/api",method:"GET",headers:i,query:o},n);return new g(r,a=>Ae(a))}async createNativeRegistrationFlow(t={},n){return await(await this.createNativeRegistrationFlowRaw(t,n)).value()}async createNativeSettingsFlowRaw(t,n){const o={},i={};t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken));const r=await this.request({path:"/self-service/settings/api",method:"GET",headers:i,query:o},n);return new g(r,a=>we(a))}async createNativeSettingsFlow(t={},n){return await(await this.createNativeSettingsFlowRaw(t,n)).value()}async createNativeVerificationFlowRaw(t,n){const o={};t.returnTo!=null&&(o.return_to=t.returnTo);const i={},r=await this.request({path:"/self-service/verification/api",method:"GET",headers:i,query:o},n);return new g(r,a=>he(a))}async createNativeVerificationFlow(t={},n){return await(await this.createNativeVerificationFlowRaw(t,n)).value()}async disableMyOtherSessionsRaw(t,n){const o={},i={};t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken)),t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/sessions",method:"DELETE",headers:i,query:o},n);return new g(r,a=>zn(a))}async disableMyOtherSessions(t={},n){return await(await this.disableMyOtherSessionsRaw(t,n)).value()}async disableMySessionRaw(t,n){if(t.id==null)throw new S("id",'Required parameter "id" was null or undefined when calling disableMySession().');const o={},i={};t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken)),t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/sessions/{id}".replace("{id}",encodeURIComponent(String(t.id))),method:"DELETE",headers:i,query:o},n);return new De(r)}async disableMySession(t,n){await this.disableMySessionRaw(t,n)}async exchangeSessionTokenRaw(t,n){if(t.initCode==null)throw new S("initCode",'Required parameter "initCode" was null or undefined when calling exchangeSessionToken().');if(t.returnToCode==null)throw new S("returnToCode",'Required parameter "returnToCode" was null or undefined when calling exchangeSessionToken().');const o={};t.initCode!=null&&(o.init_code=t.initCode),t.returnToCode!=null&&(o.return_to_code=t.returnToCode);const i={},r=await this.request({path:"/sessions/token-exchange",method:"GET",headers:i,query:o},n);return new g(r,a=>Le(a))}async exchangeSessionToken(t,n){return await(await this.exchangeSessionTokenRaw(t,n)).value()}async getFlowErrorRaw(t,n){if(t.id==null)throw new S("id",'Required parameter "id" was null or undefined when calling getFlowError().');const o={};t.id!=null&&(o.id=t.id);const i={},r=await this.request({path:"/self-service/errors",method:"GET",headers:i,query:o},n);return new g(r,a=>Qn(a))}async getFlowError(t,n){return await(await this.getFlowErrorRaw(t,n)).value()}async getLoginFlowRaw(t,n){if(t.id==null)throw new S("id",'Required parameter "id" was null or undefined when calling getLoginFlow().');const o={};t.id!=null&&(o.id=t.id);const i={};t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/login/flows",method:"GET",headers:i,query:o},n);return new g(r,a=>Ue(a))}async getLoginFlow(t,n){return await(await this.getLoginFlowRaw(t,n)).value()}async getRecoveryFlowRaw(t,n){if(t.id==null)throw new S("id",'Required parameter "id" was null or undefined when calling getRecoveryFlow().');const o={};t.id!=null&&(o.id=t.id);const i={};t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/recovery/flows",method:"GET",headers:i,query:o},n);return new g(r,a=>de(a))}async getRecoveryFlow(t,n){return await(await this.getRecoveryFlowRaw(t,n)).value()}async getRegistrationFlowRaw(t,n){if(t.id==null)throw new S("id",'Required parameter "id" was null or undefined when calling getRegistrationFlow().');const o={};t.id!=null&&(o.id=t.id);const i={};t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/registration/flows",method:"GET",headers:i,query:o},n);return new g(r,a=>Ae(a))}async getRegistrationFlow(t,n){return await(await this.getRegistrationFlowRaw(t,n)).value()}async getSettingsFlowRaw(t,n){if(t.id==null)throw new S("id",'Required parameter "id" was null or undefined when calling getSettingsFlow().');const o={};t.id!=null&&(o.id=t.id);const i={};t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken)),t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/settings/flows",method:"GET",headers:i,query:o},n);return new g(r,a=>we(a))}async getSettingsFlow(t,n){return await(await this.getSettingsFlowRaw(t,n)).value()}async getVerificationFlowRaw(t,n){if(t.id==null)throw new S("id",'Required parameter "id" was null or undefined when calling getVerificationFlow().');const o={};t.id!=null&&(o.id=t.id);const i={};t.cookie!=null&&(i.cookie=String(t.cookie));const r=await this.request({path:"/self-service/verification/flows",method:"GET",headers:i,query:o},n);return new g(r,a=>he(a))}async getVerificationFlow(t,n){return await(await this.getVerificationFlowRaw(t,n)).value()}async getWebAuthnJavaScriptRaw(t){const n={},o={},i=await this.request({path:"/.well-known/ory/webauthn.js",method:"GET",headers:o,query:n},t);return this.isJsonMime(i.headers.get("content-type"))?new g(i):new bn(i)}async getWebAuthnJavaScript(t){return await(await this.getWebAuthnJavaScriptRaw(t)).value()}async listMySessionsRaw(t,n){const o={};t.perPage!=null&&(o.per_page=t.perPage),t.page!=null&&(o.page=t.page),t.pageSize!=null&&(o.page_size=t.pageSize),t.pageToken!=null&&(o.page_token=t.pageToken);const i={};t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken)),t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/sessions",method:"GET",headers:i,query:o},n);return new g(r,a=>a.map(fe))}async listMySessions(t={},n){return await(await this.listMySessionsRaw(t,n)).value()}async performNativeLogoutRaw(t,n){if(t.performNativeLogoutBody==null)throw new S("performNativeLogoutBody",'Required parameter "performNativeLogoutBody" was null or undefined when calling performNativeLogout().');const o={},i={};i["Content-Type"]="application/json";const r=await this.request({path:"/self-service/logout/api",method:"DELETE",headers:i,query:o,body:To(t.performNativeLogoutBody)},n);return new De(r)}async performNativeLogout(t,n){await this.performNativeLogoutRaw(t,n)}async toSessionRaw(t,n){const o={};t.tokenizeAs!=null&&(o.tokenize_as=t.tokenizeAs);const i={};t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken)),t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/sessions/whoami",method:"GET",headers:i,query:o},n);return new g(r,a=>fe(a))}async toSession(t={},n){return await(await this.toSessionRaw(t,n)).value()}async updateFedcmFlowRaw(t,n){if(t.updateFedcmFlowBody==null)throw new S("updateFedcmFlowBody",'Required parameter "updateFedcmFlowBody" was null or undefined when calling updateFedcmFlow().');const o={},i={};i["Content-Type"]="application/json";const r=await this.request({path:"/self-service/fed-cm/token",method:"POST",headers:i,query:o,body:Wo(t.updateFedcmFlowBody)},n);return new g(r,a=>Le(a))}async updateFedcmFlow(t,n){return await(await this.updateFedcmFlowRaw(t,n)).value()}async updateLoginFlowRaw(t,n){if(t.flow==null)throw new S("flow",'Required parameter "flow" was null or undefined when calling updateLoginFlow().');if(t.updateLoginFlowBody==null)throw new S("updateLoginFlowBody",'Required parameter "updateLoginFlowBody" was null or undefined when calling updateLoginFlow().');const o={};t.flow!=null&&(o.flow=t.flow);const i={};i["Content-Type"]="application/json",t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken)),t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/login",method:"POST",headers:i,query:o,body:si(t.updateLoginFlowBody)},n);return new g(r,a=>Le(a))}async updateLoginFlow(t,n){return await(await this.updateLoginFlowRaw(t,n)).value()}async updateLogoutFlowRaw(t,n){const o={};t.token!=null&&(o.token=t.token),t.returnTo!=null&&(o.return_to=t.returnTo);const i={};t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/logout",method:"GET",headers:i,query:o},n);return new De(r)}async updateLogoutFlow(t={},n){await this.updateLogoutFlowRaw(t,n)}async updateRecoveryFlowRaw(t,n){if(t.flow==null)throw new S("flow",'Required parameter "flow" was null or undefined when calling updateRecoveryFlow().');if(t.updateRecoveryFlowBody==null)throw new S("updateRecoveryFlowBody",'Required parameter "updateRecoveryFlowBody" was null or undefined when calling updateRecoveryFlow().');const o={};t.flow!=null&&(o.flow=t.flow),t.token!=null&&(o.token=t.token);const i={};i["Content-Type"]="application/json",t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/recovery",method:"POST",headers:i,query:o,body:wi(t.updateRecoveryFlowBody)},n);return new g(r,a=>de(a))}async updateRecoveryFlow(t,n){return await(await this.updateRecoveryFlowRaw(t,n)).value()}async updateRegistrationFlowRaw(t,n){if(t.flow==null)throw new S("flow",'Required parameter "flow" was null or undefined when calling updateRegistrationFlow().');if(t.updateRegistrationFlowBody==null)throw new S("updateRegistrationFlowBody",'Required parameter "updateRegistrationFlowBody" was null or undefined when calling updateRegistrationFlow().');const o={};t.flow!=null&&(o.flow=t.flow);const i={};i["Content-Type"]="application/json",t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/registration",method:"POST",headers:i,query:o,body:Ni(t.updateRegistrationFlowBody)},n);return new g(r,a=>Vo(a))}async updateRegistrationFlow(t,n){return await(await this.updateRegistrationFlowRaw(t,n)).value()}async updateSettingsFlowRaw(t,n){if(t.flow==null)throw new S("flow",'Required parameter "flow" was null or undefined when calling updateSettingsFlow().');if(t.updateSettingsFlowBody==null)throw new S("updateSettingsFlowBody",'Required parameter "updateSettingsFlowBody" was null or undefined when calling updateSettingsFlow().');const o={};t.flow!=null&&(o.flow=t.flow);const i={};i["Content-Type"]="application/json",t.xSessionToken!=null&&(i["X-Session-Token"]=String(t.xSessionToken)),t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/settings",method:"POST",headers:i,query:o,body:Gi(t.updateSettingsFlowBody)},n);return new g(r,a=>we(a))}async updateSettingsFlow(t,n){return await(await this.updateSettingsFlowRaw(t,n)).value()}async updateVerificationFlowRaw(t,n){if(t.flow==null)throw new S("flow",'Required parameter "flow" was null or undefined when calling updateVerificationFlow().');if(t.updateVerificationFlowBody==null)throw new S("updateVerificationFlowBody",'Required parameter "updateVerificationFlowBody" was null or undefined when calling updateVerificationFlow().');const o={};t.flow!=null&&(o.flow=t.flow),t.token!=null&&(o.token=t.token);const i={};i["Content-Type"]="application/json",t.cookie!=null&&(i.Cookie=String(t.cookie));const r=await this.request({path:"/self-service/verification",method:"POST",headers:i,query:o,body:ji(t.updateVerificationFlowBody)},n);return new g(r,a=>he(a))}async updateVerificationFlow(t,n){return await(await this.updateVerificationFlowRaw(t,n)).value()}}function V(e){return typeof e=="object"&&!!e&&"error"in e&&typeof e.error=="object"&&!!e.error&&"id"in e.error}function or(e){return V(e)&&e.error.id==="session_refresh_required"}function wt(e){return V(e)&&e.error.id==="self_service_flow_expired"}function ir(e){return V(e)&&V(e)&&e.error.id==="browser_location_change_required"}function _e(e){return V(e)&&e.error.id==="session_already_available"}function rr(e){return V(e)&&e.error.id==="session_aal2_required"}function ar(e){return V(e)&&e.error.id==="security_csrf_violation"}const sr=e=>e instanceof Y?!0:typeof e=="object"&&!!e&&"name"in e&&e.name==="ResponseError",B=e=>async t=>{if(sr(t))switch(t.response.status){case 404:e.onRestartFlow();return;case 410:{const n=await pt(t.response);if(wt(n)){e.onRestartFlow(n.use_flow_id);return}e.onRestartFlow();return}case 400:return e.onValidationError(await t.response.json());case 403:case 422:{const n=await pt(t.response);if(ir(n)&&n.redirect_browser_to){e.onRedirect(n.redirect_browser_to,!0);return}else if(wt(n)){e.onRestartFlow(n.use_flow_id);return}else if(or(n)){e.onRedirect(n.redirect_browser_to,!0);return}else if(ar(n)){e.onRestartFlow();return}throw new Y(t.response,"The Ory API endpoint returned a response code the SDK does not know how to handle. Please check the network tab for more information:"+JSON.stringify(n))}default:throw new Y(t.response,"The Ory API endpoint returned a response code the SDK does not know how to handle. Please check the network tab for more information.")}else if(t instanceof Re)throw new Re(t,"Unable to call the API endpoint. Ensure that CORS is set up correctly and that you have provided a valid SDK URL to Ory Elements.");throw t};async function pt(e){try{return await e.clone().json()}catch{throw new Y(e,"The Ory API endpoint returned a response the SDK does not know how to handle:"+await e.text())}}const ht=["show_settings_ui","show_recovery_ui","show_verification_ui","redirect_browser_to","set_ory_session_token"];function Pe(e,{onRedirect:t}){if(!e||e.length===0)return!1;const n=cr(e);if(!n)return!1;const o=(i,r,a)=>a?(t(a,!0),!0):(t("/"+r+"?flow="+i,!1),!0);if(lr(n))throw new Error("Ory Elements does not support API flows yet.");if(ur(n)&&n.redirect_browser_to)return t(n.redirect_browser_to,!0),!0;if(wr(n))return o(n.flow.id,"verification",n.flow.url);if(dr(n))return o(n.flow.id,"recovery",n.flow.url);if(fr(n))return o(n.flow.id,"settings",n.flow.url);throw new Error("Unknown action: "+JSON.stringify(n))}function cr(e){return!e||e.length===0?void 0:e.toSorted((n,o)=>ht.indexOf(n.action)-ht.indexOf(o.action))[0]}function lr(e){return e.action==="set_ory_session_token"}function ur(e){return e.action==="redirect_browser_to"}function dr(e){return e.action==="show_recovery_ui"}function fr(e){return e.action==="show_settings_ui"}function wr(e){return e.action==="show_verification_ui"}function We(e){return e.node_type==="input"}function _t({attributes:e}){return We(e)?e.name:e.id}const gt=e=>!(typeof e!="object"||e===null||!ro(e)||e.type!==io.Error),pr=e=>!(typeof e!="object"||e===null||!("id"in e)||typeof e.id!="string"||"context"in e&&(typeof e.context!="object"||e.context===null)||"originalError"in e&&!gt(e.originalError)),mt=e=>e?.filter(gt).map(_r)??[],C=({onSubmit:e,onChange:t,onBlur:n}={})=>{const o=[...Array.isArray(e)?e:[],...Array.isArray(t)?t:[],...Array.isArray(n)?n:[]].filter(pr);return[...new Map(o.map(i=>[i.id,i])).values()]};var ie=(e=>(e.FieldMismatch="FieldMismatch",e.FieldRequired="FieldRequired",e))(ie||{});const ge=e=>({id:`AdditionalValidationError_${e}`}),hr=e=>{const t=(h,v)=>({id:`${h}_${v}`,originalError:e}),n=(h,v,Q)=>({id:`${h}_${v}_WithContext`,context:Q,originalError:e});return{createGenericError:h=>t("Error",h),createGenericErrorWithContext:(h,v)=>n("Error",h,v),createLoginFlowError:h=>t("LoginFlowError",h),createLoginFlowErrorWithContext:(h,v)=>n("LoginFlowError",h,v),createRegisterFlowError:h=>t("RegisterFlowError",h),createRegisterFlowErrorWithContext:(h,v)=>n("RegisterFlowError",h,v),createSettingsFlowError:h=>t("SettingsFlowError",h),createSettingsFlowErrorWithContext:(h,v)=>n("SettingsFlowError",h,v),createRecoveryFlowError:h=>t("RecoveryFlowError",h),createRecoveryFlowErrorWithContext:(h,v)=>n("RecoveryFlowError",h,v),createVerificationFlowError:h=>t("VerificationFlowError",h),createVerificationFlowErrorWithContext:(h,v)=>n("VerificationFlowError",h,v)}},_r=e=>{const{createGenericError:t,createGenericErrorWithContext:n,createLoginFlowError:o,createLoginFlowErrorWithContext:i,createRegisterFlowError:r,createRegisterFlowErrorWithContext:a,createSettingsFlowError:c,createSettingsFlowErrorWithContext:u,createRecoveryFlowError:w,createRecoveryFlowErrorWithContext:f,createVerificationFlowError:d,createVerificationFlowErrorWithContext:_}=hr(e);switch(e.id){case 4000001:return p(e.context,"reason","string")?n("InvalidFormat",{reason:e.context.reason}):t("InvalidFormat");case 4000002:return p(e.context,"property","string")?n("MissingProperty",{property:e.context.property}):t("MissingProperty");case 4000003:return p(e.context,"min_length","number")&&p(e.context,"actual_length","number")?n("TooShort",{min_length:e.context.min_length,actual_length:e.context.actual_length}):t("TooShort");case 4000004:return p(e.context,"pattern","string")?n("InvalidPattern",{pattern:e.context.pattern}):t("InvalidPattern");case 4000005:return p(e.context,"reason","string")?n("PasswordPolicyViolation",{reason:e.context.reason}):t("PasswordPolicyViolation");case 4000006:return t("InvalidCredentials");case 4000007:return t("DuplicateCredentials");case 4000008:return t("TOTPVerifierWrong");case 4000009:return t("IdentifierMissing");case 4000010:return t("AddressNotVerified");case 4000011:return t("NoTOTPDeviceSetUp");case 4000012:return t("RecoveryCodeAlreadyUsed");case 4000013:return t("NoWebAuthnDeviceSetUp");case 4000014:return t("NoRecoveryCodesSetUp");case 4000015:return t("AccountNotExistsOrHasSecurityKey");case 4000016:return t("InvalidRecoveryCode");case 4000017:return p(e.context,"max_length","number")&&p(e.context,"actual_length","number")?n("TooLong",{max_length:e.context.max_length,actual_length:e.context.actual_length}):t("TooLong");case 4000018:return p(e.context,"actual","number")&&p(e.context,"minimum","number")?n("MustBeGreaterOrEqualThan",{actual:e.context.actual,minimum:e.context.minimum}):t("MustBeGreaterOrEqualThan");case 4000019:return p(e.context,"actual","number")&&p(e.context,"minimum","number")?n("MustBeGreaterThan",{actual:e.context.actual,minimum:e.context.minimum}):t("MustBeGreaterThan");case 4000020:return p(e.context,"actual","number")&&p(e.context,"maximum","number")?n("MustBeLessOrEqualThan",{actual:e.context.actual,maximum:e.context.maximum}):t("MustBeLessOrEqualThan");case 4000021:return p(e.context,"actual","number")&&p(e.context,"maximum","number")?n("MustBeLessThan",{actual:e.context.actual,maximum:e.context.maximum}):t("MustBeLessThan");case 4000022:return p(e.context,"actual","number")&&p(e.context,"base","number")?n("IsNotMultipleOf",{actual:e.context.actual,base:e.context.base}):t("IsNotMultipleOf");case 4000023:return p(e.context,"max_items","number")&&p(e.context,"actual_items","number")?n("TooManyItems",{max_items:e.context.max_items,actual_items:e.context.actual_items}):t("TooManyItems");case 4000024:return p(e.context,"min_items","number")&&p(e.context,"actual_items","number")?n("TooFewItems",{min_items:e.context.min_items,actual_items:e.context.actual_items}):t("TooFewItems");case 4000025:return p(e.context,"index_a","number")&&p(e.context,"index_b","number")?n("DuplicateItems",{index_a:e.context.index_a,index_b:e.context.index_b}):t("DuplicateItems");case 4000026:return p(e.context,"actual_type","string")&&p(e.context,"allowed_types","object")&&Array.isArray(e.context.allowed_types)&&e.context.allowed_types.every(F=>typeof F=="string")?n("InvalidType",{actual_type:e.context.actual_type,allowed_types:e.context.allowed_types}):t("InvalidType");case 4000027:return t("AccountAlreadyExists");case 4000028:return p(e.context,"credential_identifier_hint","string")&&p(e.context,"available_credential_types","object")&&Array.isArray(e.context.available_credential_types)&&e.context.available_credential_types.every(F=>typeof F=="string")&&p(e.context,"available_oidc_providers","object")&&Array.isArray(e.context.available_oidc_providers)&&e.context.available_oidc_providers.every(F=>typeof F=="string")?n("CredentialIdentifierHintAlreadyUsedByOtherAccount",{available_credential_types:e.context.available_credential_types,available_oidc_providers:e.context.available_oidc_providers,credential_identifier_hint:e.context.credential_identifier_hint}):t("CredentialIdentifierHintAlreadyUsedByOtherAccount");case 4000029:return p(e.context,"expected","string")?n("MustBeEqualTo",{expected:e.context.expected}):t("MustBeEqualTo");case 4000030:return t("ConstFailed");case 4000031:return t("PasswordAndIdentifierTooSimilar");case 4000032:return p(e.context,"min_length","number")&&p(e.context,"actual_length","number")?n("PasswordTooShort",{min_length:e.context.min_length,actual_length:e.context.actual_length}):t("PasswordTooShort");case 4000033:return p(e.context,"max_length","number")&&p(e.context,"actual_length","number")?n("PasswordTooLong",{max_length:e.context.max_length,actual_length:e.context.actual_length}):t("PasswordTooLong");case 4000034:return p(e.context,"breaches","number")?n("PasswordLeaked",{breaches:e.context.breaches}):t("PasswordLeaked");case 4000035:return t("AccountNotExistsOrWithoutCodeSignIn");case 4000036:return t("TraitsDoNotMatch");case 4000037:return t("AccountNotExistsOrWithoutLoginMethod");case 4000038:return t("CaptchaFailed");case 4010001:return p(e.context,"expired_at","string")&&p(e.context,"expired_at_unix","number")?i("LoginFlowExpired",{expired_at:e.context.expired_at,expired_at_unix:e.context.expired_at_unix}):o("LoginFlowExpired");case 4010002:return o("NoLogInStrategyFound");case 4010003:return o("NoSignUpStrategyFound");case 4010004:return o("NoSettingsStrategyFound");case 4010005:return o("NoRecoveryStrategyFound");case 4010006:return o("NoVerificationStrategyFound");case 4010007:return o("LoginRequestAlreadyCompletedSuccessfully");case 4010008:return o("InvalidLoginCodeOrAlreadyUsed");case 4010009:return o("MismatchedLinkedCretentials");case 4010010:return o("MismatchedAddress");case 4040001:return p(e.context,"expired_at","string")&&p(e.context,"expired_at_unix","number")?a("RegisterFlowExpired",{expired_at:e.context.expired_at,expired_at_unix:e.context.expired_at_unix}):r("RegisterFlowExpired");case 4040002:return r("RegisterRequestAlreadyCompletedSuccessfully");case 4040003:return r("InvalidRegisterCodeOrAlreadyUsed");case 4050001:return p(e.context,"expired_at","string")&&p(e.context,"expired_at_unix","number")?u("SettingsFlowExpired",{expired_at:e.context.expired_at,expired_at_unix:e.context.expired_at_unix}):c("SettingsFlowExpired");case 4060001:return w("RecoveryRequestAlreadyCompletedSuccessfully");case 4060002:return w("RecoveryFlowFailureState");case 4060004:return w("InvalidTokenOrAlreadyUsed");case 4060005:return p(e.context,"expired_at","string")&&p(e.context,"expired_at_unix","number")?f("RecoveryFlowExpired",{expired_at:e.context.expired_at,expired_at_unix:e.context.expired_at_unix}):w("RecoveryFlowExpired");case 4060006:return w("InvalidRecoveryCodeOrAlreadyUsed");case 4070001:return d("InvalidVerificationTokenOrAlreadyUsed");case 4070002:return d("VerificationRequestAlreadyCompletedSuccessfully");case 4070003:return d("VerificationFlowFailureState");case 4070005:return p(e.context,"expired_at","string")&&p(e.context,"expired_at_unix","number")?_("VerificationFlowExpired",{expired_at:e.context.expired_at,expired_at_unix:e.context.expired_at_unix}):d("VerificationFlowExpired");case 4070006:return d("InvalidVerificationCodeOrAlreadyUsed");default:return p(e.context,"reason","string")?n("Generic",{reason:e.context.reason}):t("Generic")}};function O(e,t){return e?.find(n=>_t(n)===t)}function gr(e,t){return e?.filter(n=>_t(n)===t)??[]}function $(e){if(e&&We(e.attributes))return e.attributes}function mr(e){if(e&&We(e.attributes))return e.messages}function k(e){const t=$(O(e.ui.nodes,"csrf_token"));if(!t||typeof t.value!="string")throw new Error("CSRF token not found");return t.value}const yr=e=>{if(e.group!==yo.Passkey||e.type!==Fo.Input||e.attributes.node_type!==po.Input||e.attributes.name!=="passkey_remove"||!e.meta?.label?.context)return!1;const{context:t}=e.meta.label;return"added_at"in t&&typeof t.added_at=="string"&&"display_name"in t&&typeof t.display_name=="string"&&"added_at_unix"in t&&typeof t.added_at_unix=="number"},yt=e=>e.group==="oidc"&&e.attributes.node_type==="input"&&typeof e.attributes.value=="string",Fr=(e,t)=>e?.find(n=>yt(n)&&n.attributes.value===t)??void 0,Be=e=>e?.filter(t=>yt(t))??[],qe=(e,t)=>e!==void 0&&e.some(n=>n.id===t),re=async({error:e})=>await B({onRedirect:(t,n)=>{globalThis.location.href=t},onRestartFlow:()=>{throw new Error("Needs to restart the flow",{cause:P.FlowRestartRequired})},onValidationError:t=>t})(e),N=(e,t,n)=>{const o=mt(e.ui.messages);o.length>0&&(t.setErrorMap({onSubmit:o}),n?.({target:"root",errors:o}));for(const i in t.fieldInfo){const r=i,a=mt(mr(O(e.ui.nodes,r)));a.length>0&&(t.setFieldMeta(r,c=>({...c,errorMap:{onSubmit:a}})),n?.({target:r,errors:a}))}},$e="leancode_kratos",K=e=>[$e,...e],z=e=>`${$e}_${e}`;function I(e){return l.useMemo(()=>C(e.state.errorMap),[e.state.errorMap])}const Ft=l.createContext(void 0);function x(){const e=l.useContext(Ft);if(e===void 0)throw new Error("useKratosClientContext must be used within a KratosClientContextProvider");return e}function vr({children:e,api:t}){const n=l.useMemo(()=>({kratosClient:t}),[t]);return s.jsx(Ft.Provider,{value:n,children:e})}function E({children:e}){const t=y.Root;return s.jsx(t,{type:"submit",children:e})}const vt=l.createContext(void 0);function Sr({children:e,emailVerificationForm:t}){const n=l.useMemo(()=>({emailVerificationForm:t}),[t]);return s.jsx(vt.Provider,{value:n,children:e})}function kr(){const e=l.useContext(vt);if(e===void 0)throw new Error("useEmailVerificationFormContext must be used within a EmailVerificationFormProvider");return e}const br=z("verification_flow"),me=(e="no_id")=>K([br,e]),St=l.createContext(void 0);function ye({children:e}){const[t,n]=l.useState(),[o,i]=l.useState(),r=l.useCallback(()=>{n(void 0),i(void 0)},[]);return s.jsx(St.Provider,{value:{verificationFlowId:t,setVerificationFlowId:n,verifiableAddress:o,setVerifiableAddress:i,resetFlow:r},children:e})}function J(){const e=l.useContext(St);if(e===void 0)throw new Error("useVerificationFlow must be used within a VerificationFlowProvider");return e}function Cr({returnTo:e}={}){const{kratosClient:t}=x(),{setVerificationFlowId:n}=J(),o=m.useQueryClient();return m.useMutation({mutationFn:()=>t.createBrowserVerificationFlow({returnTo:e},async({init:{headers:i}})=>({headers:{...i,Accept:"application/json"}})),onSuccess(i){o.setQueryDefaults(me(i.id),{staleTime:1/0}),o.setQueryData(me(i.id),i),n(i.id)}})}function Ke(){const{kratosClient:e}=x(),{verificationFlowId:t}=J();return m.useQuery({queryKey:me(t),queryFn:async({signal:n})=>{if(!t)throw new Error("No verification flow ID provided",{cause:P.NoFlowId});try{return await e.getVerificationFlow({id:t},async({init:{headers:o}})=>({signal:n,headers:{...o,Accept:"application/json"}}))}catch(o){throw await re({error:o})}},enabled:!!t,staleTime:1/0})}function kt(){const{kratosClient:e}=x(),{verificationFlowId:t,resetFlow:n}=J(),o=m.useQueryClient();return m.useMutation({mutationFn:async i=>{if(!t)throw new Error("Verification flow ID is not set");try{const r=await e.updateVerificationFlow({flow:t,updateVerificationFlowBody:i},{headers:{Accept:"application/json","Content-Type":"application/json"}});return r.state===ft.PassedChallenge&&r.return_to&&(globalThis.location.href=r.return_to),r}catch(r){return await B({onRedirect:(a,c)=>{globalThis.location.href=a},onRestartFlow:n,onValidationError:a=>a})(r)}},onSuccess(i){i&&"id"in i&&o.setQueryData(me(i.id),i)}})}function xr({children:e}){const{verifiableAddress:t}=J(),{mutate:n}=kt(),{data:o}=Ke(),i=l.useCallback(()=>{!o||!t||n({method:"code",csrf_token:k(o),email:t,code:""})},[o,t,n]),r=y.Root;return s.jsx(r,{type:"button",onClick:i,children:e})}function Tr({children:e}){const{emailVerificationForm:t}=kr(),n=y.Root;return s.jsx(t.Field,{name:"code",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"text",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}var bt=(e=>(e.Code="code",e))(bt||{});function Or({onError:e,onVerificationSuccess:t}){const{verifiableAddress:n}=J(),{mutateAsync:o}=kt(),{data:i}=Ke();return D.useForm({defaultValues:{[bt.Code]:""},onSubmit:async({value:r,formApi:a})=>{if(!i||!n)return;const c=await o({csrf_token:k(i),method:"code",code:r.code,email:n});if(c){if(c.state==ft.PassedChallenge){t?.();return}N(c,a,e)}}})}function Nr({emailVerificationForm:e,onError:t,onVerificationSuccess:n}){const o=Or({onError:t,onVerificationSuccess:n}),i=I(o);return s.jsx(Sr,{emailVerificationForm:o,children:s.jsx("form",{onSubmit:r=>{r.preventDefault(),o.handleSubmit()},children:s.jsx(e,{Code:Tr,errors:i,isSubmitting:o.state.isSubmitting,isValidating:o.state.isValidating,Resend:xr,Submit:E})})})}function Ct(e){return s.jsx(ye,{children:s.jsx(Fe,{...e})})}function Fe({emailVerificationForm:e,initialFlowId:t,initialVerifiableAddress:n,returnTo:o,onError:i,onVerificationSuccess:r,onFlowRestart:a}){const{verificationFlowId:c,setVerificationFlowId:u,verifiableAddress:w,setVerifiableAddress:f}=J(),{error:d}=Ke(),{mutate:_}=Cr({returnTo:o});return ne({initialFlowId:t,currentFlowId:c,error:d,onFlowRestart:a,createFlow:_,setFlowId:u}),!w&&n&&f(n),s.jsx(Nr,{emailVerificationForm:e,onError:i,onVerificationSuccess:r})}const Er=Object.freeze(Object.defineProperty({__proto__:null,VerificationFlow:Ct,VerificationFlowProvider:ye,VerificationFlowWrapper:Fe,useVerificationFlowContext:J},Symbol.toStringTag,{value:"Module"})),Mr=z("login_flow"),ve=(e="no_id")=>K([Mr,e]),xt=l.createContext(void 0);function Rr({children:e}){const[t,n]=l.useState(),o=l.useCallback(()=>{n(void 0)},[]);return s.jsx(xt.Provider,{value:{loginFlowId:t,setLoginFlowId:n,resetFlow:o},children:e})}function Se(){const e=l.useContext(xt);if(e===void 0)throw new Error("useLoginFlowContext must be used within a LoginFlow");return e}function Dr({aal:e,refresh:t,returnTo:n}={}){const{kratosClient:o}=x(),{setLoginFlowId:i}=Se(),r=m.useQueryClient();return m.useMutation({mutationFn:async()=>{try{return await o.createBrowserLoginFlow({aal:e,refresh:t,returnTo:n},async({init:{headers:a}})=>({headers:{...a,Accept:"application/json"}}))}catch(a){throw await B({onRestartFlow:()=>{},onRedirect:()=>{},onValidationError:c=>c})(a)}},onSuccess(a){r.setQueryDefaults(ve(a.id),{staleTime:1/0}),r.setQueryData(ve(a.id),a),i(a.id)}})}function U(){const{kratosClient:e}=x(),{loginFlowId:t}=Se();return m.useQuery({queryKey:ve(t),queryFn:async({signal:n})=>{if(!t)throw new Error("No login flow ID provided",{cause:P.NoFlowId});try{return await e.getLoginFlow({id:t},async({init:{headers:o}})=>({signal:n,headers:{...o,Accept:"application/json"}}))}catch(o){throw await re({error:o})}},enabled:!!t,staleTime:1/0})}const Tt=()=>{const{data:e}=U();return l.useMemo(()=>{if(!e)return;const t=O(e.ui.nodes,"identifier");if(!(!t||t.attributes.node_type!=="input"||typeof t.attributes.value!="string"))return t.attributes.value},[e])};function G(){const{kratosClient:e}=x(),{loginFlowId:t,resetFlow:n}=Se(),{setVerificationFlowId:o,setVerifiableAddress:i}=J(),r=m.useQueryClient();return m.useMutation({mutationFn:async a=>{if(!t)throw new Error("Login flow ID is not set");try{const u=await(await e.updateLoginFlowRaw({flow:t,updateLoginFlowBody:a},{headers:{Accept:"application/json","Content-Type":"application/json"}})).value();if(u&&"continue_with"in u){const w=u.continue_with?.find(f=>f.action==="show_verification_ui");w!==void 0?(o(w.flow.id),i(w.flow.verifiable_address)):Pe(u.continue_with,{onRedirect:(f,d)=>{globalThis.location.href=f}})}return u}catch(c){return await B({onRedirect:(u,w)=>{globalThis.location.href=u},onRestartFlow:n,onValidationError:u=>u})(c)}},onSuccess(a){a&&"id"in a&&r.setQueryData(ve(a.id),a)}})}const Ot=l.createContext(void 0);function Ir({children:e,passwordForm:t}){const n=l.useMemo(()=>({passwordForm:t}),[t]);return s.jsx(Ot.Provider,{value:n,children:e})}function ze(){const e=l.useContext(Ot);if(e===void 0)throw new Error("useChooseMethodFormContext must be used within a ChooseMethodFormProvider");return e}function Jr({children:e,provider:t}){const{mutate:n}=G(),{data:o}=U(),i=l.useCallback(()=>{o&&n({method:"oidc",csrf_token:k(o),provider:t})},[o,n,t]),r=y.Root;return s.jsx(r,{type:"button",onClick:i,children:e})}function Ur({children:e}){const{passwordForm:t}=ze(),n=y.Root;return s.jsx(t.Field,{name:"identifier",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"text",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}function Nt({children:e}){const{passwordForm:t}=ze(),n=y.Root;return s.jsx(t.Field,{name:"password",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"password",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}function Ar({children:e,onError:t,onLoginSuccess:n}){const{mutateAsync:o}=G(),{data:i}=U(),{passwordForm:r}=ze(),a=l.useCallback(async d=>{if(!i)return;const _=await o({method:"passkey",csrf_token:k(i),passkey_login:d});if(_){if(pe(_)){n?.();return}N(_,r,t)}},[i,t,n,r,o]),c=l.useMemo(()=>$(O(i?.ui.nodes,"passkey_challenge")),[i?.ui.nodes]),u=l.useMemo(()=>K([z("passkey"),c?.value]),[c?.value]);m.useQuery({queryKey:u,queryFn:async({signal:d})=>{if(!c)throw new Error("No challenge provided");const _=await hn(c.value,d);return _?await a(_):!1},enabled:!!c,retry:!1});const w=l.useCallback(async()=>{if(!c)return;const d=await _n(c.value);d&&a(d)},[c,a]),f=y.Root;return s.jsx(f,{type:"button",onClick:w,children:e})}var ae=(e=>(e.Identifier="identifier",e.Password="password",e))(ae||{});function Lr({onError:e,onLoginSuccess:t}){const{mutateAsync:n}=G(),{data:o}=U(),i=Tt();return D.useForm({defaultValues:{[ae.Identifier]:i??"",[ae.Password]:""},onSubmit:async({value:r,formApi:a})=>{if(!o)return;const c=await n({csrf_token:k(o),method:"password",identifier:r[ae.Identifier],password:r[ae.Password]});if(c){if(pe(c)){t?.();return}N(c,a,e)}}})}function Vr({chooseMethodForm:e,oidcProvidersConfig:t,isRefresh:n,onError:o,onLoginSuccess:i}){const{data:r}=U(),a=Lr({onError:o,onLoginSuccess:i}),c=I(a),u=Tt(),w=l.useCallback(d=>s.jsx(Ar,{...d,onError:o}),[o]),f=l.useMemo(()=>{if(!r)return{};const d=Be(r.ui.nodes),_={};return d.forEach(F=>{const T=F.attributes.value;if(!qe(t,T))return;const h=Ne.toUpperFirst(T);_[h]=({children:v})=>s.jsx(Jr,{provider:T,children:v})}),_},[r,t]);return r?s.jsx(Ir,{passwordForm:a,children:s.jsx("form",{onSubmit:d=>{d.preventDefault(),a.handleSubmit()},children:n?s.jsx(e,{isRefresh:!0,errors:c,identifier:u,isSubmitting:a.state.isSubmitting,isValidating:a.state.isValidating,oidcProviders:f,Passkey:O(r.ui.nodes,"passkey_login")&&w,passwordFields:O(r.ui.nodes,"password")?{Password:Nt,Submit:E}:void 0}):s.jsx(e,{errors:c,isSubmitting:a.state.isSubmitting,isValidating:a.state.isValidating,oidcProviders:f,Passkey:w,passwordFields:{Identifier:Ur,Password:Nt,Submit:E}})})}):null}function Pr({children:e}){const{mutate:t}=G(),{data:n}=U(),o=l.useCallback(()=>{if(!n)return;const r=$(O(n.ui.nodes,"identifier"))?.value;t({method:"code",csrf_token:k(n),resend:"code",identifier:r})},[n,t]),i=y.Root;return s.jsx(i,{type:"button",onClick:o,children:e})}const Et=l.createContext(void 0);function Wr({children:e,codeForm:t}){const n=l.useMemo(()=>({codeForm:t}),[t]);return s.jsx(Et.Provider,{value:n,children:e})}function Br(){const e=l.useContext(Et);if(e===void 0)throw new Error("useSecondFactorEmailFormContext must be used within a SecondFactorEmailFormProvider");return e}function qr({children:e}){const{codeForm:t}=Br(),n=y.Root;return s.jsx(t.Field,{name:"code",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"text",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}var Mt=(e=>(e.Code="code",e))(Mt||{});function $r({onError:e,onLoginSuccess:t}){const{mutateAsync:n}=G(),{data:o}=U();return D.useForm({defaultValues:{[Mt.Code]:""},onSubmit:async({value:i,formApi:r})=>{if(!o)return;const a=$(O(o.ui.nodes,"identifier"))?.value,c=await n({csrf_token:k(o),method:"code",code:i.code,identifier:a});if(c){if(pe(c)){t?.();return}N(c,r,e)}}})}function Kr({secondFactorForm:e,onError:t,onLoginSuccess:n}){const o=$r({onError:t,onLoginSuccess:n}),i=I(o);return s.jsx(Wr,{codeForm:o,children:s.jsx("form",{onSubmit:r=>{r.preventDefault(),o.handleSubmit()},children:s.jsx(e,{Code:qr,errors:i,isSubmitting:o.state.isSubmitting,isValidating:o.state.isValidating,Resend:Pr,Submit:E})})})}function zr({children:e}){const{mutate:t}=G(),{data:n}=U(),o=l.useCallback(()=>{if(!n)return;const r=$(O(n.ui.nodes,"address"))?.value;r&&t({method:"code",csrf_token:k(n),address:r})},[n,t]),i=y.Root;return s.jsx(i,{type:"button",onClick:o,children:e})}const Rt=l.createContext(void 0),Gr=({children:e,totpForm:t})=>{const n=l.useMemo(()=>({totpForm:t}),[t]);return s.jsx(Rt.Provider,{value:n,children:e})};function Qr(){const e=l.useContext(Rt);if(e===void 0)throw new Error("useSecondFactorFormContext must be used within a SecondFactorFormProvider");return e}function Hr({children:e}){const{totpForm:t}=Qr(),n=y.Root;return s.jsx(t.Field,{name:"totp_code",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"text",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}var Dt=(e=>(e.TotpCode="totp_code",e))(Dt||{});function Xr({onError:e,onLoginSuccess:t}){const{mutateAsync:n}=G(),{data:o}=U();return D.useForm({defaultValues:{[Dt.TotpCode]:""},onSubmit:async({value:i,formApi:r})=>{if(!o)return;const a=await n({csrf_token:k(o),method:"totp",totp_code:i.totp_code});if(a){if(pe(a)){t?.();return}N(a,r,e)}}})}function Yr({secondFactorForm:e,isRefresh:t,onError:n,onLoginSuccess:o}){const i=Xr({onError:n,onLoginSuccess:o}),r=I(i),{data:a}=U();return s.jsx(Gr,{totpForm:i,children:s.jsx("form",{onSubmit:c=>{c.preventDefault(),i.handleSubmit()},children:s.jsx(e,{Email:O(a?.ui.nodes,"address")&&zr,errors:r,isRefresh:t,isSubmitting:i.state.isSubmitting,isValidating:i.state.isValidating,Submit:E,Totp:Hr})})})}function Zr({loaderComponent:e,chooseMethodForm:t,secondFactorForm:n,secondFactorEmailForm:o,emailVerificationForm:i,oidcProvidersConfig:r,initialFlowId:a,returnTo:c,onError:u,onLoginSuccess:w,onVerificationSuccess:f,onFlowRestart:d,onSessionAlreadyAvailable:_}){const{loginFlowId:F,setLoginFlowId:T}=Se(),{verificationFlowId:h}=J(),{sessionManager:v}=Ee(),{isAal2Required:Q}=v.useIsAal2Required(),{mutate:te,error:H}=Dr({returnTo:c,aal:Q?"aal2":void 0}),{data:R,error:et}=U();ne({initialFlowId:a,currentFlowId:F,error:et??void 0,onFlowRestart:d,createFlow:te,setFlowId:T,waitForSession:!0});const Oe=l.useMemo(()=>_e(H)||_e(et),[H,et]);l.useEffect(()=>{Oe&&_?.()},[Oe,_]);const ce=l.useMemo(()=>{if(Oe)return"invalid";if(!R)return"loader";if(h)return"verifyEmail";if(R.state==="choose_method"){if(R.requested_aal==="aal1")return"chooseMethod";if(R.requested_aal==="aal2")return"secondFactor"}if(R.state==="sent_email")return"secondFactorEmail";throw new Error("Invalid login flow state")},[R,h,Oe]),sn=l.useMemo(()=>R?.refresh,[R]);return s.jsxs(s.Fragment,{children:[ce==="loader"&&e&&s.jsx(e,{}),ce==="chooseMethod"&&s.jsx(Vr,{chooseMethodForm:t,isRefresh:sn,oidcProvidersConfig:r,onError:u,onLoginSuccess:w}),ce==="secondFactor"&&s.jsx(Yr,{isRefresh:sn,secondFactorForm:n,onError:u,onLoginSuccess:w}),ce==="secondFactorEmail"&&s.jsx(Kr,{secondFactorForm:o,onError:u,onLoginSuccess:w}),ce==="verifyEmail"&&s.jsx(Fe,{emailVerificationForm:i,onError:u,onVerificationSuccess:f})]})}function It(e){return s.jsx(ye,{children:s.jsx(Rr,{children:s.jsx(Zr,{...e})})})}const jr=Object.freeze(Object.defineProperty({__proto__:null,LoginFlow:It},Symbol.toStringTag,{value:"Module"})),Jt=()=>{const{kratosClient:e}=x(),{sessionManager:t}=Ee(),n=m.useQueryClient();return{logout:async({returnTo:i}={})=>{try{const r=await e.createBrowserLogoutFlow({returnTo:i},async({init:{headers:a}})=>({credentials:"include",headers:{...a,Accept:"application/json","Content-Type":"application/json"}}));return await e.updateLogoutFlow({token:r.logout_token},{headers:{Accept:"application/json","Content-Type":"application/json"}}),t.checkIfLoggedIn(),i&&(globalThis.location.href=i),n.removeQueries({queryKey:[$e]}),{isSuccess:!0}}catch(r){return{isSuccess:!1,error:r}}}}},ea=Object.freeze(Object.defineProperty({__proto__:null,useLogout:Jt},Symbol.toStringTag,{value:"Module"})),Ut=l.createContext(void 0);function ta({children:e,chooseMethodForm:t}){const n=l.useMemo(()=>({chooseMethodForm:t}),[t]);return s.jsx(Ut.Provider,{value:n,children:e})}function Ge(){const e=l.useContext(Ut);if(e===void 0)throw new Error("useChooseMethodFormContext must be used within a ChooseMethodFormProvider");return e}const na=z("registration_flow"),ke=(e="no_id")=>K([na,e]),At=l.createContext(void 0);function oa({children:e}){const[t,n]=l.useState(),[o,i]=l.useState(!1),[r,a]=l.useState(),c=l.useCallback(()=>{n(void 0),i(!1),a(void 0)},[]);return s.jsx(At.Provider,{value:{registrationFlowId:t,setRegistrationFlowId:n,traitsFormCompleted:o,setTraitsFormCompleted:i,traits:r,setTraits:a,resetFlow:c},children:e})}function q(){const e=l.useContext(At);if(e===void 0)throw new Error("useRegistrationFlowContext must be used within a RegistrationFlow");return e}function ia({returnTo:e}={}){const{kratosClient:t}=x(),{setRegistrationFlowId:n}=q(),o=m.useQueryClient();return m.useMutation({mutationFn:async()=>{try{return await t.createBrowserRegistrationFlow({returnTo:e},async({init:{headers:i}})=>({headers:{...i,Accept:"application/json"}}))}catch(i){throw await B({onRestartFlow:()=>{},onRedirect:()=>{},onValidationError:r=>r})(i)}},onSuccess(i){o.setQueryDefaults(ke(i.id),{staleTime:1/0}),o.setQueryData(ke(i.id),i),n(i.id)}})}function j(){const{kratosClient:e}=x(),{registrationFlowId:t}=q();return m.useQuery({queryKey:ke(t),queryFn:async({signal:n})=>{if(!t)throw new Error("No registration flow ID provided",{cause:P.NoFlowId});try{return await e.getRegistrationFlow({id:t},async({init:{headers:o}})=>({signal:n,headers:{...o,Accept:"application/json"}}))}catch(o){throw await re({error:o})}},enabled:!!t,staleTime:1/0})}function be(){const{kratosClient:e}=x(),{resetFlow:t,registrationFlowId:n}=q(),{setVerificationFlowId:o,setVerifiableAddress:i}=J(),r=m.useQueryClient();return m.useMutation({mutationFn:async a=>{if(!n)throw new Error("Registration flow ID is not set");try{const u=await(await e.updateRegistrationFlowRaw({flow:n,updateRegistrationFlowBody:a},{headers:{Accept:"application/json","Content-Type":"application/json"}})).value();if(u&&"continue_with"in u){const w=u.continue_with?.find(f=>f.action==="show_verification_ui");w!==void 0?(o(w.flow.id),i(w.flow.verifiable_address)):Pe(u.continue_with,{onRedirect:(f,d)=>{globalThis.location.href=f}})}return u}catch(c){return await B({onRedirect:(u,w)=>{globalThis.location.href=u},onRestartFlow:t,onValidationError:u=>u})(c)}},onSuccess(a){a&&"id"in a&&r.setQueryData(ke(a.id),a)}})}function ra({children:e}){const{setTraitsFormCompleted:t}=q(),n=l.useCallback(()=>{t(!1)},[t]),o=y.Root;return s.jsx(o,{type:"button",onClick:n,children:e})}function aa({children:e,onError:t,onRegistrationSuccess:n}){const{traits:o}=q(),{mutateAsync:i}=be(),{data:r}=j(),{chooseMethodForm:a}=Ge(),c=l.useCallback(async d=>{if(!r)return;const _=await i({method:"passkey",csrf_token:k(r),traits:o??{},passkey_register:d});if(_){if(Ve(_)){n?.();return}N(_,a,t)}},[t,n,r,o,a,i]),u=l.useMemo(()=>$(O(r?.ui.nodes,"passkey_create_data")),[r?.ui.nodes]),w=l.useCallback(async()=>{if(!u)return;const d=await gn(u.value,void 0,o);d&&c(d)},[u,c,o]),f=y.Root;return s.jsx(f,{type:"button",onClick:w,children:e})}function sa({children:e}){const{chooseMethodForm:t}=Ge(),n=y.Root;return s.jsx(t.Field,{name:"password",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"password",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}var A=(e=>(e.Password="password",e.PasswordConfirmation="password_confirmation",e))(A||{});const Lt=({value:e,fieldApi:t})=>{const n=t.form.getFieldMeta(A.PasswordConfirmation);if(n?.isDirty&&n?.isTouched)return Vt(e,t.form.getFieldValue(A.Password))},Vt=(e,t)=>{if(!e)return[ge(ie.FieldRequired)];if(e!==t)return[ge(ie.FieldMismatch)]};function ca({children:e}){const{chooseMethodForm:t}=Ge(),n=y.Root;return s.jsx(t.Field,{listeners:{onChange:({fieldApi:o})=>{o.form.setFieldMeta(A.PasswordConfirmation,i=>({...i,errorMap:{...i.errorMap,onSubmit:void 0}}))}},name:"password_confirmation",validators:{onChangeListenTo:[A.Password],onChange:Lt,onBlurListenTo:[A.PasswordConfirmation],onBlur:Lt,onSubmit:({value:o,fieldApi:i})=>Vt(o,i.form.getFieldValue(A.Password))},children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"password",value:o.state.value,onBlur:o.handleBlur,onChange:i=>o.handleChange(i.target.value),children:e})})}function la({onError:e,onRegistrationSuccess:t}){const{setTraitsFormCompleted:n,traits:o}=q(),{mutateAsync:i}=be(),{data:r}=j();return D.useForm({defaultValues:{[A.Password]:"",[A.PasswordConfirmation]:""},onSubmit:async({value:a,formApi:c})=>{if(!r)return;const u=await i({csrf_token:k(r),method:"password",traits:o??{},password:a[A.Password]});if(u){if(Ve(u)){t?.();return}u.state===dt.ChooseMethod&&n(!0),N(u,c,e)}}})}function ua({chooseMethodForm:e,onError:t,onRegistrationSuccess:n}){const o=la({onError:t,onRegistrationSuccess:n}),i=I(o);return s.jsx(ta,{chooseMethodForm:o,children:s.jsx("form",{onSubmit:r=>{r.preventDefault(),o.handleSubmit()},children:s.jsx(e,{errors:i,isSubmitting:o.state.isSubmitting,isValidating:o.state.isValidating,Passkey:aa,passwordFields:{Password:sa,PasswordConfirmation:ca,Submit:E},ReturnToTraitsForm:ra})})})}function da({children:e,provider:t}){const{mutate:n}=be(),{data:o}=j(),i=l.useCallback(()=>{o&&n({method:"oidc",csrf_token:k(o),provider:t})},[o,n,t]),r=y.Root;return s.jsx(r,{type:"button",onClick:i,children:e})}const Pt=l.createContext(void 0);function fa({children:e,traitsForm:t}){const n=l.useMemo(()=>({traitsForm:t}),[t]);return s.jsx(Pt.Provider,{value:n,children:e})}function Wt(){const e=l.useContext(Pt);if(e===void 0)throw new Error("useTraitsFormContext must be used within a TraitsFormProvider");return e}function wa({trait:e,children:t}){const{traitsForm:n}=Wt(),o=y.Root;return s.jsx(n.Field,{name:`${X}${e}`,children:i=>{if(typeof i.state.value!="string")throw new TypeError("TraitInput: value is not string");return s.jsx(o,{errors:C(i.state.meta.errorMap),name:i.name,type:"text",value:i.state.value,onChange:r=>i.handleChange(r.target.value),children:t})}})}function pa({trait:e,children:t}){const{traitsForm:n}=Wt(),o=y.Root;return s.jsx(n.Field,{name:`${X}${e}`,children:i=>{if(typeof i.state.value!="boolean")throw new TypeError("TraitCheckbox: value is not boolean");return s.jsx(o,{checked:i.state.value,errors:C(i.state.meta.errorMap),name:i.name,type:"checkbox",onChange:r=>i.handleChange(r.target.checked),children:t})}})}function ha({traitsConfig:e,onError:t,onRegistrationSuccess:n}){const{setTraitsFormCompleted:o,setTraits:i,traits:r}=q(),{mutateAsync:a}=be(),{data:c}=j();return D.useForm({defaultValues:{traits:r??Object.fromEntries(Object.values(e).map(({trait:u,type:w})=>[u,w==="boolean"?!1:""]))},onSubmit:async({value:u,formApi:w})=>{if(!c)return;const f=await a({csrf_token:k(c),method:"profile",traits:u.traits??{}});if(f){if(Ve(f)){n?.();return}f.state===dt.ChooseMethod&&f.ui.messages?.some(({id:d})=>d===1040009)&&(i(u.traits),o(!0)),N(f,w,t)}}})}function _a({traitsConfig:e,oidcProvidersConfig:t,traitsForm:n,onError:o,onRegistrationSuccess:i}){const r=ha({traitsConfig:e,onError:o,onRegistrationSuccess:i}),a=I(r),{data:c}=j(),u=l.useMemo(()=>Object.fromEntries(Object.entries(e).map(([f,d])=>[f,d.type==="boolean"?({children:_})=>s.jsx(pa,{children:_,trait:d.trait}):({children:_})=>s.jsx(wa,{children:_,trait:d.trait})])),[e]),w=l.useMemo(()=>{if(!c)return{};const f=Be(c.ui.nodes),d={};return f.forEach(_=>{const F=_.attributes.value;if(!qe(t,F))return;const T=Ne.toUpperFirst(F);d[T]=({children:h})=>s.jsx(da,{provider:F,children:h})}),d},[c,t]);return s.jsx(fa,{traitsForm:r,children:s.jsx("form",{onSubmit:f=>{f.preventDefault(),r.handleSubmit()},children:s.jsx(n,{errors:a,isSubmitting:r.state.isSubmitting,isValidating:r.state.isValidating,oidcProviders:w,traitFields:{...u,Submit:E}})})})}function ga({traitsConfig:e,oidcProvidersConfig:t,traitsForm:n,chooseMethodForm:o,emailVerificationForm:i,initialFlowId:r,returnTo:a,onError:c,onRegistrationSuccess:u,onVerificationSuccess:w,onFlowRestart:f,onSessionAlreadyAvailable:d}){const{verificationFlowId:_}=J(),{registrationFlowId:F,setRegistrationFlowId:T,traitsFormCompleted:h}=q(),{error:v}=j(),{mutate:Q,error:te}=ia({returnTo:a});ne({initialFlowId:r,currentFlowId:F,error:v??void 0,onFlowRestart:f,createFlow:Q,setFlowId:T});const H=l.useMemo(()=>_e(v)||_e(te),[v,te]);l.useEffect(()=>{H&&d?.()},[H,d]);const R=l.useMemo(()=>H?"invalid":_?"emailVerification":h?"credentials":"traits",[h,_,H]);return s.jsxs(s.Fragment,{children:[R==="traits"&&s.jsx(_a,{oidcProvidersConfig:t,traitsConfig:e,traitsForm:n,onError:c,onRegistrationSuccess:u}),R==="credentials"&&s.jsx(ua,{chooseMethodForm:o,onError:c,onRegistrationSuccess:u}),R==="emailVerification"&&s.jsx(Fe,{emailVerificationForm:i,onError:c,onVerificationSuccess:w})]})}function Bt(e){return s.jsx(ye,{children:s.jsx(oa,{children:s.jsx(ga,{...e})})})}const ma=Object.freeze(Object.defineProperty({__proto__:null,RegistrationFlow:Bt},Symbol.toStringTag,{value:"Module"})),ya=z("settings_flow"),Ce=(e="no_id")=>K([ya,e]),qt=l.createContext(void 0);function Qe({children:e}){const[t,n]=l.useState(),[o,i]=l.useState(!1),r=l.useCallback(()=>{n(void 0)},[]);return s.jsx(qt.Provider,{value:{settingsFlowId:t,setSettingsFlowId:n,emailVerificationRequired:o,setEmailVerificationRequired:i,resetFlow:r},children:e})}function se(){const e=l.useContext(qt);if(e===void 0)throw new Error("useSettingsFlow must be used within a SettingsFlowProvider");return e}function Fa(){const{kratosClient:e}=x(),{setSettingsFlowId:t}=se(),n=m.useQueryClient();return m.useMutation({mutationFn:()=>e.createBrowserSettingsFlow({},async({init:{headers:o}})=>({headers:{...o,Accept:"application/json"}})),onSuccess(o){n.setQueryDefaults(Ce(o.id),{staleTime:1/0}),n.setQueryData(Ce(o.id),o),t(o.id)}})}function M(){const{kratosClient:e}=x(),{settingsFlowId:t}=se();return m.useQuery({queryKey:Ce(t),queryFn:async({signal:n})=>{if(!t)throw new Error("No settings flow ID provided",{cause:P.NoFlowId});try{return await e.getSettingsFlow({id:t},async({init:{headers:o}})=>({signal:n,headers:{...o,Accept:"application/json"}}))}catch(o){throw await re({error:o})}},enabled:!!t,staleTime:1/0})}function ee(){const{kratosClient:e}=x(),{settingsFlowId:t,resetFlow:n,setEmailVerificationRequired:o}=se(),i=m.useQueryClient();return m.useMutation({mutationFn:async r=>{if(!t)throw new Error("Settings flow ID is not set");try{const a=await e.updateSettingsFlow({flow:t,updateSettingsFlowBody:r},{headers:{Accept:"application/json","Content-Type":"application/json"}});return a&&"continue_with"in a&&(a.continue_with?.find(u=>u.action==="show_verification_ui")?o(!0):Pe(a.continue_with,{onRedirect:(u,w)=>{globalThis.location.href=u}})),a}catch(a){return await B({onRedirect:(c,u)=>{globalThis.location.href=c},onRestartFlow:n,onValidationError:c=>c})(a)}},onSuccess(r){r&&"id"in r&&i.setQueryData(Ce(r.id),r)}})}const $t=l.createContext(void 0);function va({children:e,newPasswordForm:t}){const n=l.useMemo(()=>({newPasswordForm:t}),[t]);return s.jsx($t.Provider,{value:n,children:e})}function Kt(){const e=l.useContext($t);if(e===void 0)throw new Error("useNewPasswordFormContext must be used within a NewPasswordFormProvider");return e}function Sa({children:e}){const{newPasswordForm:t}=Kt(),n=y.Root;return s.jsx(t.Field,{name:"password",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"password",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}var L=(e=>(e.Password="password",e.PasswordConfirmation="password_confirmation",e))(L||{});const zt=({value:e,fieldApi:t})=>{const n=t.form.getFieldMeta(L.PasswordConfirmation);if(n?.isDirty&&n?.isTouched)return Gt(e,t.form.getFieldValue(L.Password))},Gt=(e,t)=>{if(!e)return[ge(ie.FieldRequired)];if(e!==t)return[ge(ie.FieldMismatch)]};function ka({children:e}){const{newPasswordForm:t}=Kt(),n=y.Root;return s.jsx(t.Field,{listeners:{onChange:({fieldApi:o})=>{o.form.setFieldMeta(L.PasswordConfirmation,i=>({...i,errorMap:{...i.errorMap,onSubmit:void 0}}))}},name:"password_confirmation",validators:{onChangeListenTo:[L.Password],onChange:zt,onBlurListenTo:[L.PasswordConfirmation],onBlur:zt,onSubmit:({value:o,fieldApi:i})=>Gt(o,i.form.getFieldValue(L.Password))},children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"password",value:o.state.value,onBlur:o.handleBlur,onChange:i=>o.handleChange(i.target.value),children:e})})}function ba({onError:e,onChangePasswordSuccess:t}){const{mutateAsync:n}=ee(),{data:o}=M();return D.useForm({defaultValues:{[L.Password]:"",[L.PasswordConfirmation]:""},onSubmit:async({value:i,formApi:r})=>{if(!o)return;const a=await n({csrf_token:k(o),method:"password",password:i[L.Password]});if(a){if(a.state==="success"){t?.();return}N(a,r,e)}}})}function Ca({newPasswordForm:e,emailVerificationRequired:t,onError:n,onChangePasswordSuccess:o}){const{data:i}=M(),r=ba({onError:n,onChangePasswordSuccess:o}),a=I(r);return s.jsx(va,{newPasswordForm:r,children:s.jsx("form",{onSubmit:c=>{c.preventDefault(),r.handleSubmit()},children:s.jsx(e,{emailVerificationRequired:t,errors:a,isLoading:!i,isSubmitting:r.state.isSubmitting,isValidating:r.state.isValidating,Password:Sa,PasswordConfirmation:ka,Submit:E})})})}function xa({children:e,provider:t,type:n}){const{mutate:o}=ee(),{data:i}=M(),r=l.useCallback(()=>{i&&o({method:"oidc",[n]:t})},[i,o,n,t]),a=y.Root;return s.jsx(a,{oidcType:n,type:"button",onClick:r,children:e})}const Ta=(e,t)=>{const n=Fr(t,e);if(n){if(n.attributes.name==="link")return"link";if(n.attributes.name==="unlink")return"unlink";throw new Error(`Unknown OIDC provider type for ${e}: ${n.attributes.name}`)}};function Oa({oidcForm:e,oidcProvidersConfig:t}){const{data:n}=M(),o=l.useMemo(()=>{if(!n)return{};const i=Be(n.ui.nodes),r={};return i.forEach(a=>{const c=a.attributes.value,u=Ta(c,n.ui.nodes);if(!u||!qe(t,c))return;const w=Ne.toUpperFirst(c);r[w]=({children:f})=>s.jsx(xa,{provider:c,type:u,children:f})}),r},[n,t]);return s.jsx(e,{isLoading:!n,...o})}const Na=()=>{const{mutateAsync:e,isPending:t}=ee(),{data:n}=M(),o=l.useCallback(async c=>{if(!t){if(!n)throw new Error("Settings flow is not available");await e({method:"passkey",csrf_token:k(n),passkey_remove:c})}},[t,n,e]),i=l.useCallback(async c=>{n&&await e({method:"passkey",csrf_token:k(n),passkey_settings_register:c})},[n,e]),r=l.useMemo(()=>$(O(n?.ui.nodes,"passkey_create_data")),[n?.ui.nodes]),a=l.useCallback(async()=>{if(t||!r)return;const c=await mn(r.value);c&&await i(c)},[t,r,i]);return{isPending:t,removePasskey:o,addNewPasskey:a}};function Ea({passkeysForm:e}){const{data:t}=M(),{removePasskey:n,isPending:o,addNewPasskey:i}=Na(),r=t?gr(t.ui.nodes,"passkey_remove").filter(yr).map(({meta:a,attributes:c})=>({addedAt:a.label.context.added_at,addedAtUnix:a.label.context.added_at_unix,id:String(c.value),name:a.label.context.display_name,removePasskey:()=>n(c.value)})):[];return s.jsx(e,{addNewPasskey:i,existingPasskeys:r,isLoading:!t,isPending:o})}const Qt=l.createContext(void 0);function Ma({children:e,totpForm:t}){const n=l.useMemo(()=>({totpForm:t}),[t]);return s.jsx(Qt.Provider,{value:n,children:e})}function Ra(){const e=l.useContext(Qt);if(e===void 0)throw new Error("useTotpFormContext must be used within a TotpFormProvider");return e}function Da({children:e}){const{totpForm:t}=Ra(),n=y.Root;return s.jsx(t.Field,{name:"code",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"text",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}function Ia({children:e}){const{mutateAsync:t}=ee(),{data:n}=M(),o=l.useCallback(async()=>{n&&await t({method:"totp",csrf_token:k(n),totp_unlink:!0})},[n,t]),i=y.Root;return s.jsx(i,{type:"button",onClick:o,children:e})}var He=(e=>(e.Code="code",e))(He||{});function Ja({onError:e,onTotpSuccess:t}){const{mutateAsync:n}=ee(),{data:o}=M();return D.useForm({defaultValues:{[He.Code]:""},onSubmit:async({value:i,formApi:r})=>{if(!o)return;const a=await n({csrf_token:k(o),method:"totp",totp_code:i[He.Code]});if(a){if(a.state==="success"){t?.();return}N(a,r,e)}}})}function Ua({totpForm:e,emailVerificationRequired:t,onError:n,onTotpSuccess:o}){const i=Ja({onError:n,onTotpSuccess:o}),r=I(i),{data:a}=M(),c=l.useMemo(()=>{if(!a)return;const d=O(a.ui.nodes,"totp_qr");if(!(!d||d.attributes.node_type!==ut.Img))return d.attributes.src},[a]),u=l.useMemo(()=>{if(!a)return;const d=O(a.ui.nodes,"totp_secret_key");if(!d||d.attributes.node_type!==ut.Text)return;const{text:_}=d.attributes;return _.context&&"secret"in _.context&&typeof _.context.secret=="string"?_.context.secret:_.text},[a]),w=l.useMemo(()=>{if(a)return!!O(a.ui.nodes,"totp_unlink")},[a]),f=!a||w===void 0;return s.jsx(Ma,{totpForm:i,children:s.jsx("form",{onSubmit:d=>{d.preventDefault(),i.handleSubmit()},children:f?s.jsx(e,{isLoading:!0}):w?s.jsx(e,{isTotpLinked:!0,emailVerificationRequired:t,Unlink:Ia}):s.jsx(e,{Code:Da,emailVerificationRequired:t,errors:r,isSubmitting:i.state.isSubmitting,isValidating:i.state.isValidating,Submit:E,totpQrImageSrc:c,totpSecretKey:u})})})}const Ht=l.createContext(void 0);function Aa({children:e,traitsForm:t}){const n=l.useMemo(()=>({traitsForm:t}),[t]);return s.jsx(Ht.Provider,{value:n,children:e})}function Xt(){const e=l.useContext(Ht);if(e===void 0)throw new Error("useTraitsFormContext must be used within a TraitsFormProvider");return e}function La({trait:e,children:t}){const{traitsForm:n}=Xt(),o=y.Root;return s.jsx(n.Field,{name:`${X}${e}`,children:i=>{if(typeof i.state.value!="string")throw new TypeError("TraitInput: value is not string");return s.jsx(o,{errors:C(i.state.meta.errorMap),name:i.name,type:"text",value:i.state.value,onChange:r=>i.handleChange(r.target.value),children:t})}})}function Va({trait:e,children:t}){const{traitsForm:n}=Xt(),o=y.Root;return s.jsx(n.Field,{name:`${X}${e}`,children:i=>{if(typeof i.state.value!="boolean")throw new TypeError("TraitCheckbox: value is not boolean");return s.jsx(o,{checked:i.state.value,errors:C(i.state.meta.errorMap),name:i.name,type:"checkbox",onChange:r=>i.handleChange(r.target.checked),children:t})}})}function Pa({traitsConfig:e,onError:t,onChangeTraitsSuccess:n}){const{mutateAsync:o}=ee(),{data:i}=M();return D.useForm({defaultValues:{traits:i?.identity.traits??Object.fromEntries(Object.values(e).map(({trait:r,type:a})=>[r,a==="boolean"?!1:""]))},onSubmit:async({value:r,formApi:a})=>{if(!i)return;const c=await o({csrf_token:k(i),method:"profile",traits:r.traits??{}});if(c){if(c.state===Ao.Success){n?.();return}N(c,a,t)}}})}function Wa({traitsConfig:e,traitsForm:t,emailVerificationRequired:n,onError:o,onChangeTraitsSuccess:i}){const{data:r}=M(),a=Pa({traitsConfig:e,onError:o,onChangeTraitsSuccess:i}),c=I(a),u=l.useMemo(()=>Object.fromEntries(Object.entries(e).map(([w,f])=>[w,f.type==="boolean"?({children:d})=>s.jsx(Va,{children:d,trait:f.trait}):({children:d})=>s.jsx(La,{children:d,trait:f.trait})])),[e]);return s.jsx(Aa,{traitsForm:a,children:s.jsx("form",{onSubmit:w=>{w.preventDefault(),a.handleSubmit()},children:s.jsx(t,{emailVerificationRequired:n,errors:c,isLoading:!r,isSubmitting:a.state.isSubmitting,isValidating:a.state.isValidating,Submit:E,...u})})})}function Yt(e){return s.jsx(Qe,{children:s.jsx(Xe,{...e})})}function Xe({newPasswordForm:e,traitsForm:t,passkeysForm:n,totpForm:o,oidcForm:i,traitsConfig:r,oidcProvidersConfig:a,settingsForm:c,initialFlowId:u,onError:w,onChangePasswordSuccess:f,onChangeTraitsSuccess:d,onFlowRestart:_}){const{settingsFlowId:F,setSettingsFlowId:T,emailVerificationRequired:h}=se(),{mutate:v}=Fa(),{data:Q,error:te}=M();return ne({initialFlowId:u,currentFlowId:F,error:te,onFlowRestart:_,createFlow:v,setFlowId:T}),s.jsx(c,{emailVerificationRequired:h,isLoading:!Q,newPasswordForm:e&&s.jsx(Ca,{emailVerificationRequired:h,newPasswordForm:e,onChangePasswordSuccess:f,onError:w}),oidcForm:i&&s.jsx(Oa,{oidcForm:i,oidcProvidersConfig:a}),passkeysForm:n&&s.jsx(Ea,{passkeysForm:n}),totpForm:o&&s.jsx(Ua,{emailVerificationRequired:h,totpForm:o,onError:w,onTotpSuccess:d}),traitsForm:r&&t&&s.jsx(Wa,{emailVerificationRequired:h,traitsConfig:r,traitsForm:t,onChangeTraitsSuccess:d,onError:w})})}const Ba=Object.freeze(Object.defineProperty({__proto__:null,SettingsFlow:Yt,SettingsFlowProvider:Qe,SettingsFlowWrapper:Xe,useSettingsFlowContext:se},Symbol.toStringTag,{value:"Module"})),Zt=l.createContext(void 0);function qa({children:e,codeForm:t}){const n=l.useMemo(()=>({codeForm:t}),[t]);return s.jsx(Zt.Provider,{value:n,children:e})}function $a(){const e=l.useContext(Zt);if(e===void 0)throw new Error("useCodeFormContext must be used within a CodeFormProvider");return e}function Ka({children:e}){const{codeForm:t}=$a(),n=y.Root;return s.jsx(t.Field,{name:"code",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"text",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}const za=z("recovery_flow"),xe=(e="no_id")=>K([za,e]),jt=l.createContext(void 0);function Ga({children:e}){const[t,n]=l.useState(),o=l.useCallback(()=>{n(void 0)},[]);return s.jsx(jt.Provider,{value:{recoveryFlowId:t,setRecoveryFlowId:n,resetFlow:o},children:e})}function Te(){const e=l.useContext(jt);if(e===void 0)throw new Error("useRecoveryFlowContext must be used within a RecoveryFlow");return e}function Qa({returnTo:e}={}){const{kratosClient:t}=x(),{setRecoveryFlowId:n}=Te(),o=m.useQueryClient();return m.useMutation({mutationFn:()=>t.createBrowserRecoveryFlow({returnTo:e},async({init:{headers:i}})=>({headers:{...i,Accept:"application/json"}})),onSuccess(i){o.setQueryDefaults(xe(i.id),{staleTime:1/0}),o.setQueryData(xe(i.id),i),n(i.id)}})}function Ye(){const{kratosClient:e}=x(),{recoveryFlowId:t}=Te();return m.useQuery({queryKey:xe(t),queryFn:async({signal:n})=>{if(!t)throw new Error("No recovery flow ID provided",{cause:P.NoFlowId});try{return await e.getRecoveryFlow({id:t},async({init:{headers:o}})=>({signal:n,headers:{...o,Accept:"application/json"}}))}catch(o){throw await re({error:o})}},enabled:!!t,staleTime:1/0})}function en(){const{kratosClient:e}=x(),{resetFlow:t,recoveryFlowId:n}=Te(),o=m.useQueryClient();return m.useMutation({mutationFn:async i=>{if(!n)throw new Error("Recovery flow ID is not set");try{return await e.updateRecoveryFlow({flow:n,updateRecoveryFlowBody:i},{headers:{Accept:"application/json","Content-Type":"application/json"}})}catch(r){return await B({onRedirect:(a,c)=>{globalThis.location.href=a},onRestartFlow:t,onValidationError:a=>a})(r)}},onSuccess(i){i&&"id"in i&&o.setQueryData(xe(i.id),i)}})}var Ze=(e=>(e.Code="code",e))(Ze||{});function Ha({onError:e}){const{mutateAsync:t}=en(),{data:n}=Ye();return D.useForm({defaultValues:{[Ze.Code]:""},onSubmit:async({value:o,formApi:i})=>{if(!n)return;const r=await t({csrf_token:k(n),method:"code",code:o[Ze.Code]});r&&N(r,i,e)}})}function Xa({codeForm:e,onError:t}){const n=Ha({onError:t}),o=I(n);return s.jsx(qa,{codeForm:n,children:s.jsx("form",{onSubmit:i=>{i.preventDefault(),n.handleSubmit()},children:s.jsx(e,{Code:Ka,errors:o,isSubmitting:n.state.isSubmitting,isValidating:n.state.isValidating,Submit:E})})})}const tn=l.createContext(void 0);function Ya({children:e,emailForm:t}){const n=l.useMemo(()=>({emailForm:t}),[t]);return s.jsx(tn.Provider,{value:n,children:e})}function Za(){const e=l.useContext(tn);if(e===void 0)throw new Error("useEmailFormContext must be used within a EmailFormProvider");return e}function ja({children:e}){const{emailForm:t}=Za(),n=y.Root;return s.jsx(t.Field,{name:"email",children:o=>s.jsx(n,{errors:C(o.state.meta.errorMap),name:o.name,type:"text",value:o.state.value,onChange:i=>o.handleChange(i.target.value),children:e})})}var je=(e=>(e.Email="email",e))(je||{});function es({onError:e}){const{mutateAsync:t}=en(),{data:n}=Ye();return D.useForm({defaultValues:{[je.Email]:""},onSubmit:async({value:o,formApi:i})=>{if(!n)return;const r=await t({csrf_token:k(n),method:"code",email:o[je.Email]});r&&N(r,i,e)}})}function ts({emailForm:e,onError:t}){const n=es({onError:t}),o=I(n);return s.jsx(Ya,{emailForm:n,children:s.jsx("form",{onSubmit:i=>{i.preventDefault(),n.handleSubmit()},children:s.jsx(e,{Email:ja,errors:o,isSubmitting:n.state.isSubmitting,isValidating:n.state.isValidating,Submit:E})})})}function ns({emailForm:e,codeForm:t,newPasswordForm:n,initialFlowId:o,returnTo:i,onError:r,onRecoverySuccess:a,onFlowRestart:c}){const{recoveryFlowId:u,setRecoveryFlowId:w}=Te(),{mutate:f}=Qa({returnTo:i}),{data:d,error:_}=Ye(),F=l.useMemo(()=>d?.continue_with?.find(h=>h.action==="show_settings_ui")?.flow.id,[d]);ne({initialFlowId:o,currentFlowId:u,error:_,onFlowRestart:c,createFlow:f,setFlowId:w});const T=l.useMemo(()=>F?"newPassword":d?.state==="sent_email"?"code":"email",[d?.state,F]);return s.jsxs(s.Fragment,{children:[T==="email"&&s.jsx(ts,{emailForm:e,onError:r}),T==="code"&&s.jsx(Xa,{codeForm:t,onError:r}),T==="newPassword"&&F&&s.jsx(Xe,{initialFlowId:F,newPasswordForm:n,settingsForm:({newPasswordForm:h})=>h,onChangePasswordSuccess:a,onError:r})]})}function nn(e){return s.jsx(Qe,{children:s.jsx(Ga,{children:s.jsx(ns,{...e})})})}const os=Object.freeze(Object.defineProperty({__proto__:null,RecoveryFlow:nn},Symbol.toStringTag,{value:"Module"})),on=K([z("session_manager"),"session"]),rn=e=>({queryKey:on,queryFn:async()=>{try{return await e.toSession()}catch(t){if(t instanceof Y){if(t.response.status===401)return null;const n=await t.response.json();if(V(n))throw new Error("Kratos error occurred while fetching session",{cause:n})}throw new Error("Unexpected error while fetching session")}},staleTime:1/0,retry:!1});class an{queryClient;api;getSession=async()=>{try{return await this.queryClient.fetchQuery(rn(this.api))??void 0}catch{return}};getIdentity=async()=>(await this.getSession())?.identity;getUserId=async()=>(await this.getIdentity())?.id;isLoggedIn=async()=>(await this.getSession())?.active??!1;useSession=()=>{const{data:t,isLoading:n,error:o}=m.useQuery({...rn(this.api),retryOnMount:!1});return{session:t??void 0,isLoading:n,error:o}};useIdentity=()=>{const{session:t,...n}=this.useSession();return{identity:t?.identity,...n}};useUserId=()=>{const{identity:t,...n}=this.useIdentity();return{userId:t?.id,...n}};useIsLoggedIn=()=>{const{session:t,isLoading:n,error:o}=this.useSession();return{isLoggedIn:t?.active??(n?void 0:!1),isLoading:n,error:o}};useIsAal2Required=()=>{const t=this.useSession();return{isAal2Required:t.error?.cause?V(t.error.cause)&&rr(t.error.cause):void 0,isLoading:t.isLoading}};checkIfLoggedIn=async()=>await this.queryClient.refetchQueries({queryKey:on,exact:!0});constructor({queryClient:t,api:n}){this.api=n,this.queryClient=t}}const is={},rs=[];function as({queryClient:e,basePath:t,traits:n=is,SessionManager:o=an,oidcProviders:i=rs}){const r=new nr(new at({basePath:t,credentials:"include"})),a=new o({queryClient:e,api:r});return{flows:{useLogout:Jt,LoginFlow:f=>s.jsx(It,{...f,oidcProvidersConfig:i}),RecoveryFlow:nn,RegistrationFlow:f=>s.jsx(Bt,{...f,oidcProvidersConfig:i,traitsConfig:n}),SettingsFlow:f=>s.jsx(Yt,{...f,oidcProvidersConfig:i,traitsConfig:n}),VerificationFlow:Ct},providers:{KratosProviders:({children:f})=>s.jsx(vr,{api:r,children:s.jsx(un,{sessionManager:a,children:f})})},session:{sessionManager:a}}}b.BaseSessionManager=an,b.loginFlow=jr,b.logoutFlow=ea,b.mkKratos=as,b.recoveryFlow=os,b.registrationFlow=ma,b.settingsFlow=Ba,b.verificationFlow=Er,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -73,7 +73,7 @@ export type FlowsConfig<TTraitsConfig extends TraitsConfig, TOidcProvidersConfig
|
|
|
73
73
|
* />
|
|
74
74
|
* ```
|
|
75
75
|
*/
|
|
76
|
-
LoginFlow: ComponentType<LoginFlowProps<TOidcProvidersConfig>>;
|
|
76
|
+
LoginFlow: ComponentType<Omit<LoginFlowProps<TOidcProvidersConfig>, "oidcProvidersConfig">>;
|
|
77
77
|
/**
|
|
78
78
|
* Renders a multi-step password recovery flow with email verification and password reset.
|
|
79
79
|
*
|
|
@@ -132,7 +132,7 @@ export type FlowsConfig<TTraitsConfig extends TraitsConfig, TOidcProvidersConfig
|
|
|
132
132
|
* />
|
|
133
133
|
* ```
|
|
134
134
|
*/
|
|
135
|
-
RegistrationFlow: ComponentType<Omit<RegistrationFlowProps<TTraitsConfig, TOidcProvidersConfig>, "traitsConfig">>;
|
|
135
|
+
RegistrationFlow: ComponentType<Omit<RegistrationFlowProps<TTraitsConfig, TOidcProvidersConfig>, "oidcProvidersConfig" | "traitsConfig">>;
|
|
136
136
|
/**
|
|
137
137
|
* Renders a complete settings flow with user account management capabilities.
|
|
138
138
|
*
|
|
@@ -161,7 +161,7 @@ export type FlowsConfig<TTraitsConfig extends TraitsConfig, TOidcProvidersConfig
|
|
|
161
161
|
* />
|
|
162
162
|
* ```
|
|
163
163
|
*/
|
|
164
|
-
SettingsFlow: ComponentType<Omit<SettingsFlowProps<TTraitsConfig, TOidcProvidersConfig>, "traitsConfig">>;
|
|
164
|
+
SettingsFlow: ComponentType<Omit<SettingsFlowProps<TTraitsConfig, TOidcProvidersConfig>, "oidcProvidersConfig" | "traitsConfig">>;
|
|
165
165
|
/**
|
|
166
166
|
* Renders email verification flow with provider context and flow management.
|
|
167
167
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mkKratos.d.ts","sourceRoot":"","sources":["../../../src/lib/factories/mkKratos.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAG7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,iCAAiC,EAAE,MAAM,sCAAsC,CAAA;AACxF,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"mkKratos.d.ts","sourceRoot":"","sources":["../../../src/lib/factories/mkKratos.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAG7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,iCAAiC,EAAE,MAAM,sCAAsC,CAAA;AACxF,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAK5D,MAAM,MAAM,cAAc,CACxB,aAAa,SAAS,YAAY,EAClC,eAAe,SAAS,kBAAkB,CAAC,aAAa,CAAC,EACzD,oBAAoB,SAAS,mBAAmB,IAC9C;IACF,WAAW,EAAE,WAAW,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,aAAa,CAAA;IACtB,cAAc,CAAC,EAAE,KAAK,KAAK,EAAE,iCAAiC,KAAK,eAAe,CAAA;IAClF,aAAa,CAAC,EAAE,oBAAoB,CAAA;CACrC,CAAA;AAED,MAAM,MAAM,WAAW,CACrB,aAAa,SAAS,YAAY,EAClC,oBAAoB,SAAS,mBAAmB,GAAG,SAAS,EAAE,IAC5D;IACF;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,SAAS,EAAE,SAAS,CAAA;IAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,SAAS,EAAE,aAAa,CAAC,IAAI,CAAC,cAAc,CAAC,oBAAoB,CAAC,EAAE,qBAAqB,CAAC,CAAC,CAAA;IAE3F;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,YAAY,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAA;IAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,gBAAgB,EAAE,aAAa,CAC7B,IAAI,CAAC,qBAAqB,CAAC,aAAa,EAAE,oBAAoB,CAAC,EAAE,qBAAqB,GAAG,cAAc,CAAC,CACzG,CAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,YAAY,EAAE,aAAa,CACzB,IAAI,CAAC,iBAAiB,CAAC,aAAa,EAAE,oBAAoB,CAAC,EAAE,qBAAqB,GAAG,cAAc,CAAC,CACrG,CAAA;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,gBAAgB,EAAE,aAAa,CAAC,qBAAqB,CAAC,CAAA;CACvD,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,QAAQ,CACtB,aAAa,SAAS,YAAY,EAClC,eAAe,SAAS,kBAAkB,CAAC,aAAa,CAAC,EACzD,oBAAoB,SAAS,mBAAmB,GAAG,SAAS,EAAE,EAC9D,EACA,WAAW,EACX,QAAQ,EACR,MAAuC,EACvC,cAAwG,EACxG,aAA4D,GAC7D,EAAE,cAAc,CAAC,aAAa,EAAE,eAAe,EAAE,oBAAoB,CAAC;;;QAwBnE;;;;;;;;;;;;;;;;;;;;;;;;WAwBG;wCAC6B;YAAE,QAAQ,EAAE,SAAS,CAAA;SAAE;;;QAQvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA+BG;;;EASN;AAED,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAClE,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ComponentProps, ComponentType } from 'react';
|
|
2
|
+
/** Extracts the type of the `onError` callback from a flow component. */
|
|
3
|
+
export type GetFlowErrorHandler<TFlow extends ComponentType<any>> = NonNullable<ComponentProps<TFlow>["onError"]>;
|
|
4
|
+
/** Extracts the props type of a form component (by key) from a flow component. */
|
|
5
|
+
export type GetFormPropsFromFlow<TFlow extends ComponentType<any>, TFormKey extends keyof ComponentProps<TFlow>> = ComponentProps<Extract<ComponentProps<TFlow>[TFormKey], ComponentType<any>>>;
|
|
6
|
+
//# sourceMappingURL=formTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formTypes.d.ts","sourceRoot":"","sources":["../../../src/lib/flows/formTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAE1D,yEAAyE;AACzE,MAAM,MAAM,mBAAmB,CAAC,KAAK,SAAS,aAAa,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;AAEjH,kFAAkF;AAClF,MAAM,MAAM,oBAAoB,CAC9B,KAAK,SAAS,aAAa,CAAC,GAAG,CAAC,EAChC,QAAQ,SAAS,MAAM,cAAc,CAAC,KAAK,CAAC,IAC1C,cAAc,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA"}
|