{"version":3,"file":"EventMessage.js","sources":["../../src/event/EventMessage.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { AuthenticationResult, AuthError, AccountInfo } from \"@azure/msal-common\";\nimport { EventType } from \"./EventType\";\nimport { InteractionStatus, InteractionType } from \"../utils/BrowserConstants\";\nimport { PopupRequest, RedirectRequest, SilentRequest, SsoSilentRequest, EndSessionRequest } from \"..\";\n\nexport type EventMessage = {\n eventType: EventType;\n interactionType: InteractionType | null;\n payload: EventPayload;\n error: EventError;\n timestamp: number;\n};\n\nexport type PopupEvent = {\n popupWindow: Window;\n};\n\nexport type EventPayload = AccountInfo | PopupRequest | RedirectRequest | SilentRequest | SsoSilentRequest | EndSessionRequest | AuthenticationResult | PopupEvent | null;\n\nexport type EventError = AuthError | Error | null;\n\nexport type EventCallbackFunction = (message: EventMessage) => void;\n\nexport class EventMessageUtils {\n\n /**\n * Gets interaction status from event message\n * @param message\n * @param currentStatus\n */\n static getInteractionStatusFromEvent(message: EventMessage, currentStatus?: InteractionStatus): InteractionStatus|null {\n switch (message.eventType) {\n case EventType.LOGIN_START:\n return InteractionStatus.Login;\n case EventType.SSO_SILENT_START:\n return InteractionStatus.SsoSilent;\n case EventType.ACQUIRE_TOKEN_START:\n if (message.interactionType === InteractionType.Redirect || message.interactionType === InteractionType.Popup) {\n return InteractionStatus.AcquireToken;\n }\n break;\n case EventType.HANDLE_REDIRECT_START:\n return InteractionStatus.HandleRedirect;\n case EventType.LOGOUT_START:\n return InteractionStatus.Logout;\n case EventType.SSO_SILENT_SUCCESS:\n case EventType.SSO_SILENT_FAILURE:\n if (currentStatus && currentStatus !== InteractionStatus.SsoSilent) {\n // Prevent this event from clearing any status other than ssoSilent\n break;\n }\n return InteractionStatus.None;\n case EventType.LOGOUT_END:\n if (currentStatus && currentStatus !== InteractionStatus.Logout) {\n // Prevent this event from clearing any status other than logout\n break;\n }\n return InteractionStatus.None;\n case EventType.HANDLE_REDIRECT_END:\n if (currentStatus && currentStatus !== InteractionStatus.HandleRedirect) {\n // Prevent this event from clearing any status other than handleRedirect\n break;\n }\n return InteractionStatus.None;\n case EventType.LOGIN_SUCCESS:\n case EventType.LOGIN_FAILURE:\n case EventType.ACQUIRE_TOKEN_SUCCESS:\n case EventType.ACQUIRE_TOKEN_FAILURE:\n if (message.interactionType === InteractionType.Redirect || message.interactionType === InteractionType.Popup) {\n if (currentStatus && currentStatus !== InteractionStatus.Login && currentStatus !== InteractionStatus.AcquireToken) {\n // Prevent this event from clearing any status other than login or acquireToken\n break;\n }\n return InteractionStatus.None;\n }\n break;\n default:\n break;\n }\n return null;\n }\n}\n"],"names":[],"mappings":";;;;;AAAA;;;;;IA4BA;KA0DC;;;;;;IAnDU,+CAA6B,GAApC,UAAqC,OAAqB,EAAE,aAAiC;QACzF,QAAQ,OAAO,CAAC,SAAS;YACrB,KAAK,SAAS,CAAC,WAAW;gBACtB,OAAO,iBAAiB,CAAC,KAAK,CAAC;YACnC,KAAK,SAAS,CAAC,gBAAgB;gBAC3B,OAAO,iBAAiB,CAAC,SAAS,CAAC;YACvC,KAAK,SAAS,CAAC,mBAAmB;gBAC9B,IAAI,OAAO,CAAC,eAAe,KAAK,eAAe,CAAC,QAAQ,IAAI,OAAO,CAAC,eAAe,KAAK,eAAe,CAAC,KAAK,EAAE;oBAC3G,OAAO,iBAAiB,CAAC,YAAY,CAAC;iBACzC;gBACD,MAAM;YACV,KAAK,SAAS,CAAC,qBAAqB;gBAChC,OAAO,iBAAiB,CAAC,cAAc,CAAC;YAC5C,KAAK,SAAS,CAAC,YAAY;gBACvB,OAAO,iBAAiB,CAAC,MAAM,CAAC;YACpC,KAAK,SAAS,CAAC,kBAAkB,CAAC;YAClC,KAAK,SAAS,CAAC,kBAAkB;gBAC7B,IAAI,aAAa,IAAI,aAAa,KAAK,iBAAiB,CAAC,SAAS,EAAE;;oBAEhE,MAAM;iBACT;gBACD,OAAO,iBAAiB,CAAC,IAAI,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