{
  "version": 3,
  "sources": ["../src/index.ts", "../src/msal-config.ts", "../src/vue3-msal-plugin.ts", "../src/helpers.ts"],
  "sourcesContent": ["import { InteractionStatus, InteractionType } from '@azure/msal-browser';\nimport type {\n  AuthenticationResult,\n  AuthError,\n  PopupRequest,\n  RedirectRequest,\n  SilentRequest,\n} from '@azure/msal-browser';\nimport { getCurrentInstance, toRefs, watch, ref } from 'vue';\nimport type { Ref } from 'vue';\nimport type { MsalContext, MsalAuthenticationResult } from './types';\n\nimport { msalInstance } from './msal-config';\nimport { msalPlugin } from './vue3-msal-plugin';\n\nexport type { AccountIdentifiers, State, MsalContext, MsalAuthenticationResult } from './types';\n\n// Define default login request\nconst loginRequest = {\n  scopes: ['User.Read'],\n};\n\n/**\n * Provides access to the MSAL instance, user accounts, and interaction status.\n * @throws {Error} If called outside the setup() function of a component or if the MSAL plugin is not installed.\n * @returns {MsalContext} The MSAL context.\n */\nexport function useMsal(): MsalContext {\n  const internalInstance = getCurrentInstance();\n  if (!internalInstance) {\n    throw new Error('useMsal() cannot be called outside the setup() function of a component');\n  }\n  const { instance, accounts, inProgress } = toRefs(internalInstance.appContext.config.globalProperties.$msal);\n\n  if (!instance.value || !accounts.value || !inProgress.value) {\n    throw new Error('Please install the msalPlugin');\n  }\n\n  if (inProgress.value === InteractionStatus.Startup) {\n    instance.value.initialize().then(() => {\n      instance.value.handleRedirectPromise().catch(() => {\n        // Errors should be handled by listening to the LOGIN_FAILURE event\n      });\n    });\n  }\n\n  return {\n    instance: instance.value,\n    accounts,\n    inProgress,\n    loginRequest,\n    callMsGraph,\n  };\n}\n\n/**\n * Returns a reactive reference to a boolean indicating whether the user is authenticated.\n * @returns {Ref<boolean>} A reference to a boolean indicating whether the user is authenticated.\n */\nexport function useIsAuthenticated(): Ref<boolean> {\n  const { accounts } = useMsal();\n  const isAuthenticated = ref(accounts.value.length > 0);\n\n  watch(accounts, () => {\n    isAuthenticated.value = accounts.value.length > 0;\n  });\n\n  return isAuthenticated;\n}\n\n/**\n * Returns an object with methods for acquiring a token and reactive references to the authentication result, any error, and whether an authentication process is in progress.\n * @param {InteractionType} interactionType The type of interaction to use for authentication.\n * @param {PopupRequest | RedirectRequest | SilentRequest} request The request object for authentication.\n * @returns {MsalAuthenticationResult} The result of the authentication process.\n */\nexport function useMsalAuthentication(\n  interactionType: InteractionType,\n  request: PopupRequest | RedirectRequest | SilentRequest,\n): MsalAuthenticationResult {\n  const { instance, inProgress } = useMsal();\n\n  const localInProgress = ref<boolean>(false);\n  const result = ref<AuthenticationResult | null>(null);\n  const error = ref<AuthError | null>(null);\n\n  const acquireToken = async (requestOverride?: PopupRequest | RedirectRequest | SilentRequest) => {\n    if (!localInProgress.value) {\n      localInProgress.value = true;\n      const tokenRequest = requestOverride || request;\n\n      if (inProgress.value === InteractionStatus.Startup || inProgress.value === InteractionStatus.HandleRedirect) {\n        try {\n          const response = await instance.handleRedirectPromise();\n          if (response) {\n            result.value = response;\n            error.value = null;\n            return;\n          }\n        } catch (e) {\n          result.value = null;\n          error.value = e as AuthError;\n          return;\n        }\n      }\n\n      try {\n        const response = await instance.acquireTokenSilent(tokenRequest);\n        result.value = response;\n        error.value = null;\n      } catch {\n        if (inProgress.value !== InteractionStatus.None) {\n          return;\n        }\n\n        if (interactionType === InteractionType.Popup) {\n          instance\n            .loginPopup(tokenRequest)\n            .then((response) => {\n              result.value = response;\n              error.value = null;\n            })\n            .catch((e) => {\n              error.value = e;\n              result.value = null;\n            });\n        } else if (interactionType === InteractionType.Redirect) {\n          await instance.loginRedirect(tokenRequest).catch((e) => {\n            error.value = e;\n            result.value = null;\n          });\n        }\n      }\n      localInProgress.value = false;\n    }\n  };\n\n  const stopWatcher = watch(inProgress, () => {\n    if (!result.value && !error.value) {\n      acquireToken();\n    } else {\n      stopWatcher();\n    }\n  });\n\n  acquireToken();\n\n  return {\n    acquireToken,\n    result,\n    error,\n    inProgress: localInProgress,\n  };\n}\n\n// Define the configuration for the Graph API\nconst graphConfig = {\n  graphMeEndpoint: 'https://graph.microsoft.com/v1.0/me',\n};\n\n/**\n * Makes a GET request to the Microsoft Graph API.\n * @param {string} accessToken The access token to use for the request.\n * @returns {Promise<any>} A promise that resolves with the response data or rejects with an error.\n */\nasync function callMsGraph(accessToken: string) {\n  const headers = new Headers();\n  const bearer = `Bearer ${accessToken}`;\n\n  headers.append('Authorization', bearer);\n\n  const options = {\n    method: 'GET',\n    headers: headers,\n  };\n\n  return fetch(graphConfig.graphMeEndpoint, options)\n    .then((response) => response.json())\n    .catch((error) => {\n      throw error;\n    });\n}\n\nexport { msalInstance };\n\nexport { msalPlugin };\n", "import { PublicClientApplication } from '@azure/msal-browser';\nimport type { Configuration } from '@azure/msal-browser';\n\n/**\n * Creates and returns a new PublicClientApplication instance with the provided configuration.\n *\n * @param msalConfig - The configuration for the MSAL PublicClientApplication.\n * @returns A new PublicClientApplication instance.\n */\nexport const msalInstance = (msalConfig: Configuration) => {\n  return new PublicClientApplication(msalConfig);\n};\n", "import { shallowReactive } from 'vue';\nimport type { App, Plugin } from 'vue';\nimport { EventMessageUtils, EventType, InteractionStatus, PublicClientApplication } from '@azure/msal-browser';\nimport type { EventMessage } from '@azure/msal-browser';\n\nimport type { State } from './types';\nimport { accountArraysAreEqual } from './helpers';\n\nexport const msalPlugin: Plugin = {\n  install: (app: App, msalInstance: PublicClientApplication) => {\n    // Initializing the interaction status and accounts\n    const inProgress: InteractionStatus = InteractionStatus.Startup;\n    const accounts = msalInstance.getAllAccounts();\n\n    // Creating a reactive state\n    const state = shallowReactive<State>({\n      instance: msalInstance,\n      inProgress: inProgress,\n      accounts: accounts,\n    });\n\n    // Adding the state to the global properties of the Vue app\n    app.config.globalProperties.$msal = state;\n\n    // Adding an event callback to the MSAL instance\n    msalInstance.addEventCallback((message: EventMessage) => {\n      switch (message.eventType) {\n        case EventType.ACCOUNT_ADDED:\n        case EventType.ACCOUNT_REMOVED:\n        case EventType.LOGIN_SUCCESS:\n        case EventType.SSO_SILENT_SUCCESS:\n        case EventType.HANDLE_REDIRECT_END:\n        case EventType.LOGIN_FAILURE:\n        case EventType.SSO_SILENT_FAILURE:\n        case EventType.LOGOUT_END:\n        case EventType.ACQUIRE_TOKEN_SUCCESS:\n        case EventType.ACQUIRE_TOKEN_FAILURE: {\n          // Updating the accounts in the state when an account-related event occurs\n          const currentAccounts = msalInstance.getAllAccounts();\n          if (!accountArraysAreEqual(currentAccounts, state.accounts)) {\n            state.accounts = currentAccounts;\n          }\n          break;\n        }\n      }\n      // Updating the interaction status in the state when an interaction-related event occurs\n      const status = EventMessageUtils.getInteractionStatusFromEvent(message, state.inProgress);\n      if (status !== null) {\n        state.inProgress = status;\n      }\n    });\n  },\n};\n", "import type { AccountIdentifiers } from './types';\n\n/**\n * Helper function to determine whether 2 arrays are equal\n * Used to avoid unnecessary state updates\n * @param arrayA\n * @param arrayB\n */\nexport function accountArraysAreEqual(arrayA: Array<AccountIdentifiers>, arrayB: Array<AccountIdentifiers>): boolean {\n  if (arrayA.length !== arrayB.length) {\n    return false;\n  }\n\n  const comparisonArray = [...arrayB];\n\n  return arrayA.every((elementA) => {\n    const elementB = comparisonArray.shift();\n    if (!elementA || !elementB) {\n      return false;\n    }\n\n    return (\n      elementA.homeAccountId === elementB.homeAccountId &&\n      elementA.localAccountId === elementB.localAccountId &&\n      elementA.username === elementB.username\n    );\n  });\n}\n"],
  "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,eAAAC,EAAA,uBAAAC,EAAA,YAAAC,EAAA,0BAAAC,IAAA,eAAAC,EAAAP,GAAA,IAAAQ,EAAmD,+BAQnDC,EAAuD,eCRvD,IAAAC,EAAwC,+BAS3BC,EAAgBC,GACpB,IAAI,0BAAwBA,CAAU,ECV/C,IAAAC,EAAgC,eAEhCC,EAAyF,+BCMlF,SAASC,EAAsBC,EAAmCC,EAA4C,CACnH,GAAID,EAAO,SAAWC,EAAO,OAC3B,MAAO,GAGT,IAAMC,EAAkB,CAAC,GAAGD,CA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AM,MAAQ,IAChB,CAAC,EACA,MAAOK,GAAM,CACZL,EAAM,MAAQK,EACdN,EAAO,MAAQ,IACjB,CAAC,EACMH,IAAoB,kBAAgB,UAC7C,MAAMP,EAAS,cAAcc,CAAY,EAAE,MAAOE,GAAM,CACtDL,EAAM,MAAQK,EACdN,EAAO,MAAQ,IACjB,CAAC,CAEL,CACAD,EAAgB,MAAQ,EAC1B,CACF,EAEMQ,KAAc,SAAMf,EAAY,IAAM,CACtC,CAACQ,EAAO,OAAS,CAACC,EAAM,MAC1BC,EAAa,EAEbK,EAAY,CAEhB,CAAC,EAED,OAAAL,EAAa,EAEN,CACL,aAAAA,EACA,OAAAF,EACA,MAAAC,EACA,WAAYF,CACd,CACF,CAGA,IAAMS,EAAc,CAClB,gBAAiB,qCACnB,EAOA,eAAef,EAAYgB,EAAqB,CAC9C,IAAMC,EAAU,IAAI,QACdC,EAAS,UAAUF,CAAW,GAEpCC,EAAQ,OAAO,gBAAiBC,CAAM,EAEtC,IAAMC,EAAU,CACd,OAAQ,MACR,QAASF,CACX,EAEA,OAAO,MAAMF,EAAY,gBAAiBI,CAAO,EAC9C,KAAMP,GAAaA,EAAS,KAAK,CAAC,EAClC,MAAOJ,GAAU,CAChB,MAAMA,CACR,CAAC,CACL",
  "names": ["index_exports", "__export", "msalInstance", "msalPlugin", "useIsAuthenticated", "useMsal", "useMsalAuthentication", "__toCommonJS", "import_msal_browser", "import_vue", "import_msal_browser", "msalInstance", "msalConfig", "import_vue", "import_msal_browser", "accountArraysAreEqual", "arrayA", "arrayB", "comparisonArray", "elementA", "elementB", "msalPlugin", "app", "msalInstance", "inProgress", "accounts", "state", "message", "currentAccounts", "accountArraysAreEqual", "status", "loginRequest", "useMsal", "internalInstance", "instance", "accounts", "inProgress", "callMsGraph", "useIsAuthenticated", "isAuthenticated", "useMsalAuthentication", "interactionType", "request", "localInProgress", "result", "error", "acquireToken", "requestOverride", "tokenRequest", "response", "e", "stopWatcher", "graphConfig", "accessToken", "headers", "bearer", "options"]
}
