1import{AuthError as s,SignupAction as N,LoginChallengeType as f}from"./index.DbIBqvaw.js";import{a as d}from"./index.CbUm5JID.js";import{Z as h}from"./zones.-sXk8wqd.js";import{A as e}from"./AuthErrorCode.CY9fqB_E.js";import{U as O}from"./UserEventType.Baa6S0_b.js";import{m as c}from"./mapManhattanApiUser.CfP13BOC.js";import"./preload-helper.BlTxHScW.js";import"./resolve.B3WuOKFk.js";import"./subidTransformer.D67TlOXC.js";import"./isExternal.pyCLhaOv.js";import"./getFeatureFlagClient.CFsM0M_T.js";import"./index.DVwZf235.js";import"./utc.D8ANpP3u.js";import"./_commonjsHelpers.D6-XlEtG.js";import"./index.DBbMZl2G.js";import"./index.DdhaQPQ0.js";import"./impressions.model.D7dMMwUg.js";import"./impressionsStore.C0MRAWlD.js";import"./index.CDAgpjSw.js";import"./v4.BKrj-4V8.js";function w(S,a){const t=S.toLowerCase();return t.includes("active session")?e.SESSION_EXPIRED:t.includes("token has expired")?e.EXPIRED_ACTION_CODE:t.includes("token is not valid")?e.INVALID_ACTION_CODE:a===400?e.INVALID_ACTION_CODE:e.UNKNOWN_ERROR}class F{API_URL;tokenManager;httpClient;oauthPopupHandler;userStateManager;userPreferenceStrategy;constructor(a,t,r,n,i,o){this.API_URL=a.toString(),this.userStateManager=t,this.tokenManager=r,this.httpClient=n,this.oauthPopupHandler=i,this.userPreferenceStrategy=o}onUserChanged(a){return this.userStateManager.onUserChanged(a)}async validateAndRenewSession(){try{if(!await this.tokenManager.getToken())return{isSuccessful:!1,error:new s(e.SESSION_NOT_FOUND,"No session token found")};const t=await this.httpClient.fetch(`${this.API_URL}/api/v1/profile/check`),r=await this.getCurrentUser();if(t.ok&&r.isSuccessful&&r.user)return{isSuccessful:!0};const n=await t.json();switch(await this.userStateManager.clearUser(),t.status){case 401:return{isSuccessful:!1,error:new s(e.SESSION_NOT_FOUND,n.message)};default:return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,n.message)}}}catch{return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,"Failed to validate session")}}}async getCurrentUser(a){try{if(!await this.tokenManager.getToken())return{isSuccessful:!0,user:null};if(!a?.skipCache){const i=await this.userStateManager.getUser();if(i)return{isSuccessful:!0,user:i}}const r=await this.httpClient.fetch(`${this.API_URL}/api/v1/profile`),n=await r.json();if(r.ok){const i=c(n.data);return await this.userStateManager.setUser(i),{isSuccessful:!0,user:i}}switch(r.status){case 401:return{isSuccessful:!0,user:null};case 404:return{isSuccessful:!1,error:new s(e.SESSION_EXPIRED,n.message)};default:return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,n.message)}}}catch{return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,"Failed to get current user")}}}async deleteAccount(){try{if(!await this.tokenManager.getToken())return{isSuccessful:!1,error:new s(e.SESSION_NOT_FOUND,"No session token found")};const t=await this.httpClient.fetch(`${this.API_URL}/api/v1/profile/delete`,{method:"DELETE"});if(t.ok)return await this.userStateManager.clearUser(),{isSuccessful:!0};const r=await t.json();switch(t.status){case 401:return{isSuccessful:!1,error:new s(e.SESSION_NOT_FOUND,r.message)};default:return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,r.message)}}}catch{return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,"Failed to delete account")}}}async sendPasswordResetEmail(a){if(!a)return{isSuccessful:!1,error:new s(e.INVALID_EMAIL,"Email is required")};try{const t=await this.httpClient.fetch(`${this.API_URL}/api/v1/profile/forgotpassword`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:a})});if(t.ok)return{isSuccessful:!0};const r=await t.json();switch(t.status){case 400:{let n=e.UNKNOWN_ERROR;if(Array.isArray(r.failures)){for(const i of r.failures)if(i.includes("body.email")){n=e.INVALID_EMAIL;break}}return{isSuccessful:!1,error:new s(n,r.message,r.failures)}}default:return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,r.message)}}}catch{return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,"Failed to send password reset email")}}}async confirmPasswordReset(a,t){if(!a)return{isSuccessful:!1,error:new s(e.INVALID_ACTION_CODE,"Invalid action code")};
1if(!t)return{isSuccessful:!1,error:new s(e.INVALID_PASSWORD,"Invalid password")};try{const r=await this.httpClient.fetch(`${this.API_URL}/api/v1/profile/resetpassword`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resetToken:a,newPassword:t})});if(r.ok)return{isSuccessful:!0};const n=await r.json();switch(r.status){case 400:{let i=e.UNKNOWN_ERROR;if(Array.isArray(n.failures))for(const o of n.failures){if(o.includes("body.resetToken")){i=e.INVALID_ACTION_CODE;break}if(o.includes("body.newPassword")){i=e.INVALID_PASSWORD;break}}return{isSuccessful:!1,error:new s(i,n.message,n.failures)}}case 401:return{isSuccessful:!1,error:new s(e.INVALID_ACTION_CODE,n.message)};default:return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,n.message)}}}catch{return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,"Failed to confirm password reset")}}}async validatePasswordResetCode(a){return{isSuccessful:!0}}async sendVerificationEmail(){try{if(!await this.tokenManager.getToken())return{isSuccessful:!1,error:new s(e.SESSION_NOT_FOUND,"No session token found")};const t=await this.httpClient.fetch(`${this.API_URL}/api/v1/profile/sendverifyemail`,{method:"POST"});if(t.ok)return{isSuccessful:!0};const r=await t.json();switch(t.status){case 401:return{isSuccessful:!1,error:new s(e.SESSION_NOT_FOUND,r.message)}}return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,r.message)}}catch{return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,"Failed to send verification email")}}}async validateEmailVerificationCode(a){let t;try{const n=await this.httpClient.fetch(`${this.API_URL}/api/v1/profile/verifyemail`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:a})});if(n.ok){const i=await this.userStateManager.getUser();i&&await this.userStateManager.setUser({...i,emailVerified:!0},O.USER_UPDATED),t={isSuccessful:!0}}else{const o=(await n.json())?.message??"";t={isSuccessful:!1,error:new s(w(o,n.status),o)}}}catch{t={isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,"Failed to validate email")}}const r=t&&t.isSuccessful?"successful":"unsuccessful";return d.track("Authentication_Completed",{authenticationCompleted:r,zone:h.SHEET}),t}async registerWithEmailAndPassword(a,t,r,n){if(!a)return{isSuccessful:!1,error:new s(e.INVALID_EMAIL,"invalid email")};if(!t)return{isSuccessful:!1,error:new s(e.INVALID_PASSWORD,"invalid password")};if(!r)return{isSuccessful:!1,error:new s(e.INVALID_PROFILE_NAME,"invalid first name")};try{const i=await this.httpClient.fetch(`${this.API_URL}/api/v1/profile/register`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:a,password:t,firstName:r})}),o=await i.json();if(i.ok){const u=c(o.data);return await this.userStateManager.setUser(u),n?.signupActions?.includes(N.EMAIL_OPT_IN)&&await this.userPreferenceStrategy.setEmailOptIn(!0),{isSuccessful:!0,user:u}}switch(i.status){case 400:{let u=e.UNKNOWN_ERROR;for(const l of o.failures){if(l.includes("body.email")){u=e.INVALID_EMAIL;break}if(l.includes("body.password")){u=e.INVALID_PASSWORD;break}if(l.includes("body.firstName")){u=e.INVALID_PROFILE_NAME;break}}return{isSuccessful:!1,error:new s(u,o.message)}}case 409:return{isSuccessful:!1,error:new s(e.EMAIL_ALREADY_IN_USE,o.message)};default:return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,o.message)}}}catch{return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,"Failed to register with email and password")}}}async signOut(){try{if(!await this.tokenManager.getToken())return{isSuccessful:!1,error:new s(e.SESSION_NOT_FOUND,"No session token found")};const t=await this.httpClient.fetch(`${this.API_URL}/api/v1/profile/logout`,{method:"POST"});if(t.ok)return await this.userStateManager.clearUser(),{isSuccessful:!0};const r=await t.json();switch(t.status){case 401:return{isSuccessful:!1,error:new s(e.SESSION_NOT_FOUND,r.message)};case 404:return{isSuccessful:!1,error:new s(e.SESSION_EXPIRED,r.message)};default:return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,r.message)}}}catch{return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,"failed to sign out")}}}async signInAnonymously(){try{const a=await this.httpClient.fetch(`${this.API_URL}
1/api/v1/profile/loginanonymous`,{method:"POST"}),t=await a.json();if(a.ok){const r=c(t.data);return await this.userStateManager.setUser(r),{isSuccessful:!0,user:r}}switch(a.status){case 401:return{isSuccessful:!1,error:new s(e.SESSION_EXISTS,t.message)};default:return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,t.message)}}}catch{return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,"failed to sign in anonymously")}}}async signInWithEmailAndPassword(a,t){try{const r=await this.httpClient.fetch(`${this.API_URL}/api/v1/profile/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:a,password:t})}),n=await r.json();if(r.ok){const i=c(n.data);return await this.userStateManager.setUser(i),{isSuccessful:!0,user:i}}switch(r.status){case 401:return{isSuccessful:!1,error:new s(e.SESSION_EXISTS,n.message)};case 404:return{isSuccessful:!1,error:new s(e.CREDENTIAL_MISMATCH,n.message)};default:return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,n.message)}}}catch{return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,"Failed to sign in with email and password")}}}async getProfileDocuments(){try{if(!await this.tokenManager.getToken())return{isSuccessful:!1,documents:[],error:new s(e.SESSION_NOT_FOUND,"No session token found")};const t=await this.httpClient.fetch(`${this.API_URL}/api/v1/profile/documents`),r=await t.json().catch(()=>({}));return t.ok?{isSuccessful:!0,documents:r?.data?.documents??r?.documents??[]}:{isSuccessful:!1,documents:[],error:new s(e.UNKNOWN_ERROR,r?.message??"Failed to fetch profile documents")}}catch{return{isSuccessful:!1,documents:[],error:new s(e.UNKNOWN_ERROR,"Failed to fetch profile documents")}}}async acknowledgeProfileDocuments(a){try{if(!await this.tokenManager.getToken())return{isSuccessful:!1,error:new s(e.SESSION_NOT_FOUND,"No session token found")};const r=await this.httpClient.fetch(`${this.API_URL}/api/v1/profile/documents/acknowledge`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({documentId:a})});if(r.ok)return{isSuccessful:!0};const n=await r.json().catch(()=>({}));switch(r.status){case 400:return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,n?.message??"Invalid request")};case 401:return{isSuccessful:!1,error:new s(e.SESSION_NOT_FOUND,n?.message??"Not authenticated")};case 404:return{isSuccessful:!1,error:new s(e.SESSION_EXPIRED,n?.message??"Session expired")};case 451:return{isSuccessful:!1,error:new s(e.OPERATION_NOT_ALLOWED,n?.message??"Legal compliance required")};default:return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,n?.message??"Failed to acknowledge documents")}}}catch{return{isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,"Failed to acknowledge documents")}}}async signInWithProvider(a,t){const r=await this.oauthPopupHandler.initiateOAuthFlow(a,t);if(!r.isSuccessful||!r.authToken){const n=r.error??new s(e.UNKNOWN_ERROR,"Failed to complete OAuth sign in");return{challengeType:f.None,isSuccessful:!1,error:n}}return this.completeOAuthSignIn(r.authToken)}async completeOAuthSignIn(a){try{await this.tokenManager.setToken(a);const t=await this.httpClient.fetch(`${this.API_URL}/api/v1/profile`),r=await t.json();if(t.ok){const n=c(r.data);return await this.userStateManager.setUser(n),{isSuccessful:!0,user:n}}else return{challengeType:f.None,isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,r.message)}}catch{return{challengeType:f.None,isSuccessful:!1,error:new s(e.UNKNOWN_ERROR,"Failed to complete OAuth sign in")}}}}export{F as ManhattanAuthProviderStrategy};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.