@leancodepl/kratos
Version:
Headless React components library for building Ory Kratos authentication flows
1 lines • 106 kB
JavaScript
(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_browse