UNPKG

@azure/msal-browser

Version:
81 lines (78 loc) • 3.35 kB
/*! @azure/msal-browser v5.25.0 2026-10-06 */ 'use strict'; 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 { CustomAuthFlowScenarioV2 } from './CustomAuthFlowScenarioV2.mjs'; /* * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ /** * Result of a native auth V2 operation. Use {@link CustomAuthResultV2.isState} * to narrow the state before accessing its members. */ class CustomAuthResultV2 { constructor(state, data, scenario = CustomAuthFlowScenarioV2.Unknown) { this.state = state; this.data = data; this.scenario = scenario; } /** * Narrows the result to a specific state by its `stateType` discriminator. * A successful match makes the state's properties available without a cast. * @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 result is in the terminal failed state. A failed result * contains the flow-specific error. * @returns True (and narrows `state`) when the operation failed. */ isFailed() { return this.state.stateType === "failed"; } /** * Creates a failed result from the supplied error. The result uses the * shared {@link FailedStateV2} terminal state. * @param error - The error that occurred. * @param options - The flow-error type and error context. * @returns A failed result carrying the flow-specific error. */ static createWithError(error, options) { const { errorType: ErrorType, scenario = CustomAuthFlowScenarioV2.Unknown, correlationId, } = options; const errorData = CustomAuthResultV2.createErrorData(error, correlationId); const flowError = new ErrorType(errorData, scenario); const result = new CustomAuthResultV2(new FailedStateV2(), undefined, 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