@azure/msal-browser
Version:
Microsoft Authentication Library for js
88 lines (85 loc) • 3.58 kB
JavaScript
/*! @azure/msal-browser v5.30.0 2026-11-18 */
;
import { AuthError } from '@azure/msal-common/browser';
import { CustomAuthError } from '../../error/CustomAuthError.mjs';
import { MsalCustomAuthError } from '../../error/MsalCustomAuthError.mjs';
import { UnexpectedError } from '../../error/UnexpectedError.mjs';
import { FailedStateV2 } from './state/FailedStateV2.mjs';
import { AuthFlowErrorV2 } from './error/AuthFlowErrorV2.mjs';
import { CustomAuthFlowScenarioV2 } from './CustomAuthFlowScenarioV2.mjs';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Result of a native auth V2 operation.
* @warning This API is experimental. It may be changed in the future without notice. Do not use in production applications.
*/
class CustomAuthResultV2 {
constructor(state, data, scenario = CustomAuthFlowScenarioV2.Unknown) {
this.state = state;
this.data = data;
this.scenario = scenario;
}
/**
* Checks whether the result matches a state type and narrows its state.
* @param stateType - The state type to test for.
* @returns True (and narrows `state`) when the current state matches `stateType`.
*/
isState(stateType) {
return this.state.stateType === stateType;
}
/**
* Checks whether the operation failed.
* @returns True (and narrows `state`) when the operation failed.
*/
isFailed() {
return this.state.stateType === "failed";
}
/**
* Checks whether the current state requires a password.
* @returns True (and narrows `state`) when a password is required.
*/
isPasswordRequired() {
return this.state.stateType === "passwordRequired";
}
/**
* Creates a failed result from the supplied error.
* Optional error context identifies MFA verification or authentication-method registration.
* @param error - The error that occurred.
* @param options - The flow-error context.
* @returns A failed result carrying the unified V2 flow error.
*/
static createWithError(error, options) {
const { correlationId } = options;
const flowError = error instanceof AuthFlowErrorV2
? error
: new AuthFlowErrorV2(CustomAuthResultV2.createErrorData(error, correlationId), options.scenario ?? CustomAuthFlowScenarioV2.Unknown, options.errorContext);
const result = new CustomAuthResultV2(new FailedStateV2(), undefined, flowError.scenario);
result.error = flowError;
return result;
}
static createErrorData(error, correlationId) {
if (error instanceof CustomAuthError) {
return error;
}
if (error instanceof AuthError) {
const errorCodes = [];
if ("errorNo" in error) {
if (typeof error.errorNo === "string") {
const code = Number(error.errorNo);
if (!isNaN(code)) {
errorCodes.push(code);
}
}
else if (typeof error.errorNo === "number") {
errorCodes.push(error.errorNo);
}
}
return new MsalCustomAuthError(error.errorCode, error.errorMessage, error.subError, errorCodes, error.correlationId);
}
return new UnexpectedError(error, correlationId);
}
}
export { CustomAuthResultV2 };
//# sourceMappingURL=CustomAuthResultV2.mjs.map