{"version":3,"file":"NativeAuthError.js","sources":["../../src/error/NativeAuthError.ts"],"sourcesContent":["/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { AuthError, InteractionRequiredAuthError } from \"@azure/msal-common\";\r\nimport { BrowserAuthError } from \"./BrowserAuthError\";\r\n\r\nexport type OSError = {\r\n error: number;\r\n protocol_error: string;\r\n properties: object;\r\n status: string;\r\n retryable?: boolean;\r\n};\r\n\r\nexport enum NativeStatusCode {\r\n USER_INTERACTION_REQUIRED = \"USER_INTERACTION_REQUIRED\",\r\n USER_CANCEL = \"USER_CANCEL\",\r\n NO_NETWORK = \"NO_NETWORK\",\r\n TRANSIENT_ERROR = \"TRANSIENT_ERROR\",\r\n PERSISTENT_ERROR = \"PERSISTENT_ERROR\",\r\n DISABLED = \"DISABLED\",\r\n ACCOUNT_UNAVAILABLE = \"ACCOUNT_UNAVAILABLE\"\r\n}\r\n\r\nexport const NativeAuthErrorMessage = {\r\n extensionError: {\r\n code: \"ContentError\"\r\n },\r\n userSwitch: {\r\n code: \"user_switch\",\r\n desc: \"User attempted to switch accounts in the native broker, which is not allowed. All new accounts must sign-in through the standard web flow first, please try again.\"\r\n },\r\n tokensNotFoundInCache: {\r\n code: \"tokens_not_found_in_internal_memory_cache\",\r\n desc: \"Tokens not cached in MSAL JS internal memory, please make the WAM request\"\r\n }\r\n};\r\n\r\nexport class NativeAuthError extends AuthError {\r\n ext: OSError | undefined;\r\n\r\n constructor(errorCode: string, description: string, ext?: OSError) {\r\n super(errorCode, description);\r\n\r\n Object.setPrototypeOf(this, NativeAuthError.prototype);\r\n this.name = \"NativeAuthError\";\r\n this.ext = ext;\r\n }\r\n\r\n /**\r\n * These errors should result in a fallback to the 'standard' browser based auth flow.\r\n */\r\n isFatal(): boolean {\r\n if (this.ext && this.ext.status && (this.ext.status === NativeStatusCode.PERSISTENT_ERROR || this.ext.status === NativeStatusCode.DISABLED)) {\r\n return true;\r\n }\r\n\r\n switch (this.errorCode) {\r\n case NativeAuthErrorMessage.extensionError.code:\r\n return true;\r\n default:\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Create the appropriate error object based on the WAM status code.\r\n * @param code\r\n * @param description\r\n * @param ext\r\n * @returns\r\n */\r\n static createError(code: string, description: string, ext?: OSError): AuthError {\r\n if (ext && ext.status) {\r\n switch (ext.status) {\r\n case NativeStatusCode.ACCOUNT_UNAVAILABLE:\r\n return InteractionRequiredAuthError.createNativeAccountUnavailableError();\r\n case NativeStatusCode.USER_INTERACTION_REQUIRED:\r\n return new InteractionRequiredAuthError(code, description);\r\n case NativeStatusCode.USER_CANCEL:\r\n return BrowserAuthError.createUserCancelledError();\r\n case NativeStatusCode.NO_NETWORK:\r\n return BrowserAuthError.createNoNetworkConnectivityError();\r\n }\r\n }\r\n\r\n return new NativeAuthError(code, description, ext);\r\n }\r\n\r\n /**\r\n * Creates user switch error when the user chooses a different account in the native broker prompt\r\n * @returns\r\n */\r\n static createUserSwitchError(): NativeAuthError {\r\n return new NativeAuthError(NativeAuthErrorMessage.userSwitch.code, NativeAuthErrorMessage.userSwitch.desc);\r\n }\r\n\r\n /**\r\n * Creates a tokens not found error when the internal cache look up fails\r\n * @returns NativeAuthError: tokensNotFoundInCache\r\n */\r\n static createTokensNotFoundInCacheError(): NativeAuthError {\r\n return new NativeAuthError(NativeAuthErrorMessage.tokensNotFoundInCache.code, NativeAuthErrorMessage.tokensNotFoundInCache.desc);\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;;;AAAA;;;;IAgBY;AAAZ,WAAY,gBAAgB;IACxB,2EAAuD,CAAA;IACvD,+CAA2B,CAAA;IAC3B,6CAAyB,CAAA;IACzB,uDAAmC,CAAA;IACnC,yDAAqC,CAAA;IACrC,yCAAqB,CAAA;IACrB,+DAA2C,CAAA;AAC/C,CAAC,EARW,gBAAgB,KAAhB,gBAAgB,QAQ3B;IAEY,sBAAsB,GAAG;IAClC,cAAc,EAAE;QACZ,IAAI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