@leancodepl/kratos 10.0.2 → 10.1.1
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 +46 -0
- package/README.md +134 -42
- package/dist/index.js +1260 -1249
- package/dist/index.umd.cjs +1 -1
- package/dist/lib/factories/mkKratos.d.ts +14 -9
- package/dist/lib/factories/mkKratos.d.ts.map +1 -1
- package/dist/lib/flows/login/chooseMethodForm/ChooseMethodFormWrapper.d.ts +13 -22
- package/dist/lib/flows/login/chooseMethodForm/ChooseMethodFormWrapper.d.ts.map +1 -1
- package/dist/lib/flows/login/loginFlow.d.ts +5 -3
- package/dist/lib/flows/login/loginFlow.d.ts.map +1 -1
- package/dist/lib/flows/registration/registrationFlow.d.ts +5 -4
- package/dist/lib/flows/registration/registrationFlow.d.ts.map +1 -1
- package/dist/lib/flows/registration/traitsForm/TraitsFormWrapper.d.ts +7 -14
- package/dist/lib/flows/registration/traitsForm/TraitsFormWrapper.d.ts.map +1 -1
- package/dist/lib/flows/settings/oidcForm/OidcFormWrapper.d.ts +7 -11
- package/dist/lib/flows/settings/oidcForm/OidcFormWrapper.d.ts.map +1 -1
- package/dist/lib/flows/settings/oidcForm/providers.d.ts +1 -2
- package/dist/lib/flows/settings/oidcForm/providers.d.ts.map +1 -1
- package/dist/lib/flows/settings/settingsFlow.d.ts +7 -5
- package/dist/lib/flows/settings/settingsFlow.d.ts.map +1 -1
- package/dist/lib/utils/flow.d.ts +12 -8
- package/dist/lib/utils/flow.d.ts.map +1 -1
- package/dist/lib/utils/index.d.ts +1 -0
- package/dist/lib/utils/index.d.ts.map +1 -1
- package/dist/lib/utils/oidcProviders.d.ts +18 -0
- package/dist/lib/utils/oidcProviders.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("@tanstack/react-form"),require("@radix-ui/react-slot"),require("@leancodepl/utils")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@tanstack/react-query","@tanstack/react-form","@radix-ui/react-slot","@leancodepl/utils"],s):(b=typeof globalThis<"u"?globalThis:b||self,s(b["@leancodepl/kratos"]={},b.jsxRuntime,b.react,b.reactQuery,b.reactForm,b.Slot,b.utils))})(this,(function(b,s,l,y,D,un,dn){"use strict";function fn(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 m=fn(un);var P=(e=>(e[e.NoFlowId=0]="NoFlowId",e[e.FlowRestartRequired=1]="FlowRestartRequired",e))(P||{});const et=l.createContext(void 0);function Ne(){const e=l.useContext(et);if(e===void 0)throw new Error("useKratosSessionContext must be used within a KratosSessionContextProvider");return e}function pn({children:e,sessionManager:t}){const n=l.useMemo(()=>({sessionManager:t}),[t]);return s.jsx(et.Provider,{value:n,children:e})}const ee=({initialFlowId:e,currentFlowId:t,error:n,onFlowRestart:o,createFlow:i,setFlowId:r,waitForSession:a})=>{const[c,u]=l.useState(!1),[d,w]=l.useState(e),{sessionManager:f}=Ne(),{isLoading:g}=f.useSession();d!==e&&(u(!1),w(e));const k=!!a&&g;l.useEffect(()=>{t||k||(e&&!c?(r(e),u(!0)):i())},[i,t,e,c,r,k]),l.useEffect(()=>{n&&n.cause===P.FlowRestartRequired&&(i(),o?.())},[i,n,o])},X="traits.";function tt(e){return"type"in e&&e.type==="public-key"&&"id"in e&&"rawId"in e&&"response"in e}function wn(e){return"attestationObject"in e&&"clientDataJSON"in e}function hn(e){return"authenticatorData"in e&&"clientDataJSON"in e&&"signature"in e}function ce(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 nt(e){if(!e||!tt(e))return;const{response:t,id:n,rawId:o}=e;if(wn(t))return JSON.stringify({id:n,rawId:W(o),type:e.type,response:{attestationObject:W(t.attestationObject),clientDataJSON:W(t.clientDataJSON)}})}async function ot({credentialOptions:e,signal:t,userName:n,userDisplayName:o}){return await navigator.credentials.create({signal:t,publicKey:{challenge:ce(e.publicKey.challenge),timeout:e.publicKey.timeout,rp:{id:e.publicKey.rp.id,name:e.publicKey.rp.name},user:{id:ce(e.publicKey.user.id),name:n,displayName:o},pubKeyCredParams:e.publicKey.pubKeyCredParams}})}function it(e){if(!e||!tt(e))return;const{response:t,id:n,rawId:o}=e;if(!hn(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 gn({challengeOptions:e,signal:t}){return await navigator.credentials.get({signal:t,publicKey:{challenge:ce(e.publicKey.challenge),timeout:e.publicKey.timeout,rpId:e.publicKey.rpId,userVerification:e.publicKey.userVerification}})}function _n(){return!!globalThis.PublicKeyCredential}async function yn(e,t){const n=JSON.parse(e);if(_n()&&globalThis.PublicKeyCredential.isConditionalMediationAvailable&&await globalThis.PublicKeyCredential.isConditionalMediationAvailable())try{const o=await navigator.credentials.get({mediation:"conditional",signal:t,publicKey:{challenge:ce(n.publicKey.challenge),timeout:n.publicKey.timeout,rpId:n.publicKey.rpId,userVerification:n.publicKey.userVerification}});return it(o)}catch{return}}async function mn(e,t){const n=JSON.parse(e);try{return it(await gn({challengeOptions:n,signal:t}))}catch{return}}async function Fn(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 nt(await ot({credentialOptions:o,signal:t,userName:a,userDisplayName:a}))}catch{return}}async function vn(e,t){const n=JSON.parse(e);try{return nt(await ot({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,Sn="https://playground.projects.oryapis.com".replace(/\/+$/,"");class rt{constructor(t={}){this.configuration=t}set config(t){this.configuration=t}get basePath(){return this.configuration.basePath!=null?this.configuration.basePath:Sn}get fetchApi(){return this.configuration.fetchApi}get middleware(){return this.configuration.middleware||[]}get queryParamsStringify(){return this.configuration.queryParamsStringify||at}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 kn=new rt;class Ee{constructor(t=kn){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?Ee.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(w=>i[w]===void 0?delete i[w]:{});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;Cn(c.body)||c.body instanceof URLSearchParams||bn(c.body)?u=c.body:this.isJsonMime(i["Content-Type"])?u=JSON.stringify(c.body):u=c.body;const d={...c,body:u};return{url:o,init:d}}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 Me(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 bn(e){return typeof Blob<"u"&&e instanceof Blob}function Cn(e){return typeof FormData<"u"&&e instanceof FormData}class Y extends Error{constructor(t,n){super(n),this.response=t}name="ResponseError"}class Me extends Error{constructor(t,n){super(n),this.cause=t}name="FetchError"}class F extends Error{constructor(t,n){super(n),this.field=t}name="RequiredError"}function at(e,t=""){return Object.keys(e).map(n=>st(n,e[n],t)).filter(n=>n.length>0).join("&")}function st(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 st(e,i,n)}return t instanceof Date?`${encodeURIComponent(o)}=${encodeURIComponent(t.toISOString())}`:t instanceof Object?at(t,o):`${encodeURIComponent(o)}=${encodeURIComponent(String(t))}`}function xn(e,t){return Object.keys(e).reduce((n,o)=>({...n,[o]:t(e[o])}),{})}class _{constructor(t,n=o=>o){this.raw=t,this.transformer=n}async value(){return this.transformer(await this.raw.json())}}class Re{constructor(t){this.raw=t}async value(){}}class Tn{constructor(t){this.raw=t}async value(){return await this.raw.text()}}function De(e){return On(e)}function On(e,t){return e}function Nn(e){return En(e)}function En(e,t){return e==null?e:{id:e.id,url:e.url==null?void 0:e.url}}function Mn(e,t){return e==null?e:{action:e.action,flow:Nn(e.flow)}}function Rn(e,t){return e==null?e:{action:e.action,redirect_browser_to:e.redirect_browser_to}}function Dn(e,t){return e==null?e:{action:e.action,ory_session_token:e.ory_session_token}}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}}function An(e,t){return e==null?e:{action:e.action,flow:In(e.flow)}}function Un(e){return Ln(e)}function Ln(e,t){return e==null?e:{id:e.id,url:e.url==null?void 0:e.url,verifiable_address:e.verifiable_address}}function Vn(e,t){return e==null?e:{action:e.action,flow:Un(e.flow)}}function le(e){return Pn(e)}function Pn(e,t){if(e==null)return e;switch(e.action){case"redirect_browser_to":return Object.assign({},Rn(e),{action:"redirect_browser_to"});case"set_ory_session_token":return Object.assign({},Dn(e),{action:"set_ory_session_token"});case"show_recovery_ui":return Object.assign({},Mn(e),{action:"show_recovery_ui"});case"show_settings_ui":return Object.assign({},An(e),{action:"show_settings_ui"});case"show_verification_ui":return Object.assign({},Vn(e),{action:"show_verification_ui"});default:throw new Error(`No variant of ContinueWith exists with 'action=${e.action}'`)}}function Wn(e){return Bn(e)}function Bn(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 qn(e){return $n(e)}function $n(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(Wn)}}function Kn(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),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 Gn(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,updated_at:e.updated_at==null?void 0:new Date(e.updated_at),value:e.value,via:e.via}}function Hn(e){return Xn(e)}function Xn(e,t){return e==null?e:{count:e.count==null?void 0:e.count}}function Yn(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),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 jn(e){return eo(e)}function eo(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 Ie(e){return to(e)}function to(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:xn(e.credentials,jn),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(Gn),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(Kn)}}function no(e){return oo(e)}function oo(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 io(e){return ro(e)}function ro(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 ct(e){return ao(e)}function ao(e,t){return e==null?e:{challenge:e.challenge,client:io(e.client),oidc_context:e.oidc_context==null?void 0:no(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 so={Error:"error"};function co(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 lo(e)}function lo(e,t){return e==null?e:{context:e.context==null?void 0:e.context,id:e.id,text:e.text,type:e.type}}function uo(e){return fo(e)}function fo(e,t){return e==null?e:{label:e.label==null?void 0:Z(e.label)}}function po(e,t){return e==null?e:{href:e.href,id:e.id,node_type:e.node_type,title:Z(e.title)}}function wo(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 lt={Text:"text",Img:"img"};function ho(e,t){return e==null?e:{height:e.height,id:e.id,node_type:e.node_type,src:e.src,width:e.width}}function go(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 _o={Input:"input"};function yo(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 mo(e,t){return e==null?e:{id:e.id,node_type:e.node_type,text:Z(e.text)}}function Fo(e){return vo(e)}function vo(e,t){if(e==null)return e;switch(e.node_type){case"a":return Object.assign({},po(e),{node_type:"a"});case"div":return Object.assign({},wo(e),{node_type:"div"});case"img":return Object.assign({},ho(e),{node_type:"img"});case"input":return Object.assign({},go(e),{node_type:"input"});case"script":return Object.assign({},yo(e),{node_type:"script"});case"text":return Object.assign({},mo(e),{node_type:"text"});default:throw new Error(`No variant of UiNodeAttributes exists with 'node_type=${e.node_type}'`)}}const So={Passkey:"passkey"},ko={Input:"input"};function bo(e){return Co(e)}function Co(e,t){return e==null?e:{attributes:Fo(e.attributes),group:e.group,messages:e.messages.map(Z),meta:uo(e.meta),type:e.type}}function te(e){return xo(e)}function xo(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(bo)}}function Je(e){return To(e)}function To(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:ct(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:De(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:te(e.ui),updated_at:e.updated_at==null?void 0:new Date(e.updated_at)}}function Oo(e){return No(e)}function No(e,t){return e==null?e:{logout_token:e.logout_token,logout_url:e.logout_url}}function Eo(e){return Mo(e,!1)}function Mo(e,t=!1){return e==null?e:{session_token:e.session_token}}function ue(e){return Ro(e)}function Ro(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(le),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:te(e.ui)}}function Ae(e){return Do(e)}function Do(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:ct(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:te(e.ui)}}const ut={ChooseMethod:"choose_method"};function Io(e){return Jo(e)}function Jo(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 Ao(e){return Uo(e)}function Uo(e,t){return e==null?e:{aal:e.aal==null?void 0:De(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 de(e){return Lo(e)}function Lo(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(Ao),authenticator_assurance_level:e.authenticator_assurance_level==null?void 0:De(e.authenticator_assurance_level),devices:e.devices==null?void 0:e.devices.map(Io),expires_at:e.expires_at==null?void 0:new Date(e.expires_at),id:e.id,identity:e.identity==null?void 0:Ie(e.identity),issued_at:e.issued_at==null?void 0:new Date(e.issued_at),tokenized:e.tokenized==null?void 0:e.tokenized}}function fe(e){return Vo(e)}function Vo(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(le),expires_at:new Date(e.expires_at),id:e.id,identity:Ie(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:te(e.ui)}}const Po={Success:"success"};function pe(e){return!(!("session"in e)||e.session===void 0)}function Ue(e){return Wo(e)}function Wo(e,t){return e==null?e:{continue_with:e.continue_with==null?void 0:e.continue_with.map(le),session:de(e.session),session_token:e.session_token==null?void 0:e.session_token}}function Le(e){return!(!("identity"in e)||e.identity===void 0)}function Bo(e){return qo(e)}function qo(e,t){return e==null?e:{continue_with:e.continue_with==null?void 0:e.continue_with.map(le),identity:Ie(e.identity),session:e.session==null?void 0:de(e.session),session_token:e.session_token==null?void 0:e.session_token}}function $o(e){return Ko(e,!1)}function Ko(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,nonce:e.nonce,token:e.token,transient_payload:e.transient_payload}}function zo(e){return Go(e,!1)}function Go(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 Qo(e){return Ho(e,!1)}function Ho(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,identifier:e.identifier,method:e.method,transient_payload:e.transient_payload}}function Xo(e){return Yo(e,!1)}function Yo(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,lookup_secret:e.lookup_secret,method:e.method}}function Zo(e){return jo(e,!1)}function jo(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 ei(e){return ti(e,!1)}function ti(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,passkey_login:e.passkey_login}}function ni(e){return oi(e,!1)}function oi(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 ii(e){return ri(e,!1)}function ri(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,provider:e.provider,transient_payload:e.transient_payload}}function ai(e){return si(e,!1)}function si(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 ci(e){return li(e,!1)}function li(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 ui(e){return di(e,!1)}function di(e,t=!1){if(e==null)return e;switch(e.method){case"code":return Object.assign({},zo(e),{method:"code"});case"identifier_first":return Object.assign({},Qo(e),{method:"identifier_first"});case"lookup_secret":return Object.assign({},Xo(e),{method:"lookup_secret"});case"oidc":return Object.assign({},Zo(e),{method:"oidc"});case"passkey":return Object.assign({},ei(e),{method:"passkey"});case"password":return Object.assign({},ni(e),{method:"password"});case"saml":return Object.assign({},ii(e),{method:"saml"});case"totp":return Object.assign({},ai(e),{method:"totp"});case"webauthn":return Object.assign({},ci(e),{method:"webauthn"});default:throw new Error(`No variant of UpdateLoginFlowBody exists with 'method=${e.method}'`)}}function fi(e){return pi(e,!1)}function pi(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 wi(e){return hi(e,!1)}function hi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,email:e.email,method:e.method,transient_payload:e.transient_payload}}function gi(e){return _i(e,!1)}function _i(e,t=!1){if(e==null)return e;switch(e.method){case"code":return Object.assign({},fi(e),{method:"code"});case"link":return Object.assign({},wi(e),{method:"link"});default:throw new Error(`No variant of UpdateRecoveryFlowBody exists with 'method=${e.method}'`)}}function yi(e){return mi(e,!1)}function mi(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 Fi(e){return vi(e,!1)}function vi(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 Si(e){return ki(e,!1)}function ki(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 bi(e){return Ci(e,!1)}function Ci(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 xi(e){return Ti(e,!1)}function Ti(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 Oi(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,traits:e.traits,transient_payload:e.transient_payload}}function Ei(e){return Mi(e,!1)}function Mi(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 Ri(e){return Di(e,!1)}function Di(e,t=!1){if(e==null)return e;switch(e.method){case"code":return Object.assign({},yi(e),{method:"code"});case"oidc":return Object.assign({},Fi(e),{method:"oidc"});case"passkey":return Object.assign({},Si(e),{method:"passkey"});case"password":return Object.assign({},bi(e),{method:"password"});case"profile":return Object.assign({},xi(e),{method:"profile"});case"saml":return Object.assign({},Oi(e),{method:"saml"});case"webauthn":return Object.assign({},Ei(e),{method:"webauthn"});default:throw new Error(`No variant of UpdateRegistrationFlowBody exists with 'method=${e.method}'`)}}function Ii(e){return Ji(e,!1)}function Ji(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 Ai(e){return Ui(e,!1)}function Ui(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 Li(e){return Vi(e,!1)}function Vi(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 Pi(e){return Wi(e,!1)}function Wi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,password:e.password,transient_payload:e.transient_payload}}function Bi(e){return qi(e,!1)}function qi(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,method:e.method,traits:e.traits,transient_payload:e.transient_payload}}function $i(e){return Ki(e,!1)}function Ki(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 zi(e){return Gi(e,!1)}function Gi(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 Qi(e){return Hi(e,!1)}function Hi(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 Xi(e){return Yi(e,!1)}function Yi(e,t=!1){if(e==null)return e;switch(e.method){case"lookup_secret":return Object.assign({},Ii(e),{method:"lookup_secret"});case"oidc":return Object.assign({},Ai(e),{method:"oidc"});case"passkey":return Object.assign({},Li(e),{method:"passkey"});case"password":return Object.assign({},Pi(e),{method:"password"});case"profile":return Object.assign({},Bi(e),{method:"profile"});case"saml":return Object.assign({},$i(e),{method:"saml"});case"totp":return Object.assign({},zi(e),{method:"totp"});case"webauthn":return Object.assign({},Qi(e),{method:"webauthn"});default:throw new Error(`No variant of UpdateSettingsFlowBody exists with 'method=${e.method}'`)}}function Zi(e){return ji(e,!1)}function ji(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 er(e){return tr(e,!1)}function tr(e,t=!1){return e==null?e:{csrf_token:e.csrf_token,email:e.email,method:e.method,transient_payload:e.transient_payload}}function nr(e){return or(e,!1)}function or(e,t=!1){if(e==null)return e;switch(e.method){case"code":return Object.assign({},Zi(e),{method:"code"});case"link":return Object.assign({},er(e),{method:"link"});default:throw new Error(`No variant of UpdateVerificationFlowBody exists with 'method=${e.method}'`)}}function we(e){return ir(e)}function ir(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:te(e.ui)}}const dt={ChooseMethod:"choose_method",SentEmail:"sent_email",PassedChallenge:"passed_challenge",UnknownDefaultOpenApi:"11184809"};class rr extends Ee{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 _(r,a=>Je(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 _(r,a=>Oo(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 _(r,a=>ue(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 _(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 _(r,a=>fe(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 _(r,a=>we(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 _(i,r=>qn(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 _(r,a=>Je(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 _(i,r=>ue(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 _(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 _(r,a=>fe(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 _(r,a=>we(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 _(r,a=>Hn(a))}async disableMyOtherSessions(t={},n){return await(await this.disableMyOtherSessionsRaw(t,n)).value()}async disableMySessionRaw(t,n){if(t.id==null)throw new F("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 Re(r)}async disableMySession(t,n){await this.disableMySessionRaw(t,n)}async exchangeSessionTokenRaw(t,n){if(t.initCode==null)throw new F("initCode",'Required parameter "initCode" was null or undefined when calling exchangeSessionToken().');if(t.returnToCode==null)throw new F("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 _(r,a=>Ue(a))}async exchangeSessionToken(t,n){return await(await this.exchangeSessionTokenRaw(t,n)).value()}async getFlowErrorRaw(t,n){if(t.id==null)throw new F("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 _(r,a=>Yn(a))}async getFlowError(t,n){return await(await this.getFlowErrorRaw(t,n)).value()}async getLoginFlowRaw(t,n){if(t.id==null)throw new F("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 _(r,a=>Je(a))}async getLoginFlow(t,n){return await(await this.getLoginFlowRaw(t,n)).value()}async getRecoveryFlowRaw(t,n){if(t.id==null)throw new F("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 _(r,a=>ue(a))}async getRecoveryFlow(t,n){return await(await this.getRecoveryFlowRaw(t,n)).value()}async getRegistrationFlowRaw(t,n){if(t.id==null)throw new F("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 _(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 F("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 _(r,a=>fe(a))}async getSettingsFlow(t,n){return await(await this.getSettingsFlowRaw(t,n)).value()}async getVerificationFlowRaw(t,n){if(t.id==null)throw new F("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 _(r,a=>we(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 _(i):new Tn(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 _(r,a=>a.map(de))}async listMySessions(t={},n){return await(await this.listMySessionsRaw(t,n)).value()}async performNativeLogoutRaw(t,n){if(t.performNativeLogoutBody==null)throw new F("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:Eo(t.performNativeLogoutBody)},n);return new Re(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 _(r,a=>de(a))}async toSession(t={},n){return await(await this.toSessionRaw(t,n)).value()}async updateFedcmFlowRaw(t,n){if(t.updateFedcmFlowBody==null)throw new F("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:$o(t.updateFedcmFlowBody)},n);return new _(r,a=>Ue(a))}async updateFedcmFlow(t,n){return await(await this.updateFedcmFlowRaw(t,n)).value()}async updateLoginFlowRaw(t,n){if(t.flow==null)throw new F("flow",'Required parameter "flow" was null or undefined when calling updateLoginFlow().');if(t.updateLoginFlowBody==null)throw new F("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:ui(t.updateLoginFlowBody)},n);return new _(r,a=>Ue(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 Re(r)}async updateLogoutFlow(t={},n){await this.updateLogoutFlowRaw(t,n)}async updateRecoveryFlowRaw(t,n){if(t.flow==null)throw new F("flow",'Required parameter "flow" was null or undefined when calling updateRecoveryFlow().');if(t.updateRecoveryFlowBody==null)throw new F("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:gi(t.updateRecoveryFlowBody)},n);return new _(r,a=>ue(a))}async updateRecoveryFlow(t,n){return await(await this.updateRecoveryFlowRaw(t,n)).value()}async updateRegistrationFlowRaw(t,n){if(t.flow==null)throw new F("flow",'Required parameter "flow" was null or undefined when calling updateRegistrationFlow().');if(t.updateRegistrationFlowBody==null)throw new F("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:Ri(t.updateRegistrationFlowBody)},n);return new _(r,a=>Bo(a))}async updateRegistrationFlow(t,n){return await(await this.updateRegistrationFlowRaw(t,n)).value()}async updateSettingsFlowRaw(t,n){if(t.flow==null)throw new F("flow",'Required parameter "flow" was null or undefined when calling updateSettingsFlow().');if(t.updateSettingsFlowBody==null)throw new F("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:Xi(t.updateSettingsFlowBody)},n);return new _(r,a=>fe(a))}async updateSettingsFlow(t,n){return await(await this.updateSettingsFlowRaw(t,n)).value()}async updateVerificationFlowRaw(t,n){if(t.flow==null)throw new F("flow",'Required parameter "flow" was null or undefined when calling updateVerificationFlow().');if(t.updateVerificationFlowBody==null)throw new F("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:nr(t.updateVerificationFlowBody)},n);return new _(r,a=>we(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 ar(e){return V(e)&&e.error.id==="session_refresh_required"}function ft(e){return V(e)&&e.error.id==="self_service_flow_expired"}function sr(e){return V(e)&&V(e)&&e.error.id==="browser_location_change_required"}function he(e){return V(e)&&e.error.id==="session_already_available"}function cr(e){return V(e)&&e.error.id==="session_aal2_required"}function lr(e){return V(e)&&e.error.id==="security_csrf_violation"}const ur=e=>e instanceof Y?!0:typeof e=="object"&&!!e&&"name"in e&&e.name==="ResponseError",B=e=>async t=>{if(ur(t))switch(t.response.status){case 404:e.onRestartFlow();return;case 410:{const n=await pt(t.response);if(ft(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(sr(n)&&n.redirect_browser_to){e.onRedirect(n.redirect_browser_to,!0);return}else if(ft(n)){e.onRestartFlow(n.use_flow_id);return}else if(ar(n)){e.onRedirect(n.redirect_browser_to,!0);return}else if(lr(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 Me)throw new Me(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 wt=["show_settings_ui","show_recovery_ui","show_verification_ui","redirect_browser_to","set_ory_session_token"];function Ve(e,{onRedirect:t}){if(!e||e.length===0)return!1;const n=dr(e);if(!n)return!1;const o=(i,r,a)=>a?(t(a,!0),!0):(t("/"+r+"?flow="+i,!1),!0);if(fr(n))throw new Error("Ory Elements does not support API flows yet.");if(pr(n)&&n.redirect_browser_to)return t(n.redirect_browser_to,!0),!0;if(gr(n))return o(n.flow.id,"verification",n.flow.url);if(wr(n))return o(n.flow.id,"recovery",n.flow.url);if(hr(n))return o(n.flow.id,"settings",n.flow.url);throw new Error("Unknown action: "+JSON.stringify(n))}function dr(e){return!e||e.length===0?void 0:e.toSorted((n,o)=>wt.indexOf(n.action)-wt.indexOf(o.action))[0]}function fr(e){return e.action==="set_ory_session_token"}function pr(e){return e.action==="redirect_browser_to"}function wr(e){return e.action==="show_recovery_ui"}function hr(e){return e.action==="show_settings_ui"}function gr(e){return e.action==="show_verification_ui"}function Pe(e){return e.node_type==="input"}function ht({attributes:e}){return Pe(e)?e.name:e.id}const gt=e=>!(typeof e!="object"||e===null||!co(e)||e.type!==so.Error),_r=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)),_t=e=>e?.filter(gt).map(mr)??[],C=({onSubmit:e,onChange:t,onBlur:n}={})=>{const o=[...Array.isArray(e)?e:[],...Array.isArray(t)?t:[],...Array.isArray(n)?n:[]].filter(_r);return[...new Map(o.map(i=>[i.id,i])).values()]};var ne=(e=>(e.FieldMismatch="FieldMismatch",e.FieldRequired="FieldRequired",e))(ne||{});const ge=e=>({id:`AdditionalValidationError_${e}`}),yr=e=>{const t=(h,S)=>({id:`${h}_${S}`,originalError:e}),n=(h,S,$)=>({id:`${h}_${S}_WithContext`,context:$,originalError:e});return{createGenericError:h=>t("Error",h),createGenericErrorWithContext:(h,S)=>n("Error",h,S),createLoginFlowError:h=>t("LoginFlowError",h),createLoginFlowErrorWithContext:(h,S)=>n("LoginFlowError",h,S),createRegisterFlowError:h=>t("RegisterFlowError",h),createRegisterFlowErrorWithContext:(h,S)=>n("RegisterFlowError",h,S),createSettingsFlowError:h=>t("SettingsFlowError",h),createSettingsFlowErrorWithContext:(h,S)=>n("SettingsFlowError",h,S),createRecoveryFlowError:h=>t("RecoveryFlowError",h),createRecoveryFlowErrorWithContext:(h,S)=>n("RecoveryFlowError",h,S),createVerificationFlowError:h=>t("VerificationFlowError",h),createVerificationFlowErrorWithContext:(h,S)=>n("VerificationFlowError",h,S)}},mr=e=>{const{createGenericError:t,createGenericErrorWithContext:n,createLoginFlowError:o,createLoginFlowErrorWithContext:i,createRegisterFlowError:r,createRegisterFlowErrorWithContext:a,createSettingsFlowError:c,createSettingsFlowErrorWithContext:u,createRecoveryFlowError:d,createRecoveryFlowErrorWithContext:w,createVerificationFlowError:f,createVerificationFlowErrorWithContext:g}=yr(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(k=>typeof k=="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(k=>typeof k=="string")&&p(e.context,"available_oidc_providers","object")&&Array.isArray(e.context.available_oidc_providers)&&e.context.available_oidc_providers.every(k=>typeof k=="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 d("RecoveryRequestAlreadyCompletedSuccessfully");case 4060002:return d("RecoveryFlowFailureState");case 4060004:return d("InvalidTokenOrAlreadyUsed");case 4060005:return p(e.context,"expired_at","string")&&p(e.context,"expired_at_unix","number")?w("RecoveryFlowExpired",{expired_at:e.context.expired_at,expired_at_unix:e.context.expired_at_unix}):d("RecoveryFlowExpired");case 4060006:return d("InvalidRecoveryCodeOrAlreadyUsed");case 4070001:return f("InvalidVerificationTokenOrAlreadyUsed");case 4070002:return f("VerificationRequestAlreadyCompletedSuccessfully");case 4070003:return f("VerificationFlowFailureState");case 4070005:return p(e.context,"expired_at","string")&&p(e.context,"expired_at_unix","number")?g("VerificationFlowExpired",{expired_at:e.context.expired_at,expired_at_unix:e.context.expired_at_unix}):f("VerificationFlowExpired");case 4070006:return f("InvalidVerificationCodeOrAlreadyUsed");default:return p(e.context,"reason","string")?n("Generic",{reason:e.context.reason}):t("Generic")}};function T(e,t){return e?.find(n=>ht(n)===t)}function Fr(e,t){return e?.filter(n=>ht(n)===t)??[]}function K(e){if(e&&Pe(e.attributes))return e.attributes}function vr(e){if(e&&Pe(e.attributes))return e.messages}function v(e){const t=K(T(e.ui.nodes,"csrf_token"));if(!t||typeof t.value!="string")throw new Error("CSRF token not found");return t.value}const Sr=e=>{if(e.group!==So.Passkey||e.type!==ko.Input||e.attributes.node_type!==_o.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=["apple","facebook","google"],kr=e=>e.group==="oidc"&&e.attributes.node_type==="input"&&yt.includes(e.attributes.value),_e=(e,t)=>e?.find(n=>kr(n)&&n.attributes.value===t)??void 0,oe=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=_t(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=_t(vr(T(e.ui.nodes,r)));a.length>0&&(t.setFieldMeta(r,c=>({...c,errorMap:{onSubmit:a}})),n?.({target:r,errors:a}))}},We="leancode_kratos",z=e=>[We,...e],G=e=>`${We}_${e}`;function I(e){return l.useMemo(()=>C(e.state.errorMap),[e.state.errorMap])}const mt=l.createContext(void 0);function x(){const e=l.useContext(mt);if(e===void 0)throw new Error("useKratosClientContext must be used within a KratosClientContextProvider");return e}function br({children:e,api:t}){const n=l.useMemo(()=>({kratosClient:t}),[t]);return s.jsx(mt.Provider,{value:n,children:e})}function E({children:e}){const t=m.Root;return s.jsx(t,{type:"submit",children:e})}const Ft=l.createContext(void 0);function Cr({children:e,emailVerificationForm:t}){const n=l.useMemo(()=>({emailVerificationForm:t}),[t]);return s.jsx(Ft.Provider,{value:n,children:e})}function xr(){const e=l.useContext(Ft);if(e===void 0)throw new Error("useEmailVerificationFormContext must be used within a EmailVerificationFormProvider");return e}const Tr=G("verification_flow"),ye=(e="no_id")=>z([Tr,e]),vt=l.createContext(void 0);function me({children:e}){const[t,n]=l.useState(),[o,i]=l.useState(),r=l.useCallback(()=>{n(void 0),i(void 0)},[]);return s.jsx(vt.Provider,{value:{verificationFlowId:t,setVerificationFlowId:n,verifiableAddress:o,setVerifiableAddress:i,resetFlow:r},children:e})}function J(){const e=l.useContext(vt);if(e===void 0)throw new Error("useVerificationFlow must be used within a VerificationFlowProvider");return e}function Or({returnTo:e}={}){const{kratosClient:t}=x(),{setVerificationFlowId:n}=J(),o=y.useQueryClient();return y.useMutation({mutationFn:()=>t.createBrowserVerificationFlow({returnTo:e},async({init:{headers:i}})=>({headers:{...i,Accept:"application/json"}})),onSuccess(i){o.setQueryDefaults(ye(i.id),{staleTime:1/0}),o.setQueryData(ye(i.id),i),n(i.id)}})}function Be(){const{kratosClient:e}=x(),{verificationFlowId:t}=J();return y.useQuery({queryKey:ye(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 oe({error:o})}},enabled:!!t,staleTime:1/0})}function St(){const{kratosClient:e}=x(),{verificationFlowId:t,resetFlow:n}=J(),o=y.useQueryClient();return y.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===dt.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(ye(i.id),i)}})}function Nr({children:e}){const{verifiableAddress:t}=J(),{mutate:n}=St(),{data:o}=Be(),i=l.useCallback(()=>{!o||!t||n({method:"code",csrf_token:v(o),email:t,code:""})},[o,t,n]),r=m.Root;return s.jsx(r,{type:"button",onClick:i,children:e})}function Er({children:e}){const{emailVerificationForm:t}=xr(),n=m.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 kt=(e=>(e.Code="code",e))(kt||{});function Mr({onError:e,onVerificationSuccess:t}){const{verifiableAddress:n}=J(),{mutateAsync:o}=St(),{data:i}=Be();return D.useForm({defaultValues:{[kt.Code]:""},onSubmit:async({value:r,formApi:a})=>{if(!i||!n)return;const c=await o({csrf_token:v(i),method:"code",code:r.code,email:n});if(c){if(c.state==dt.PassedChallenge){t?.();return}N(c,a,e)}}})}function Rr({emailVerificationForm:e,onError:t,onVerificationSuccess:n}){const o=Mr({onError:t,onVerificationSuccess:n}),i=I(o);return s.jsx(Cr,{emailVerificationForm:o,children:s.jsx("form",{onSubmit:r=>{r.preventDefault(),o.handleSubmit()},children:s.jsx(e,{Code:Er,errors:i,isSubmitting:o.state.isSubmitting,isValidating:o.state.isValidating,Resend:Nr,Submit:E})})})}function bt(e){return s.jsx(me,{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:d,setVerifiableAddress:w}=J(),{error:f}=Be(),{mutate:g}=Or({returnTo:o});return ee({initialFlowId:t,currentFlowId:c,error:f,onFlowRestart:a,createFlow:g,setFlowId:u}),!d&&n&&w(n),s.jsx(Rr,{emailVerificationForm:e,onError:i,onVerificationSuccess:r})}const Dr=Object.freeze(Object.defineProperty({__proto__:null,VerificationFlow:bt,VerificationFlowProvider:me,VerificationFlowWrapper:Fe,useVerificationFlowContext:J},Symbol.toStringTag,{value:"Module"})),Ir=G("login_flow"),ve=(e="no_id")=>z([Ir,e]),Ct=l.createContext(void 0);function Jr({children:e}){const[t,n]=l.useState(),o=l.useCallback(()=>{n(void 0)},[]);return s.jsx(Ct.Provider,{value:{loginFlowId:t,setLoginFlowId:n,resetFlow:o},children:e})}function Se(){const e=l.useContext(Ct);if(e===void 0)throw new Error("useLoginFlowContext must be used within a LoginFlow");return e}function Ar({aal:e,refresh:t,returnTo:n}={}){const{kratosClient:o}=x(),{setLoginFlowId:i}=Se(),r=y.useQueryClient();return y.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 A(){const{kratosClient:e}=x(),{loginFlowId:t}=Se();return y.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 oe({error:o})}},enabled:!!t,staleTime:1/0})}const xt=()=>{const{data:e}=A();return l.useMemo(()=>{if(!e)return;const t=T(e.ui.nodes,"identifier");if(!(!t||t.attributes.node_type!=="input"||typeof t.attributes.value!="string"))return t.attributes.value},[e])};function Q(){const{kratosClient:e}=x(),{loginFlowId:t,resetFlow:n}=Se(),{setVerificationFlowId:o,setVerifiableAddress:i}=J(),r=y.useQueryClient();return y.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 d=u.continue_with?.find(w=>w.action==="show_verification_ui");d!==void 0?(o(d.flow.id),i(d.flow.verifiable_address)):Ve(u.continue_with,{onRedirect:(w,f)=>{globalThis.location.href=w}})}return u}catch(c){return await B({onRedirect:(u,d)=>{globalThis.location.href=u},onRestartFlow:n,onValidationError:u=>u})(c)}},onSuccess(a){a&&"id"in a&&r.setQueryData(ve(a.id),a)}})}const Tt=l.createContext(void 0);function Ur({children:e,passwordForm:t}){const n=l.useMemo(()=>({passwordForm:t}),[t]);return s.jsx(Tt.Provider,{value:n,children:e})}function qe(){const e=l.useContext(Tt);if(e===void 0)throw new Error("useChooseMethodFormContext must be used within a ChooseMethodFormProvider");return e}function $e({children:e,provider:t}){const{mutate:n}=Q(),{data:o}=A(),i=l.useCallback(()=>{o&&n({method:"oidc",csrf_token:v(o),provider:t})},[o,n,t]),r=m.Root;return s.jsx(r,{type:"button",onClick:i,children:e})}function Ot({children:e}){return s.jsx($e,{provider:"apple",children:e})}function Nt({children:e}){return s.jsx($e,{provider:"facebook",children:e})}function Et({children:e}){return s.jsx($e,{provider:"google",children:e})}function Lr({children:e}){const{passwordForm:t}=qe(),n=m.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 Mt({children:e}){const{passwordForm:t}=qe(),n=m.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 Vr({children:e,onError:t,onLoginSuccess:n}){const{mutateAsync:o}=Q(),{data:i}=A(),{passwordForm:r}=qe(),a=l.useCallback(async f=>{if(!i)return;const g=await o({method:"passkey",csrf_token:v(i),passkey_login:f});if(g){if(pe(g)){n?.();return}N(g,r,t)}},[i,t,n,r,o]),c=l.useMemo(()=>K(T(i?.ui.nodes,"passkey_challenge")),[i?.ui.nodes]),u=l.useMemo(()=>z([G("passkey"),c?.value]),[c?.value]);y.useQuery({queryKey:u,queryFn:async({signal:f})=>{if(!c)throw new Error("No challenge provided");const g=await yn(c.value,f);return g?await a(g):!1},enabled:!!c,retry:!1});const d=l.useCallback(async()=>{if(!c)return;const f=await mn(c.value);f&&a(f)},[c,a]),w=m.Root;return s.jsx(w,{type:"button",onClick:d,children:e})}var ie=(e=>(e.Identifier="identifier",e.Password="password",e))(ie||{});function Pr({onError:e,onLoginSuccess:t}){const{mutateAsync:n}=Q(),{data:o}=A(),i=xt();return D.useForm({defaultValues:{[ie.Identifier]:i??"",[ie.Password]:""},onSubmit:async({value:r,formApi:a})=>{if(!o)return;const c=await n({csrf_token:v(o),method:"password",identifier:r[ie.Identifier],password:r[ie.Password]});if(c){if(pe(c)){t?.();return}N(c,a,e)}}})}function Wr({chooseMethodForm:e,isRefresh:t,onError:n,onLoginSuccess:o}){const{data:i}=A(),r=Pr({onError:n,onLoginSuccess:o}),a=I(r),c=xt(),u=l.useCallback(d=>s.jsx(Vr,{...d,onError:n}),[n]);return i?s.jsx(Ur,{passwordForm:r,children:s.jsx("form",{onSubmit:d=>{d.preventDefault(),r.handleSubmit()},children:t?s.jsx(e,{isRefresh:!0,Apple:_e(i.ui.nodes,"apple")?Ot:void 0,errors:a,Facebook:_e(i.ui.nodes,"facebook")?Nt:void 0,Google:_e(i.ui.nodes,"google")?Et:void 0,identifier:c,isSubmitting:r.state.isSubmitting,isValidating:r.state.isValidating,Passkey:T(i.ui.nodes,"passkey_login")&&u,passwordFields:T(i.ui.nodes,"password")&&{Password:Mt,Submit:E}}):s.jsx(e,{Apple:Ot,errors:a,Facebook:Nt,Google:Et,isSubmitting:r.state.isSubmitting,isValidating:r.state.isValidating,Passkey:u,passwordFields:{Identifier:Lr,Password:Mt,Submit:E}})})}):null}function Br({children:e}){const{mutate:t}=Q(),{data:n}=A(),o=l.useCallback(()=>{if(!n)return;const r=K(T(n.ui.nodes,"identifier"))?.value;t({method:"code",csrf_token:v(n),resend:"code",identifier:r})},[n,t]),i=m.Root;return s.jsx(i,{type:"button",onClick:o,children:e})}const Rt=l.createContext(void 0);function qr({children:e,codeForm:t}){const n=l.useMemo(()=>({codeForm:t}),[t]);return s.jsx(Rt.Provider,{value:n,children:e})}function $r(){const e=l.useContext(Rt);if(e===void 0)throw new Error("useSecondFactorEmailFormContext must be used within a SecondFactorEmailFormProvider");return e}function Kr({children:e}){const{codeForm:t}=$r(),n=m.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 Dt=(e=>(e.Code="code",e))(Dt||{});function zr({onError:e,onLoginSuccess:t}){const{mutateAsync:n}=Q(),{data:o}=A();return D.useForm({defaultValues:{[Dt.Code]:""},onSubmit:async({value:i,formApi:r})=>{if(!o)return;const a=K(T(o.ui.nodes,"identifier"))?.value,c=await n({csrf_token:v(o),method:"code",code:i.code,identifier:a});if(c){if(pe(c)){t?.();return}N(c,r,e)}}})}function Gr({secondFactorForm:e,onError:t,onLoginSuccess:n}){const o=zr({onError:t,onLoginSuccess:n}),i=I(o);return s.jsx(qr,{codeForm:o,children:s.jsx("form",{onSubmit:r=>{r.preventDefault(),o.handleSubmit()},children:s.jsx(e,{Code:Kr,errors:i,isSubmitting:o.state.isSubmitting,isValidating:o.state.isValidating,Resend:Br,Submit:E})})})}function Qr({children:e}){const{mutate:t}=Q(),{data:n}=A(),o=l.useCallback(()=>{if(!n)return;const r=K(T(n.ui.nodes,"address"))?.value;r&&t({method:"code",csrf_token:v(n),address:r})},[n,t]),i=m.Root;return s.jsx(i,{type:"button",onClick:o,children:e})}const It=l.createContext(void 0),Hr=({children:e,totpForm:t})=>{const n=l.useMemo(()=>({totpForm:t}),[t]);return s.jsx(It.Provider,{value:n,children:e})};function Xr(){const e=l.useContext(It);if(e===void 0)throw new Error("useSecondFactorFormContext must be used within a SecondFactorFormProvider");return e}function Yr({children:e}){const{totpForm:t}=Xr(),n=m.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 Jt=(e=>(e.TotpCode="totp_code",e))(Jt||{});function Zr({onError:e,onLoginSuccess:t}){const{mutateAsync:n}=Q(),{data:o}=A();return D.useForm({defaultValues:{[Jt.TotpCode]:""},onSubmit:async({value:i,formApi:r})=>{if(!o)return;const a=await n({csrf_token:v(o),method:"totp",totp_code:i.totp_code});if(a){if(pe(a)){t?.();return}N(a,r,e)}}})}function jr({secondFactorForm:e,isRefresh:t,onError:n,onLoginSuccess:o}){const i=Zr({onError:n,onLoginSuccess:o}),r=I(i),{data:a}=A();return s.jsx(Hr,{totpForm:i,children:s.jsx("form",{onSubmit:c=>{c.preventDefault(),i.handleSubmit()},children:s.jsx(e,{Email:T(a?.ui.nodes,"address")&&Qr,errors:r,isRefresh:t,isSubmitting:i.state.isSubmitting,isValidating:i.state.isValidating,Submit:E,Totp:Yr})})})}function ea({loaderComponent:e,chooseMethodForm:t,secondFactorForm:n,secondFactorEmailForm:o,emailVerificationForm:i,initialFlowId:r,returnTo:a,onError:c,onLoginSuccess:u,onVerificationSuccess:d,onFlowRestart:w,onSessionAlreadyAvailable:f}){const{loginFlowId:g,setLoginFlowId:k}=Se(),{verificationFlowId:O}=J(),{sessionManager:h}=Ne(),{isAal2Required:S}=h.useIsAal2Required(),{mutate:$,error:H}=Ar({returnTo:a,aal:S?"aal2":void 0}),{data:R,error:je}=A();ee({initialFlowId:r,currentFlowId:g,error:je??void 0,onFlowRestart:w,createFlow:$,setFlowId:k,waitForSession:!0});const Oe=l.useMemo(()=>he(H)||he(je),[H,je]);l.useEffect(()=>{Oe&&f?.()},[Oe,f]);const se=l.useMemo(()=>{if(Oe)return"invalid";if(!R)return"loader";if(O)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,O,Oe]),ln=l.useMemo(()=>R?.refresh,[R]);return s.jsxs(s.Fragment,{children:[se==="loader"&&e&&s.jsx(e,{}),se==="chooseMethod"&&s.jsx(Wr,{chooseMethodForm:t,isRefresh:ln,onError:c,onLoginSuccess:u}),se==="secondFactor"&&s.jsx(jr,{isRefresh:ln,secondFactorForm:n,onError:c,onLoginSuccess:u}),se==="secondFactorEmail"&&s.jsx(Gr,{secondFactorForm:o,onError:c,onLoginSuccess:u}),se==="verifyEmail"&&s.jsx(Fe,{emailVerificationForm:i,onError:c,onVerificationSuccess:d})]})}function At(e){return s.jsx(me,{children:s.jsx(Jr,{children:s.jsx(ea,{...e})})})}const ta=Object.freeze(Object.defineProperty({__proto__:null,LoginFlow:At},Symbol.toStringTag,{value:"Module"})),Ut=()=>{const{kratosClient:e}=x(),{sessionManager:t}=Ne(),n=y.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:[We]}),{isSuccess:!0}}catch(r){return{isSuccess:!1,error:r}}}}},na=Object.freeze(Object.defineProperty({__proto__:null,useLogout:Ut},Symbol.toStringTag,{value:"Module"})),Lt=l.createContext(void 0);function oa({children:e,chooseMethodForm:t}){const n=l.useMemo(()=>({chooseMethodForm:t}),[t]);return s.jsx(Lt.Provider,{value:n,children:e})}function Ke(){const e=l.useContext(Lt);if(e===void 0)throw new Error("useChooseMethodFormContext must be used within a ChooseMethodFormProvider");return e}const ia=G("registration_flow"),ke=(e="no_id")=>z([ia,e]),Vt=l.createContext(void 0);function ra({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(Vt.Provider,{value:{registrationFlowId:t,setRegistrationFlowId:n,traitsFormCompleted:o,setTraitsFormCompleted:i,traits:r,setTraits:a,resetFlow:c},children:e})}function q(){const e=l.useContext(Vt);if(e===void 0)throw new Error("useRegistrationFlowContext must be used within a RegistrationFlow");return e}function aa({returnTo:e}={}){const{kratosClient:t}=x(),{setRegistrationFlowId:n}=q(),o=y.useQueryClient();return y.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 re(){const{kratosClient:e}=x(),{registrationFlowId:t}=q();return y.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 oe({error:o})}},enabled:!!t,staleTime:1/0})}function be(){const{kratosClient:e}=x(),{resetFlow:t,registrationFlowId:n}=q(),{setVerificationFlowId:o,setVerifiableAddress:i}=J(),r=y.useQueryClient();return y.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 d=u.continue_with?.find(w=>w.action==="show_verification_ui");d!==void 0?(o(d.flow.id),i(d.flow.verifiable_address)):Ve(u.continue_with,{onRedirect:(w,f)=>{globalThis.location.href=w}})}return u}catch(c){return await B({onRedirect:(u,d)=>{globalThis.location.href=u},onRestartFlow:t,onValidationError:u=>u})(c)}},onSuccess(a){a&&"id"in a&&r.setQueryData(ke(a.id),a)}})}function sa({children:e}){const{setTraitsFormCompleted:t}=q(),n=l.useCallback(()=>{t(!1)},[t]),o=m.Root;return s.jsx(o,{type:"button",onClick:n,children:e})}function ca({children:e,onError:t,onRegistrationSuccess:n}){const{traits:o}=q(),{mutateAsync:i}=be(),{data:r}=re(),{chooseMethodForm:a}=Ke(),c=l.useCallback(async f=>{if(!r)return;const g=await i({method:"passkey",csrf_token:v(r),traits:o??{},passkey_register:f});if(g){if(Le(g)){n?.();return}N(g,a,t)}},[t,n,r,o,a,i]),u=l.useMemo(()=>K(T(r?.ui.nodes,"passkey_create_data")),[r?.ui.nodes]),d=l.useCallback(async()=>{if(!u)return;const f=await Fn(u.value,void 0,o);f&&c(f)},[u,c,o]),w=m.Root;return s.jsx(w,{type:"button",onClick:d,children:e})}function la({children:e}){const{chooseMethodForm:t}=Ke(),n=m.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 U=(e=>(e.Password="password",e.PasswordConfirmation="password_confirmation",e))(U||{});const Pt=({value:e,fieldApi:t})=>{const n=t.form.getFieldMeta(U.PasswordConfirmation);if(n?.isDirty&&n?.isTouched)return Wt(e,t.form.getFieldValue(U.Password))},Wt=(e,t)=>{if(!e)return[ge(ne.FieldRequired)];if(e!==t)return[ge(ne.FieldMismatch)]};function ua({children:e}){const{chooseMethodForm:t}=Ke(),n=m.Root;return s.jsx(t.Field,{listeners:{onChange:({fieldApi:o})=>{o.form.setFieldMeta(U.PasswordConfirmation,i=>({...i,errorMap:{...i.errorMap,onSubmit:void 0}}))}},name:"password_confirmation",validators:{onChangeListenTo:[U.Password],onChange:Pt,onBlurListenTo:[U.PasswordConfirmation],onBlur:Pt,onSubmit:({value:o,fieldApi:i})=>Wt(o,i.form.getFieldValue(U.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 da({onError:e,onRegistrationSuccess:t}){const{setTraitsFormCompleted:n,traits:o}=q(),{mutateAsync:i}=be(),{data:r}=re();return D.useForm({defaultValues:{[U.Password]:"",[U.PasswordConfirmation]:""},onSubmit:async({value:a,formApi:c})=>{if(!r)return;const u=await i({csrf_token:v(r),method:"password",traits:o??{},password:a[U.Password]});if(u){if(Le(u)){t?.();return}u.state===ut.ChooseMethod&&n(!0),N(u,c,e)}}})}function fa({chooseMethodForm:e,onError:t,onRegistrationSuccess:n}){const o=da({onError:t,onRegistrationSuccess:n}),i=I(o);return s.jsx(oa,{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:ca,passwordFields:{Password:la,PasswordConfirmation:ua,Submit:E},ReturnToTraitsForm:sa})})})}function ze({children:e,provider:t}){const{mutate:n}=be(),{data:o}=re(),i=l.useCallback(()=>{o&&n({method:"oidc",csrf_token:v(o),provider:t})},[o,n,t]),r=m.Root;return s.jsx(r,{type:"button",onClick:i,children:e})}function pa({children:e}){return s.jsx(ze,{provider:"apple",children:e})}function wa({children:e}){return s.jsx(ze,{provider:"facebook",children:e})}function ha({children:e}){return s.jsx(ze,{provider:"google",children:e})}const Bt=l.createContext(void 0);function ga({children:e,traitsForm:t}){const n=l.useMemo(()=>({traitsForm:t}),[t]);return s.jsx(Bt.Provider,{value:n,children:e})}function qt(){const e=l.useContext(Bt);if(e===void 0)throw new Error("useTraitsFormContext must be used within a TraitsFormProvider");return e}function _a({trait:e,children:t}){const{traitsForm:n}=qt(),o=m.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 ya({trait:e,children:t}){const{traitsForm:n}=qt(),o=m.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 ma({traitsConfig:e,onError:t,onRegistrationSuccess:n}){const{setTraitsFormCompleted:o,setTraits:i,traits:r}=q(),{mutateAsync:a}=be(),{data:c}=re();return D.useForm({defaultValues:{traits:r??Object.fromEntries(Object.values(e).map(({trait:u,type:d})=>[u,d==="boolean"?!1:""]))},onSubmit:async({value:u,formApi:d})=>{if(!c)return;const w=await a({csrf_token:v(c),method:"profile",traits:u.traits??{}});if(w){if(Le(w)){n?.();return}w.state===ut.ChooseMethod&&w.ui.messages?.some(({id:f})=>f===1040009)&&(i(u.traits),o(!0)),N(w,d,t)}}})}function Fa({traitsConfig:e,traitsForm:t,onError:n,onRegistrationSuccess:o}){const i=ma({traitsConfig:e,onError:n,onRegistrationSuccess:o}),r=I(i),a=l.useMemo(()=>Object.fromEntries(Object.entries(e).map(([c,u])=>[c,u.type==="boolean"?({children:d})=>s.jsx(ya,{children:d,trait:u.trait}):({children:d})=>s.jsx(_a,{children:d,trait:u.trait})])),[e]);return s.jsx(ga,{traitsForm:i,children:s.jsx("form",{onSubmit:c=>{c.preventDefault(),i.handleSubmit()},children:s.jsx(t,{Apple:pa,errors:r,Facebook:wa,Google:ha,isSubmitting:i.state.isSubmitting,isValidating:i.state.isValidating,traitFields:{...a,Submit:E}})})})}function va({traitsConfig:e,traitsForm:t,chooseMethodForm:n,emailVerificationForm:o,initialFlowId:i,returnTo:r,onError:a,onRegistrationSuccess:c,onVerificationSuccess:u,onFlowRestart:d,onSessionAlreadyAvailable:w}){const{verificationFlowId:f}=J(),{registrationFlowId:g,setRegistrationFlowId:k,traitsFormCompleted:O}=q(),{error:h}=re(),{mutate:S,error:$}=aa({returnTo:r});ee({initialFlowId:i,currentFlowId:g,error:h??void 0,onFlowRestart:d,createFlow:S,setFlowId:k});const H=l.useMemo(()=>he(h)||he($),[h,$]);l.useEffect(()=>{H&&w?.()},[H,w]);const R=l.useMemo(()=>H?"invalid":f?"emailVerification":O?"credentials":"traits",[O,f,H]);return s.jsxs(s.Fragment,{children:[R==="traits"&&s.jsx(Fa,{traitsConfig:e,traitsForm:t,onError:a,onRegistrationSuccess:c}),R==="credentials"&&s.jsx(fa,{chooseMethodForm:n,onError:a,onRegistrationSuccess:c}),R==="emailVerification"&&s.jsx(Fe,{emailVerificationForm:o,onError:a,onVerificationSuccess:u})]})}function $t(e){return s.jsx(me,{children:s.jsx(ra,{children:s.jsx(va,{...e})})})}const Sa=Object.freeze(Object.defineProperty({__proto__:null,RegistrationFlow:$t},Symbol.toStringTag,{value:"Module"})),ka=G("settings_flow"),Ce=(e="no_id")=>z([ka,e]),Kt=l.createContext(void 0);function Ge({children:e}){const[t,n]=l.useState(),[o,i]=l.useState(!1),r=l.useCallback(()=>{n(void 0)},[]);return s.jsx(Kt.Provider,{value:{settingsFlowId:t,setSettingsFlowId:n,emailVerificationRequired:o,setEmailVerificationRequired:i,resetFlow:r},children:e})}function ae(){const e=l.useContext(Kt);if(e===void 0)throw new Error("useSettingsFlow must be used within a SettingsFlowProvider");return e}function ba(){const{kratosClient:e}=x(),{setSettingsFlowId:t}=ae(),n=y.useQueryClient();return y.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}=ae();return y.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 oe({error:o})}},enabled:!!t,staleTime:1/0})}function j(){const{kratosClient:e}=x(),{settingsFlowId:t,resetFlow:n,setEmailVerificationRequired:o}=ae(),i=y.useQueryClient();return y.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):Ve(a.continue_with,{onRedirect:(u,d)=>{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 zt=l.createContext(void 0);function Ca({children:e,newPasswordForm:t}){const n=l.useMemo(()=>({newPasswordForm:t}),[t]);return s.jsx(zt.Provider,{value:n,children:e})}function Gt(){const e=l.useContext(zt);if(e===void 0)throw new Error("useNewPasswordFormContext must be used within a NewPasswordFormProvider");return e}function xa({children:e}){const{newPasswordForm:t}=Gt(),n=m.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 Qt=({value:e,fieldApi:t})=>{const n=t.form.getFieldMeta(L.PasswordConfirmation);if(n?.isDirty&&n?.isTouched)return Ht(e,t.form.getFieldValue(L.Password))},Ht=(e,t)=>{if(!e)return[ge(ne.FieldRequired)];if(e!==t)return[ge(ne.FieldMismatch)]};function Ta({children:e}){const{newPasswordForm:t}=Gt(),n=m.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:Qt,onBlurListenTo:[L.PasswordConfirmation],onBlur:Qt,onSubmit:({value:o,fieldApi:i})=>Ht(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 Oa({onError:e,onChangePasswordSuccess:t}){const{mutateAsync:n}=j(),{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:v(o),method:"password",password:i[L.Password]});if(a){if(a.state==="success"){t?.();return}N(a,r,e)}}})}function Na({newPasswordForm:e,emailVerificationRequired:t,onError:n,onChangePasswordSuccess:o}){const{data:i}=M(),r=Oa({onError:n,onChangePasswordSuccess:o}),a=I(r);return s.jsx(Ca,{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:xa,PasswordConfirmation:Ta,Submit:E})})})}function Ea({children:e,provider:t,type:n}){const{mutate:o}=j(),{data:i}=M(),r=l.useCallback(()=>{i&&o({method:"oidc",[n]:t})},[i,o,n,t]),a=m.Root;return s.jsx(a,{oidcType:n,type:"button",onClick:r,children:e})}const Ma=(e,t)=>{const n=_e(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 Ra({oidcForm:e}){const{data:t}=M(),n=l.useMemo(()=>t?yt.reduce((o,i)=>{const r=dn.toUpperFirst(i),a=Ma(i,t.ui.nodes);return a&&(o[r]=({children:c})=>s.jsx(Ea,{provider:i,type:a,children:c})),o},{}):{},[t]);return s.jsx(e,{...n,isLoading:!t})}const Da=()=>{const{mutateAsync:e,isPending:t}=j(),{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:v(n),passkey_remove:c})}},[t,n,e]),i=l.useCallback(async c=>{n&&await e({method:"passkey",csrf_token:v(n),passkey_settings_register:c})},[n,e]),r=l.useMemo(()=>K(T(n?.ui.nodes,"passkey_create_data")),[n?.ui.nodes]),a=l.useCallback(async()=>{if(t||!r)return;const c=await vn(r.value);c&&await i(c)},[t,r,i]);return{isPending:t,removePasskey:o,addNewPasskey:a}};function Ia({passkeysForm:e}){const{data:t}=M(),{removePasskey:n,isPending:o,addNewPasskey:i}=Da(),r=t?Fr(t.ui.nodes,"passkey_remove").filter(Sr).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 Xt=l.createContext(void 0);function Ja({children:e,totpForm:t}){const n=l.useMemo(()=>({totpForm:t}),[t]);return s.jsx(Xt.Provider,{value:n,children:e})}function Aa(){const e=l.useContext(Xt);if(e===void 0)throw new Error("useTotpFormContext must be used within a TotpFormProvider");return e}function Ua({children:e}){const{totpForm:t}=Aa(),n=m.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 La({children:e}){const{mutateAsync:t}=j(),{data:n}=M(),o=l.useCallback(async()=>{n&&await t({method:"totp",csrf_token:v(n),totp_unlink:!0})},[n,t]),i=m.Root;return s.jsx(i,{type:"button",onClick:o,children:e})}var Qe=(e=>(e.Code="code",e))(Qe||{});function Va({onError:e,onTotpSuccess:t}){const{mutateAsync:n}=j(),{data:o}=M();return D.useForm({defaultValues:{[Qe.Code]:""},onSubmit:async({value:i,formApi:r})=>{if(!o)return;const a=await n({csrf_token:v(o),method:"totp",totp_code:i[Qe.Code]});if(a){if(a.state==="success"){t?.();return}N(a,r,e)}}})}function Pa({totpForm:e,emailVerificationRequired:t,onError:n,onTotpSuccess:o}){const i=Va({onError:n,onTotpSuccess:o}),r=I(i),{data:a}=M(),c=l.useMemo(()=>{if(!a)return;const f=T(a.ui.nodes,"totp_qr");if(!(!f||f.attributes.node_type!==lt.Img))return f.attributes.src},[a]),u=l.useMemo(()=>{if(!a)return;const f=T(a.ui.nodes,"totp_secret_key");if(!f||f.attributes.node_type!==lt.Text)return;const{text:g}=f.attributes;return g.context&&"secret"in g.context&&typeof g.context.secret=="string"?g.context.secret:g.text},[a]),d=l.useMemo(()=>{if(a)return!!T(a.ui.nodes,"totp_unlink")},[a]),w=!a||d===void 0;return s.jsx(Ja,{totpForm:i,children:s.jsx("form",{onSubmit:f=>{f.preventDefault(),i.handleSubmit()},children:w?s.jsx(e,{isLoading:!0}):d?s.jsx(e,{isTotpLinked:!0,emailVerificationRequired:t,Unlink:La}):s.jsx(e,{Code:Ua,emailVerificationRequired:t,errors:r,isSubmitting:i.state.isSubmitting,isValidating:i.state.isValidating,Submit:E,totpQrImageSrc:c,totpSecretKey:u})})})}const Yt=l.createContext(void 0);function Wa({children:e,traitsForm:t}){const n=l.useMemo(()=>({traitsForm:t}),[t]);return s.jsx(Yt.Provider,{value:n,children:e})}function Zt(){const e=l.useContext(Yt);if(e===void 0)throw new Error("useTraitsFormContext must be used within a TraitsFormProvider");return e}function Ba({trait:e,children:t}){const{traitsForm:n}=Zt(),o=m.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 qa({trait:e,children:t}){const{traitsForm:n}=Zt(),o=m.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 $a({traitsConfig:e,onError:t,onChangeTraitsSuccess:n}){const{mutateAsync:o}=j(),{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:v(i),method:"profile",traits:r.traits??{}});if(c){if(c.state===Po.Success){n?.();return}N(c,a,t)}}})}function Ka({traitsConfig:e,traitsForm:t,emailVerificationRequired:n,onError:o,onChangeTraitsSuccess:i}){const{data:r}=M(),a=$a({traitsConfig:e,onError:o,onChangeTraitsSuccess:i}),c=I(a),u=l.useMemo(()=>Object.fromEntries(Object.entries(e).map(([d,w])=>[d,w.type==="boolean"?({children:f})=>s.jsx(qa,{children:f,trait:w.trait}):({children:f})=>s.jsx(Ba,{children:f,trait:w.trait})])),[e]);return s.jsx(Wa,{traitsForm:a,children:s.jsx("form",{onSubmit:d=>{d.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 jt(e){return s.jsx(Ge,{children:s.jsx(He,{...e})})}function He({newPasswordForm:e,traitsForm:t,passkeysForm:n,totpForm:o,oidcForm:i,traitsConfig:r,settingsForm:a,initialFlowId:c,onError:u,onChangePasswordSuccess:d,onChangeTraitsSuccess:w,onFlowRestart:f}){const{settingsFlowId:g,setSettingsFlowId:k,emailVerificationRequired:O}=ae(),{mutate:h}=ba(),{data:S,error:$}=M();return ee({initialFlowId:c,currentFlowId:g,error:$,onFlowRestart:f,createFlow:h,setFlowId:k}),s.jsx(a,{emailVerificationRequired:O,isLoading:!S,newPasswordForm:e&&s.jsx(Na,{emailVerificationRequired:O,newPasswordForm:e,onChangePasswordSuccess:d,onError:u}),oidcForm:i&&s.jsx(Ra,{oidcForm:i}),passkeysForm:n&&s.jsx(Ia,{passkeysForm:n}),totpForm:o&&s.jsx(Pa,{emailVerificationRequired:O,totpForm:o,onError:u,onTotpSuccess:w}),traitsForm:r&&t&&s.jsx(Ka,{emailVerificationRequired:O,traitsConfig:r,traitsForm:t,onChangeTraitsSuccess:w,onError:u})})}const za=Object.freeze(Object.defineProperty({__proto__:null,SettingsFlow:jt,SettingsFlowProvider:Ge,SettingsFlowWrapper:He,useSettingsFlowContext:ae},Symbol.toStringTag,{value:"Module"})),en=l.createContext(void 0);function Ga({children:e,codeForm:t}){const n=l.useMemo(()=>({codeForm:t}),[t]);return s.jsx(en.Provider,{value:n,children:e})}function Qa(){const e=l.useContext(en);if(e===void 0)throw new Error("useCodeFormContext must be used within a CodeFormProvider");return e}function Ha({children:e}){const{codeForm:t}=Qa(),n=m.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 Xa=G("recovery_flow"),xe=(e="no_id")=>z([Xa,e]),tn=l.createContext(void 0);function Ya({children:e}){const[t,n]=l.useState(),o=l.useCallback(()=>{n(void 0)},[]);return s.jsx(tn.Provider,{value:{recoveryFlowId:t,setRecoveryFlowId:n,resetFlow:o},children:e})}function Te(){const e=l.useContext(tn);if(e===void 0)throw new Error("useRecoveryFlowContext must be used within a RecoveryFlow");return e}function Za({returnTo:e}={}){const{kratosClient:t}=x(),{setRecoveryFlowId:n}=Te(),o=y.useQueryClient();return y.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 Xe(){const{kratosClient:e}=x(),{recoveryFlowId:t}=Te();return y.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 oe({error:o})}},enabled:!!t,staleTime:1/0})}function nn(){const{kratosClient:e}=x(),{resetFlow:t,recoveryFlowId:n}=Te(),o=y.useQueryClient();return y.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 Ye=(e=>(e.Code="code",e))(Ye||{});function ja({onError:e}){const{mutateAsync:t}=nn(),{data:n}=Xe();return D.useForm({defaultValues:{[Ye.Code]:""},onSubmit:async({value:o,formApi:i})=>{if(!n)return;const r=await t({csrf_token:v(n),method:"code",code:o[Ye.Code]});r&&N(r,i,e)}})}function es({codeForm:e,onError:t}){const n=ja({onError:t}),o=I(n);return s.jsx(Ga,{codeForm:n,children:s.jsx("form",{onSubmit:i=>{i.preventDefault(),n.handleSubmit()},children:s.jsx(e,{Code:Ha,errors:o,isSubmitting:n.state.isSubmitting,isValidating:n.state.isValidating,Submit:E})})})}const on=l.createContext(void 0);function ts({children:e,emailForm:t}){const n=l.useMemo(()=>({emailForm:t}),[t]);return s.jsx(on.Provider,{value:n,children:e})}function ns(){const e=l.useContext(on);if(e===void 0)throw new Error("useEmailFormContext must be used within a EmailFormProvider");return e}function os({children:e}){const{emailForm:t}=ns(),n=m.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 Ze=(e=>(e.Email="email",e))(Ze||{});function is({onError:e}){const{mutateAsync:t}=nn(),{data:n}=Xe();return D.useForm({defaultValues:{[Ze.Email]:""},onSubmit:async({value:o,formApi:i})=>{if(!n)return;const r=await t({csrf_token:v(n),method:"code",email:o[Ze.Email]});r&&N(r,i,e)}})}function rs({emailForm:e,onError:t}){const n=is({onError:t}),o=I(n);return s.jsx(ts,{emailForm:n,children:s.jsx("form",{onSubmit:i=>{i.preventDefault(),n.handleSubmit()},children:s.jsx(e,{Email:os,errors:o,isSubmitting:n.state.isSubmitting,isValidating:n.state.isValidating,Submit:E})})})}function as({emailForm:e,codeForm:t,newPasswordForm:n,initialFlowId:o,returnTo:i,onError:r,onRecoverySuccess:a,onFlowRestart:c}){const{recoveryFlowId:u,setRecoveryFlowId:d}=Te(),{mutate:w}=Za({returnTo:i}),{data:f,error:g}=Xe(),k=l.useMemo(()=>f?.continue_with?.find(h=>h.action==="show_settings_ui")?.flow.id,[f]);ee({initialFlowId:o,currentFlowId:u,error:g,onFlowRestart:c,createFlow:w,setFlowId:d});const O=l.useMemo(()=>k?"newPassword":f?.state==="sent_email"?"code":"email",[f?.state,k]);return s.jsxs(s.Fragment,{children:[O==="email"&&s.jsx(rs,{emailForm:e,onError:r}),O==="code"&&s.jsx(es,{codeForm:t,onError:r}),O==="newPassword"&&k&&s.jsx(He,{initialFlowId:k,newPasswordForm:n,settingsForm:({newPasswordForm:h})=>h,onChangePasswordSuccess:a,onError:r})]})}function rn(e){return s.jsx(Ge,{children:s.jsx(Ya,{children:s.jsx(as,{...e})})})}const ss=Object.freeze(Object.defineProperty({__proto__:null,RecoveryFlow:rn},Symbol.toStringTag,{value:"Module"})),an=z([G("session_manager"),"session"]),sn=e=>({queryKey:an,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 cn{queryClient;api;getSession=async()=>{try{return await this.queryClient.fetchQuery(sn(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}=y.useQuery({...sn(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)&&cr(t.error.cause):void 0,isLoading:t.isLoading}};checkIfLoggedIn=async()=>await this.queryClient.refetchQueries({queryKey:an,exact:!0});constructor({queryClient:t,api:n}){this.api=n,this.queryClient=t}}function cs({queryClient:e,basePath:t,traits:n={},SessionManager:o=cn}){const i=new rr(new rt({basePath:t,credentials:"include"})),r=new o({queryClient:e,api:i});return{flows:{useLogout:Ut,LoginFlow:At,RecoveryFlow:rn,RegistrationFlow:d=>s.jsx($t,{traitsConfig:n,...d}),SettingsFlow:d=>s.jsx(jt,{traitsConfig:n,...d}),VerificationFlow:bt},providers:{KratosProviders:({children:d})=>s.jsx(br,{api:i,children:s.jsx(pn,{sessionManager:r,children:d})})},session:{sessionManager:r}}}b.BaseSessionManager=cn,b.loginFlow=ta,b.logoutFlow=na,b.mkKratos=cs,b.recoveryFlow=ss,b.registrationFlow=Sa,b.settingsFlow=za,b.verificationFlow=Dr,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}}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"})}));
|