{"version":3,"file":"NativeAuthError.js","sources":["../../src/error/NativeAuthError.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { AuthError, InteractionRequiredAuthError } from \"@azure/msal-common\";\nimport { BrowserAuthError } from \"./BrowserAuthError\";\n\nexport type OSError = {\n error: number;\n protocol_error: string;\n properties: object;\n status: string;\n retryable?: boolean;\n};\n\nexport enum NativeStatusCode {\n USER_INTERACTION_REQUIRED = \"USER_INTERACTION_REQUIRED\",\n USER_CANCEL = \"USER_CANCEL\",\n NO_NETWORK = \"NO_NETWORK\",\n TRANSIENT_ERROR = \"TRANSIENT_ERROR\",\n PERSISTENT_ERROR = \"PERSISTENT_ERROR\",\n DISABLED = \"DISABLED\",\n ACCOUNT_UNAVAILABLE = \"ACCOUNT_UNAVAILABLE\"\n}\n\nexport const NativeAuthErrorMessage = {\n extensionError: {\n code: \"ContentError\"\n },\n userSwitch: {\n code: \"user_switch\",\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.\"\n },\n tokensNotFoundInCache: {\n code: \"tokens_not_found_in_internal_memory_cache\",\n desc: \"Tokens not cached in MSAL JS internal memory, please make the WAM request\"\n }\n};\n\nexport class NativeAuthError extends AuthError {\n ext: OSError | undefined;\n\n constructor(errorCode: string, description: string, ext?: OSError) {\n super(errorCode, description);\n\n Object.setPrototypeOf(this, NativeAuthError.prototype);\n this.name = \"NativeAuthError\";\n this.ext = ext;\n }\n\n /**\n * These errors should result in a fallback to the 'standard' browser based auth flow.\n */\n isFatal(): boolean {\n if (this.ext && this.ext.status && (this.ext.status === NativeStatusCode.PERSISTENT_ERROR || this.ext.status === NativeStatusCode.DISABLED)) {\n return true;\n }\n\n switch (this.errorCode) {\n case NativeAuthErrorMessage.extensionError.code:\n return true;\n default:\n return false;\n }\n }\n\n /**\n * Create the appropriate error object based on the WAM status code.\n * @param code\n * @param description\n * @param ext\n * @returns\n */\n static createError(code: string, description: string, ext?: OSError): AuthError {\n if (ext && ext.status) {\n switch (ext.status) {\n case NativeStatusCode.ACCOUNT_UNAVAILABLE:\n return InteractionRequiredAuthError.createNativeAccountUnavailableError();\n case NativeStatusCode.USER_INTERACTION_REQUIRED:\n return new InteractionRequiredAuthError(code, description);\n case NativeStatusCode.USER_CANCEL:\n return BrowserAuthError.createUserCancelledError();\n case NativeStatusCode.NO_NETWORK:\n return BrowserAuthError.createNoNetworkConnectivityError();\n }\n }\n\n return new NativeAuthError(code, description, ext);\n }\n\n /**\n * Creates user switch error when the user chooses a different account in the native broker prompt\n * @returns\n */\n static createUserSwitchError(): NativeAuthError {\n return new NativeAuthError(NativeAuthErrorMessage.userSwitch.code, NativeAuthErrorMessage.userSwitch.desc);\n }\n\n /**\n * Creates a tokens not found error when the internal cache look up fails\n * @returns NativeAuthError: tokensNotFoundInCache\n */\n static createTokensNotFoundInCacheError(): NativeAuthError {\n return new NativeAuthError(NativeAuthErrorMessage.tokensNotFoundInCache.code, NativeAuthErrorMessage.tokensNotFoundInCache.desc);\n }\n}\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,EAAE,cAAc;KACvB;IACD,UAAU,EAAE;QACR,IAAI,EAAE,aAAa;QACnB,IAAI,EAAE,oKAAoK;KAC7K;IACD,qBAAqB,EAAE;QACnB,IAAI,EAAE,2CAA2C;QACjD,IAAI,EAAE,2EAA2E;KACpF;EACH;;IAEmC,mCAAS;IAG1C,yBAAY,SAAiB,EAAE,WAAmB,EAAE,GAAa;QAAjE,YACI,kBAAM,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