{"version":3,"file":"outlookIntegrationClient.mjs","names":["AxiosResponse","apiMutate","ConfigService","CONTROLLER","OUTLOOK_CALLBACK_PATH","OutlookIntegrationStatus","connected","mailboxPrincipal","expiresAt","scope","OutlookAuthorizeUrlRequest","redirectUri","OutlookAuthorizeUrlResponse","authorizeUrl","state","codeChallenge","OutlookAuthExchangeRequest","authorizationCode","OutlookSendMailRequest","to","subject","body","getStatus","Promise","data","ensureBaseUrl","method","headers","productHeaders","undefined","getAuthorizeUrl","request","exchangeAuthorizationCode","disconnect","sendMail","payload","checkAndAuthenticate","getOutlookRedirectUri","window","location","origin","base","String","config","UNITY_URL","replace","integrationV2ApiUrl","Record","rawId","UNITY_PRODUCT_ID","normalized","trim","Error","numericId","Number","isFinite","productId"],"sources":["../../../src/integrations/outlook/outlookIntegrationClient.ts"],"sourcesContent":["import type { AxiosResponse } from 'axios';\nimport { apiMutate } from '../../utilities/useAxiosMutate';\nimport { ConfigService } from '../../configService';\n\nconst CONTROLLER = 'OutlookIntegrationToken';\nconst OUTLOOK_CALLBACK_PATH = '/auth/outlook/callback';\n\nexport type OutlookIntegrationStatus = {\n  connected: boolean;\n  mailboxPrincipal?: string | null;\n  expiresAt?: string | null;\n  scope?: string | null;\n};\n\nexport type OutlookAuthorizeUrlRequest = {\n  redirectUri: string;\n};\n\nexport type OutlookAuthorizeUrlResponse = {\n  authorizeUrl: string;\n  state: string;\n  codeChallenge?: string;\n  redirectUri?: string;\n};\n\nexport type OutlookAuthExchangeRequest = {\n  authorizationCode: string;\n  state: string;\n  redirectUri: string;\n};\n\nexport type OutlookSendMailRequest = {\n  to: string;\n  subject: string;\n  body: string;\n};\n\nexport async function getStatus(): Promise<OutlookIntegrationStatus> {\n  const { data } = (await apiMutate(\n    ensureBaseUrl(),\n    `${CONTROLLER}/status`,\n    { method: 'get', headers: productHeaders() },\n    undefined\n  )) as AxiosResponse<OutlookIntegrationStatus>;\n\n  return data ?? { connected: false };\n}\n\nexport async function getAuthorizeUrl(\n  request: OutlookAuthorizeUrlRequest\n): Promise<OutlookAuthorizeUrlResponse> {\n  const { data } = (await apiMutate(\n    ensureBaseUrl(),\n    `${CONTROLLER}/authorize-url`,\n    {\n      method: 'post',\n      headers: productHeaders(),\n      data: request,\n    },\n    undefined\n  )) as AxiosResponse<OutlookAuthorizeUrlResponse>;\n\n  return data;\n}\n\nexport async function exchangeAuthorizationCode(\n  request: OutlookAuthExchangeRequest\n): Promise<OutlookIntegrationStatus> {\n  const { data } = (await apiMutate(\n    ensureBaseUrl(),\n    `${CONTROLLER}/oauth/exchange`,\n    {\n      method: 'post',\n      headers: productHeaders(),\n      data: request,\n    },\n    undefined\n  )) as AxiosResponse<OutlookIntegrationStatus>;\n\n  return data;\n}\n\nexport async function disconnect(): Promise<void> {\n  await apiMutate(\n    ensureBaseUrl(),\n    `${CONTROLLER}/disconnect`,\n    {\n      method: 'post',\n      headers: productHeaders(),\n    },\n    undefined\n  );\n}\n\nexport async function sendMail(payload: OutlookSendMailRequest): Promise<void> {\n  await apiMutate(\n    ensureBaseUrl(),\n    `${CONTROLLER}/send-mail`,\n    {\n      method: 'post',\n      headers: productHeaders(),\n      data: payload,\n    },\n    undefined\n  );\n}\n\nexport async function checkAndAuthenticate(): Promise<void> {\n  await apiMutate(\n    ensureBaseUrl(),\n    `${CONTROLLER}/authenticate`,\n    {\n      method: 'post',\n      headers: productHeaders(),\n    },\n    undefined\n  );\n}\n\nexport function getOutlookRedirectUri(): string {\n  if (typeof window !== 'undefined' && window.location) {\n    return `${window.location.origin}${OUTLOOK_CALLBACK_PATH}`;\n  }\n\n  const base = String(ConfigService?.config?.UNITY_URL ?? '').replace(/\\/$/, '');\n  return `${base}${OUTLOOK_CALLBACK_PATH}`;\n}\n\nfunction ensureBaseUrl(): string {\n  return ConfigService.integrationV2ApiUrl;\n}\n\nfunction productHeaders(): Record<string, string> {\n  const rawId = ConfigService?.config?.UNITY_PRODUCT_ID;\n  const normalized = String(rawId ?? '').trim();\n  if (!normalized) {\n    throw new Error('UNITY_PRODUCT_ID is not configured.');\n  }\n\n  const numericId = Number(normalized);\n  if (!Number.isFinite(numericId) || numericId <= 0) {\n    throw new Error('UNITY_PRODUCT_ID must be a positive number.');\n  }\n\n  return { productId: String(numericId) };\n}\n"],"mappings":";;;AAIA,MAAMG,aAAa;AACnB,MAAMC,wBAAwB;AAgC9B,eAAsBkB,YAA+C;CACnE,MAAM,EAAEE,SAAU,MAAMvB,UACtBwB,eAAe,EACf,GAAGtB,WAAU,UACb;EAAEuB,QAAQ;EAAOC,SAASC,gBAAe;EAAG,EAC5CC,KAAAA,EACD;AAED,QAAOL,QAAQ,EAAElB,WAAW,OAAO;;AAGrC,eAAsBwB,gBACpBC,SACsC;CACtC,MAAM,EAAEP,SAAU,MAAMvB,UACtBwB,eAAe,EACf,GAAGtB,WAAU,iBACb;EACEuB,QAAQ;EACRC,SAASC,gBAAgB;EACzBJ,MAAMO;EACP,EACDF,KAAAA,EACD;AAED,QAAOL;;AAGT,eAAsBQ,0BACpBD,SACmC;CACnC,MAAM,EAAEP,SAAU,MAAMvB,UACtBwB,eAAe,EACf,GAAGtB,WAAU,kBACb;EACEuB,QAAQ;EACRC,SAASC,gBAAgB;EACzBJ,MAAMO;EACP,EACDF,KAAAA,EACD;AAED,QAAOL;;AAGT,eAAsBS,aAA4B;AAChD,OAAMhC,UACJwB,eAAe,EACf,GAAGtB,WAAU,cACb;EACEuB,QAAQ;EACRC,SAASC,gBAAe;EACzB,EACDC,KAAAA,EACD;;AAGH,eAAsBK,SAASC,SAAgD;AAC7E,OAAMlC,UACJwB,eAAe,EACf,GAAGtB,WAAU,aACb;EACEuB,QAAQ;EACRC,SAASC,gBAAgB;EACzBJ,MAAMW;EACP,EACDN,KAAAA,EACD;;AAGH,eAAsBO,uBAAsC;AAC1D,OAAMnC,UACJwB,eAAe,EACf,GAAGtB,WAAU,gBACb;EACEuB,QAAQ;EACRC,SAASC,gBAAe;EACzB,EACDC,KAAAA,EACD;;AAGH,SAAgBQ,wB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